Module: PMP::Configuration

Extended by:
ActiveSupport::Concern
Included in:
PMP, Client, CollectionDocument, Credential, Token
Defined in:
lib/pmp/configuration.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VALID_OPTIONS_KEYS =
[
  :user,
  :password,
  :client_id,
  :client_secret,
  :oauth_token,
  :token_type,
  :adapter,
  :endpoint,
  :user_agent,
  :debug
].freeze
DEFAULT_CLIENT_ID =

this you need to get from pmp, not covered by this

nil
DEFAULT_CLIENT_SECRET =
nil
DEFAULT_ADAPTER =

Adapters are whatever Faraday supports - I like excon alot, so I’m defaulting it

:excon
DEFAULT_ENDPOINT =

The api endpoint for YQL

'https://api.pmp.io/'.freeze
DEFAULT_USER_AGENT =

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

"PMP Ruby Gem #{PMP::VERSION}".freeze
DEFAULT_TOKEN_TYPE =
'Bearer'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



87
88
89
# File 'lib/pmp/configuration.rb', line 87

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

Instance Method Details

#apply_configuration(opts = {}) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/pmp/configuration.rb', line 61

def apply_configuration(opts={})
  options = PMP.options.merge(opts)
  self.current_options = options
  VALID_OPTIONS_KEYS.each do |key|
    send("#{key}=", options[key])
  end
end

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

Convenience method to allow for global setting of configuration options

Yields:

  • (_self)

Yield Parameters:



70
71
72
# File 'lib/pmp/configuration.rb', line 70

def configure
  yield self
end

#optionsObject



55
56
57
58
59
# File 'lib/pmp/configuration.rb', line 55

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

#reset!Object

Reset configuration options to their defaults



75
76
77
78
79
80
81
82
83
84
85
# File 'lib/pmp/configuration.rb', line 75

def reset!
  @options = {}
  self.client_id     = DEFAULT_CLIENT_ID
  self.client_secret = DEFAULT_CLIENT_SECRET
  self.adapter       = DEFAULT_ADAPTER
  self.endpoint      = DEFAULT_ENDPOINT
  self.user_agent    = DEFAULT_USER_AGENT
  self.token_type    = DEFAULT_TOKEN_TYPE
  self.debug         = ENV['DEBUG']
  self
end