Module: Invoice2go::Configuration

Included in:
Invoice2go
Defined in:
lib/invoice2go/configuration.rb

Constant Summary collapse

VALID_OPTIONS_KEYS =
[
  :api_key,
  :api_version,
  :adapter,
  :endpoint,
  :client_id,
  :client_secret,
  :grant_type,
  :refresh_token
].freeze
DEFAULT_API_KEY =

By default don’t set the api key.

nil
DEFAULT_API_VERSION =

By default use V1 of the API.

''.freeze
DEFAULT_ADAPTER =

Use the Patron adapter as default tends to break on certain headers.

Faraday::Adapter::Patron
DEFAULT_ENDPOINT =

By default use the main api URL.

'https://api.2go.com'.freeze
DEFAULT_FORMAT =

By default request JSON data to be returned from the API.

:json

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

When this module is extended, reset all settings.



44
45
46
# File 'lib/invoice2go/configuration.rb', line 44

def self.extended(base)
  base.reset
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Convenience method to allow configuration options to be set in a block

Yields:

  • (_self)

Yield Parameters:



33
34
35
# File 'lib/invoice2go/configuration.rb', line 33

def configure
  yield self
end

#optionsObject



37
38
39
40
41
# File 'lib/invoice2go/configuration.rb', line 37

def options
  VALID_OPTIONS_KEYS.inject({}) do |option, key|
    option.merge!(key => send(key))
  end
end

#resetObject

Reset all configuration settings to default values.



49
50
51
52
53
54
# File 'lib/invoice2go/configuration.rb', line 49

def reset
  self.api_key     = DEFAULT_API_KEY
  self.api_version = DEFAULT_API_VERSION
  self.endpoint    = DEFAULT_ENDPOINT
  self.adapter     = DEFAULT_ADAPTER
end