Class: PMP::Credential
Constant Summary
collapse
- CREDENTIAL_PARAMS =
[:scope, :token_expires_in, :label]
Constants included
from Connection
PMP::Connection::ALLOWED_CONNECTION_OPTIONS
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
Methods included from Connection
#add_request_auth, #connection, #process_options
#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(options={}, &block)
apply_configuration(options)
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, create_credentials_url, create_params(params))
response.body
end
|
#create_credentials_url ⇒ Object
59
60
61
|
# File 'lib/pmp/credential.rb', line 59
def create_credentials_url
root_document.auth['urn:collectiondoc:form:createcredentials'].url
end
|
#create_params(params = {}) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/pmp/credential.rb', line 34
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
55
56
57
|
# File 'lib/pmp/credential.rb', line 55
def credentials_url
root_document.auth['urn:collectiondoc:form:listcredentials'].url
end
|
#destroy(client_id) ⇒ Object
29
30
31
32
|
# File 'lib/pmp/credential.rb', line 29
def destroy(client_id)
response = request(:delete, remove_credentials_url(client_id))
response.body
end
|
#list ⇒ Object
19
20
21
22
|
# File 'lib/pmp/credential.rb', line 19
def list
response = request(:get, credentials_url)
response.body
end
|
#remove_credentials_url(client_id) ⇒ Object
63
64
65
66
|
# File 'lib/pmp/credential.rb', line 63
def remove_credentials_url(client_id)
link = root_document.auth['urn:collectiondoc:form:removecredentials']
link.where(client_id: client_id).url
end
|
#request(method, url, body = {}) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/pmp/credential.rb', line 42
def request(method, url, body={})
= {
'Accept' => "*/*",
'Content-Type' => [:put, :post].include?(method) ? "application/x-www-form-urlencoded" : nil
}
conn_opts = current_options.merge({headers: , basic_auth: true})
raw = connection(conn_opts).send(method, url, body)
PMP::Response.new(raw, {method: method, url: url, body: body})
end
|
#root_document ⇒ Object
68
69
70
|
# File 'lib/pmp/credential.rb', line 68
def root_document
@root ||= PMP::CollectionDocument.new(current_options.merge(href: endpoint))
end
|