Class: PMP::Credential
- Inherits:
-
Object
- Object
- PMP::Credential
- Includes:
- Configuration, Connection
- Defined in:
- lib/pmp/credential.rb
Constant Summary collapse
- CREDENTIAL_PARAMS =
[:scope, :token_expires_in, :label]
Constants included from Connection
PMP::Connection::ALLOWED_CONNECTION_OPTIONS
Constants included from Configuration
PMP::Configuration::DEFAULT_ADAPTER, PMP::Configuration::DEFAULT_CLIENT_ID, PMP::Configuration::DEFAULT_CLIENT_SECRET, PMP::Configuration::DEFAULT_ENDPOINT, PMP::Configuration::DEFAULT_TOKEN_TYPE, PMP::Configuration::DEFAULT_USER_AGENT, PMP::Configuration::VALID_OPTIONS_KEYS
Instance Method Summary collapse
- #create(params = {}) ⇒ Object
- #create_params(params = {}) ⇒ Object
- #credentials_url ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Credential
constructor
A new instance of Credential.
- #list ⇒ Object
-
#request(method, url, body = {}) ⇒ Object
:nodoc:.
Methods included from Connection
#add_request_auth, #connection, #process_options
Methods included from Configuration
#apply_configuration, #configure, extended, #options, #reset!
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Credential
Returns a new instance of Credential.
13 14 15 16 17 |
# File 'lib/pmp/credential.rb', line 13 def initialize(={}, &block) apply_configuration() yield(self) if block_given? end |
Instance Method Details
#create(params = {}) ⇒ Object
24 25 26 27 |
# File 'lib/pmp/credential.rb', line 24 def create(params={}) response = request(:post, credentials_url, create_params(params)) response.body end |
#create_params(params = {}) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/pmp/credential.rb', line 29 def create_params(params={}) HashWithIndifferentAccess.new({ scope: 'read', token_expires_in: 60*60*24*30, label: "#{user}: #{Time.now}" }).merge(params.select{|k,v| CREDENTIAL_PARAMS.include?(k.to_sym)}) end |
#credentials_url ⇒ Object
50 51 52 |
# File 'lib/pmp/credential.rb', line 50 def credentials_url "#{endpoint}auth/credentials" end |
#list ⇒ Object
19 20 21 22 |
# File 'lib/pmp/credential.rb', line 19 def list response = request(:get, credentials_url) response.body end |
#request(method, url, body = {}) ⇒ Object
:nodoc:
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/pmp/credential.rb', line 37 def request(method, url, body={}) # :nodoc: headers = { 'Accept' => "*/*", 'Content-Type' => [:put, :post].include?(method) ? "application/x-www-form-urlencoded" : nil } conn_opts = .merge({headers: headers, basic_auth: true}) raw = connection(conn_opts).send(method, url, body) PMP::Response.new(raw, {method: method, url: url, body: body}) end |