Class: IronBank::Client

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

Overview

Handle the credentials to Zuora and establish a connection when making an authenticated request, reusing the same session cookie for future requests.

Defined Under Namespace

Classes: Error, InvalidHostname

Instance Method Summary collapse

Constructor Details

#initialize(domain:, client_id:, client_secret:, auth_type: "token") ⇒ Client

Returns a new instance of Client.



26
27
28
29
30
31
# File 'lib/iron_bank/client.rb', line 26

def initialize(domain:, client_id:, client_secret:, auth_type: "token")
  @domain        = domain
  @client_id     = client_id
  @client_secret = client_secret
  @auth_type     = auth_type
end

Instance Method Details

#connectionObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/iron_bank/client.rb', line 37

def connection
  validate_domain
  reset_connection if auth.expired?
  config = IronBank.configuration

  @connection ||= Faraday.new(faraday_config) do |conn|
    config.middlewares.each { |klass, options| conn.use(klass, options) }

    conn.request  :json
    conn.request  :retry, config.retry_options

    conn.use FaradayMiddleware::Response::RaiseError
    conn.use FaradayMiddleware::Response::RenewAuth, auth
    conn.response :json, content_type: /\bjson$/

    conn.adapter  Faraday.default_adapter
  end
end

#describe(object_name) ⇒ Object



56
57
58
# File 'lib/iron_bank/client.rb', line 56

def describe(object_name)
  IronBank::Describe::Object.from_connection(connection, object_name)
end

#inspectObject



33
34
35
# File 'lib/iron_bank/client.rb', line 33

def inspect
  %(#<IronBank::Client:0x#{(object_id << 1).to_s(16)} domain="#{domain}">)
end