Class: Dato::Account::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/dato/account/client.rb

Constant Summary collapse

REPOS =
{
  account: Repo::Account,
  sites: Repo::Site,
  deploy_events: Repo::DeployEvent
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token, options = {}) ⇒ Client

Returns a new instance of Client.



27
28
29
30
31
# File 'lib/dato/account/client.rb', line 27

def initialize(token, options = {})
  @token = token
  @base_url = options[:base_url] || 'https://account-api.datocms.com'
  @extra_headers = options[:extra_headers] || {}
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



25
26
27
# File 'lib/dato/account/client.rb', line 25

def base_url
  @base_url
end

#extra_headersObject (readonly)

Returns the value of attribute extra_headers.



25
26
27
# File 'lib/dato/account/client.rb', line 25

def extra_headers
  @extra_headers
end

#schemaObject (readonly)

Returns the value of attribute schema.



25
26
27
# File 'lib/dato/account/client.rb', line 25

def schema
  @schema
end

#tokenObject (readonly)

Returns the value of attribute token.



25
26
27
# File 'lib/dato/account/client.rb', line 25

def token
  @token
end

Instance Method Details

#request(*args) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dato/account/client.rb', line 43

def request(*args)
  connection.send(*args).body.with_indifferent_access
rescue Faraday::SSLError => e
  raise e if ENV['SSL_CERT_FILE'] == Cacert.pem

  Cacert.set_in_env
  request(*args)
rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
  raise e
rescue Faraday::ClientError => e
  raise ApiError, e
end