Module: BWAPI::Configuration

Included in:
BWAPI
Defined in:
lib/bwapi/configuration.rb

Overview

Configuration module to set default and custom client credentials

Constant Summary collapse

OPTION_KEYS =
[
  :api_endpoint,
  :user_agent,
  :adapter,
  :username,
  :password,
  :grant_type,
  :access_token,
  :refresh_token,
  :expires_in,
  :client_id,
  :client_secret,
  :verify_ssl,
  :netrc,
  :netrc_file,
  :debug,
  :log
].freeze
DEFAULT_ADAPTER =
Faraday.default_adapter
DEFAULT_API_ENDPOINT =
ENV['BWAPI_API_ENDPOINT'] || 'https://newapi.brandwatch.com/'
DEFAULT_CLIENT_ID =
'brandwatch-api-client'
DEFAULT_USER_AGENT =
"BWAPI Ruby Gem #{BWAPI::VERSION}".freeze
DEFAULT_NETRC_FILE =
File.join(ENV['HOME'], '.netrc')
DEFAULT_LOGGER_FILE =
Logger.new("#{Dir.pwd}/bwapi.log")

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Extend hook



38
39
40
# File 'lib/bwapi/configuration.rb', line 38

def self.extended(base)
  base.reset
end

Instance Method Details

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

Set configuration options using a block

Yields:

  • (_self)

Yield Parameters:



43
44
45
# File 'lib/bwapi/configuration.rb', line 43

def configure
  yield self
end

#optionsObject

Convert option_keys to hash and return



48
49
50
# File 'lib/bwapi/configuration.rb', line 48

def options
  OPTION_KEYS.reduce({}) { |a, e| a.merge!(e => send(e)) }
end

#resetObject

Reset the configuration options



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/bwapi/configuration.rb', line 53

def reset
  self.adapter             = DEFAULT_ADAPTER
  self.user_agent          = DEFAULT_USER_AGENT
  self.api_endpoint        = DEFAULT_API_ENDPOINT
  self.username            = nil
  self.password            = nil
  self.grant_type          = nil
  self.access_token        = nil
  self.refresh_token       = nil
  self.client_id           = DEFAULT_CLIENT_ID
  self.client_secret       = nil
  self.verify_ssl          = true
  self.netrc               = false
  self.netrc_file          = DEFAULT_NETRC_FILE
  self.debug               = false
  self.log                 = DEFAULT_LOGGER_FILE
end