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 Attribute Summary collapse
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
- #create(params = {}) ⇒ Object
- #create_credentials_url ⇒ Object
- #create_params(params = {}) ⇒ Object
- #credentials_url ⇒ Object
- #destroy(client_id) ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Credential
constructor
A new instance of Credential.
- #list ⇒ Object
- #remove_credentials_url(client_id) ⇒ 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.
15 16 17 18 19 20 21 |
# File 'lib/pmp/credential.rb', line 15 def initialize(={}, &block) apply_configuration() self.root = .delete(:root) yield(self) if block_given? end |
Instance Attribute Details
#root ⇒ Object
Returns the value of attribute root.
13 14 15 |
# File 'lib/pmp/credential.rb', line 13 def root @root end |
Instance Method Details
#create(params = {}) ⇒ Object
28 29 30 31 |
# File 'lib/pmp/credential.rb', line 28 def create(params={}) response = request(:post, create_credentials_url, create_params(params)) response.body end |
#create_credentials_url ⇒ Object
63 64 65 |
# File 'lib/pmp/credential.rb', line 63 def create_credentials_url root.auth['urn:collectiondoc:form:createcredentials'].url end |
#create_params(params = {}) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/pmp/credential.rb', line 38 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
59 60 61 |
# File 'lib/pmp/credential.rb', line 59 def credentials_url root.auth['urn:collectiondoc:form:listcredentials'].url end |
#destroy(client_id) ⇒ Object
33 34 35 36 |
# File 'lib/pmp/credential.rb', line 33 def destroy(client_id) response = request(:delete, remove_credentials_url(client_id)) response.body end |
#list ⇒ Object
23 24 25 26 |
# File 'lib/pmp/credential.rb', line 23 def list response = request(:get, credentials_url) response.body end |
#remove_credentials_url(client_id) ⇒ Object
67 68 69 70 |
# File 'lib/pmp/credential.rb', line 67 def remove_credentials_url(client_id) link = root.auth['urn:collectiondoc:form:removecredentials'] link.where(client_id: client_id).url end |
#request(method, url, body = {}) ⇒ Object
:nodoc:
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/pmp/credential.rb', line 46 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 |