Class: ExportoAPI::AuthClient

Inherits:
Object
  • Object
show all
Defined in:
lib/exporto_api/auth_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username:, password:, sandbox: false, adapter: Faraday.default_adapter, open_timeout: Client::DEFAULT_OPEN_TIMEOUT, timeout: Client::DEFAULT_TIMEOUT) ⇒ AuthClient

Returns a new instance of AuthClient.



9
10
11
12
13
14
15
16
17
# File 'lib/exporto_api/auth_client.rb', line 9

def initialize(username:, password:, sandbox: false, adapter: Faraday.default_adapter,
  open_timeout: Client::DEFAULT_OPEN_TIMEOUT, timeout: Client::DEFAULT_TIMEOUT)
  @username = username
  @password = password
  @sandbox = sandbox
  @adapter = adapter
  @open_timeout = open_timeout
  @timeout = timeout
end

Instance Attribute Details

#adapter ⇒ Object (readonly)

Returns the value of attribute adapter.



7
8
9
# File 'lib/exporto_api/auth_client.rb', line 7

def adapter
  @adapter
end

#open_timeout ⇒ Object (readonly)

Returns the value of attribute open_timeout.



7
8
9
# File 'lib/exporto_api/auth_client.rb', line 7

def open_timeout
  @open_timeout
end

#password ⇒ Object (readonly)

Returns the value of attribute password.



7
8
9
# File 'lib/exporto_api/auth_client.rb', line 7

def password
  @password
end

#timeout ⇒ Object (readonly)

Returns the value of attribute timeout.



7
8
9
# File 'lib/exporto_api/auth_client.rb', line 7

def timeout
  @timeout
end

#username ⇒ Object (readonly)

Returns the value of attribute username.



7
8
9
# File 'lib/exporto_api/auth_client.rb', line 7

def username
  @username
end

Instance Method Details

#connection ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/exporto_api/auth_client.rb', line 23

def connection
  @connection ||= Faraday.new do |connection|
    connection.url_prefix = sandbox? ? Client::TEST_BASE_URL : Client::LIVE_BASE_URL
    connection.options.open_timeout = open_timeout
    connection.options.timeout = timeout
    connection.headers["Accept"] = "application/json"
    connection.request :authorization, :basic, username, password
    connection.request :json
    connection.response :json, content_type: /\bjson/
    connection.adapter adapter
  end
end

#token(scope: nil) ⇒ Object



19
20
21
# File 'lib/exporto_api/auth_client.rb', line 19

def token(scope: nil)
  auth.token(scope: scope)
end