class IronBank::Client
Handle the credentials to Zuora and establish a connection when making an authenticated request, reusing the same session cookie for future requests.
Constants
- DEFAULT_RETRY_OPTIONS
Attributes
auth_type[R]
client_id[R]
client_secret[R]
domain[R]
Public Class Methods
new(domain:, client_id:, client_secret:, auth_type: "token")
click to toggle source
# 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
Public Instance Methods
connection()
click to toggle source
# 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)
click to toggle source
# File lib/iron_bank/client.rb, line 56 def describe(object_name) IronBank::Describe::Object.from_connection(connection, object_name) end
inspect()
click to toggle source
# File lib/iron_bank/client.rb, line 33 def inspect %(#<IronBank::Client:0x#{(object_id << 1).to_s(16)} domain="#{domain}">) end
Private Instance Methods
auth()
click to toggle source
# File lib/iron_bank/client.rb, line 81 def auth @auth ||= IronBank::Authentication.new( client_id: client_id, client_secret: client_secret, base_url: base_url, auth_type: auth_type ) end
base_url()
click to toggle source
# File lib/iron_bank/client.rb, line 90 def base_url @base_url ||= IronBank::Endpoint.base_url(domain) end
faraday_config()
click to toggle source
# File lib/iron_bank/client.rb, line 94 def faraday_config { url: base_url, headers: headers } end
headers()
click to toggle source
# File lib/iron_bank/client.rb, line 101 def headers { "Content-Type" => "application/json" }.merge(auth.header) end
reset_connection()
click to toggle source
# File lib/iron_bank/client.rb, line 105 def reset_connection @connection = nil auth.renew_session end
validate_domain()
click to toggle source
# File lib/iron_bank/client.rb, line 110 def validate_domain raise InvalidHostname, domain.to_s unless base_url end