Module: Nimbu::Configuration

Included in:
Nimbu
Defined in:
lib/nimbu-api/configuration.rb

Constant Summary collapse

VALID_OPTIONS_KEYS =
[
  :client_id,
  :client_secret,
  :oauth_token,
  :endpoint,
  :site,
  :subdomain,
  :ssl,
  :mime_type,
  :user_agent,
  :connection_options,
  :login,
  :password,
  :basic_auth,
  :auto_pagination,
  :content_locale,
  :adapter
].freeze
DEFAULT_CLIENT_ID =

By default, don’t set an application key

nil
DEFAULT_CLIENT_SECRET =

By default, don’t set an application secret

nil
DEFAULT_OAUTH_TOKEN =

By default, don’t set a user oauth access token

nil
DEFAULT_LOGIN =

By default, don’t set a user login name

nil
DEFAULT_PASSWORD =

By default, don’t set a user password

nil
DEFAULT_BASIC_AUTH =

By default, don’t set a user basic authentication

nil
DEFAULT_SUBDOMAIN =

By default, don’t set a nimbu subdomain

nil
DEFAULT_ENDPOINT =

The api endpoint used to connect to Nimbu if none is set

'https://api.nimbu.io'.freeze
DEFAULT_SITE =

The web endpoint used to connect to Nimbu if none is set

'https://www.nimbu.io'.freeze
DEFAULT_SSL =

The default SSL configuration

{ :ca_file => File.expand_path("../../../vendor/cacert.pem", __FILE__) }
DEFAULT_USER_AGENT =

The value sent in the http header for ‘User-Agent’ if none is set

"nimbu-api/#{Nimbu::API::VERSION} (#{RUBY_PLATFORM}) ruby/#{RUBY_VERSION}".freeze
DEFAULT_MIME_TYPE =

By default the Accept header will make a request for JSON

:json
DEFAULT_CONNECTION_OPTIONS =

By default uses the Faraday connection options if none is set

{}
DEFAULT_AUTO_PAGINATION =

By default, don’t traverse the page links

false
DEFAULT_CONTENT_LOCALE =

By default, don’t set a content_locale

nil
DEFAULT_ADAPTER =

Other adapters are :typhoeus, :patron, :em_synchrony, :excon, :test

:net_http

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



80
81
82
# File 'lib/nimbu-api/configuration.rb', line 80

def self.extended(base)
  base.reset!
end

.keysObject



85
86
87
# File 'lib/nimbu-api/configuration.rb', line 85

def keys
  VALID_OPTIONS_KEYS
end

Instance Method Details

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

Convenience method to allow for global setting of configuration options

Yields:

  • (_self)

Yield Parameters:



76
77
78
# File 'lib/nimbu-api/configuration.rb', line 76

def configure
  yield self
end

#optionsObject



90
91
92
93
94
# File 'lib/nimbu-api/configuration.rb', line 90

def options
  options = {}
  VALID_OPTIONS_KEYS.each { |k| options[k] = send(k) }
  options
end

#reset!Object

Reset configuration options to their defaults



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/nimbu-api/configuration.rb', line 98

def reset!
  self.client_id          = DEFAULT_CLIENT_ID
  self.client_secret      = DEFAULT_CLIENT_SECRET
  self.oauth_token        = DEFAULT_OAUTH_TOKEN
  self.endpoint           = DEFAULT_ENDPOINT
  self.site               = DEFAULT_SITE
  self.ssl                = DEFAULT_SSL
  self.user_agent         = DEFAULT_USER_AGENT
  self.connection_options = DEFAULT_CONNECTION_OPTIONS
  self.mime_type          = DEFAULT_MIME_TYPE
  self.              = 
  self.password           = DEFAULT_PASSWORD
  self.basic_auth         = DEFAULT_BASIC_AUTH
  self.auto_pagination    = DEFAULT_AUTO_PAGINATION
  self.content_locale     = DEFAULT_CONTENT_LOCALE
  self.adapter            = DEFAULT_ADAPTER
  self.subdomain          = DEFAULT_SUBDOMAIN
  self
end