Class: Fortnox::Client

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Configurable, HTTParty
Defined in:
lib/fortnox/client.rb

Instance Attribute Summary

Attributes included from Configurable

#access_token, #authorization_code, #client_id, #client_secret

Instance Method Summary collapse

Methods included from Configurable

#configure, keys, #options, #reset!

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



19
20
21
22
23
# File 'lib/fortnox/client.rb', line 19

def initialize(options = {})
  Fortnox::Configurable.keys.each do |key|
    instance_variable_set(:"@#{key}", options[key] || Fortnox.instance_variable_get(:"@#{key}"))
  end
end

Instance Method Details

#auth_headersObject



35
36
37
# File 'lib/fortnox/client.rb', line 35

def auth_headers
  { 'Client-Secret' => client_secret, 'Access-Token' => access_token}
end

#fetch_access_tokenObject



25
26
27
28
29
30
31
32
33
# File 'lib/fortnox/client.rb', line 25

def fetch_access_token
  headers = {
              'Client-Secret' => client_secret,
              'Authorization-Code' => authorization_code
            }

  response = get('/', headers: headers)
  @access_token = response.fetch('Authorization').fetch('AccessToken')
end