Class: PMP::Token
Constant Summary
Constants included from Configuration
Configuration::DEFAULT_ADAPTER, Configuration::DEFAULT_CLIENT_ID, Configuration::DEFAULT_CLIENT_SECRET, Configuration::DEFAULT_ENDPOINT, Configuration::DEFAULT_TOKEN_TYPE, Configuration::DEFAULT_USER_AGENT, Configuration::VALID_OPTIONS_KEYS
Instance Method Summary collapse
- #connection_options(opts = {}) ⇒ Object
- #get_token ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Token
constructor
A new instance of Token.
- #token_url ⇒ Object
Methods included from Configuration
#apply_configuration, #configure, extended, #options, #reset!
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Token
Returns a new instance of Token.
10 11 12 13 14 |
# File 'lib/pmp/token.rb', line 10 def initialize(={}, &block) apply_configuration() yield(self) if block_given? end |
Instance Method Details
#connection_options(opts = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pmp/token.rb', line 36 def (opts={}) headers = opts.delete(:headers) || {} = { headers: { 'User-Agent' => opts[:user_agent], 'Accept' => 'application/json', 'Content-Type' => 'application/x-www-form-urlencoded' }, ssl: {:verify => false}, url: opts[:endpoint] }.merge(opts) [:headers] = [:headers].merge(headers) end |
#get_token ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pmp/token.rb', line 20 def get_token = { site: endpoint, token_url: token_url, connection_opts: () } client = OAuth2::Client.new(client_id, client_secret, ) do |faraday| faraday.request :url_encoded faraday.response :logger if debug faraday.adapter adapter end client.client_credentials.get_token end |
#token_url ⇒ Object
16 17 18 |
# File 'lib/pmp/token.rb', line 16 def token_url ['token_url'] || '/auth/access_token' end |