Class: PMP::Client
Constant Summary
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
- #credentials(opts = {}) ⇒ Object
- #doc_of_type(type, opts = {}) ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
-
#method_missing(method, *args) ⇒ Object
assume you want to make a call on the root doc for stuff it can do.
-
#profile_href_for_type(type) ⇒ Object
private.
- #root(opts = {}) ⇒ Object
- #token(opts = {}) ⇒ Object
Methods included from Configuration
#apply_configuration, #configure, extended, #options, #reset!
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Client
Returns a new instance of Client.
8 9 10 11 |
# File 'lib/pmp/client.rb', line 8 def initialize(={}, &block) apply_configuration() yield(self) if block_given? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
assume you want to make a call on the root doc for stuff it can do
42 43 44 |
# File 'lib/pmp/client.rb', line 42 def method_missing(method, *args) self.root.send(method, *args) end |
Instance Method Details
#credentials(opts = {}) ⇒ Object
13 14 15 16 |
# File 'lib/pmp/client.rb', line 13 def credentials(opts={}) @credentials = nil if (opts != {}) @credentials ||= PMP::Credential.new(.merge(opts)) end |
#doc_of_type(type, opts = {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/pmp/client.rb', line 29 def doc_of_type(type, opts={}) doc = PMP::CollectionDocument.new(.merge(root:root(opts)).merge(opts)) doc.links['profile'] = Link.new(href: profile_href_for_type(type), type: "application/vnd.pmp.collection.doc+json") doc end |
#profile_href_for_type(type) ⇒ Object
private
37 38 39 |
# File 'lib/pmp/client.rb', line 37 def profile_href_for_type(type) "#{endpoint}profiles/#{type}" end |
#root(opts = {}) ⇒ Object
23 24 25 26 27 |
# File 'lib/pmp/client.rb', line 23 def root(opts={}) @root = nil if (opts != {}) opts = .merge(href: endpoint).merge(opts) @root ||= PMP::CollectionDocument.new(opts) end |