Class: PMP::Client

Inherits:
Object
  • Object
show all
Includes:
Configuration
Defined in:
lib/pmp/client.rb

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

Methods included from Configuration

#apply_configuration, #configure, extended, #options, #reset!

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:

  • _self (PMP::Client)

    the object that the method was called on



8
9
10
11
# File 'lib/pmp/client.rb', line 8

def initialize(options={}, &block)
  apply_configuration(options)
  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



46
47
48
# File 'lib/pmp/client.rb', line 46

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(options.merge(opts))
end

#doc_of_type(type, opts = {}) ⇒ Object



33
34
35
36
37
# File 'lib/pmp/client.rb', line 33

def doc_of_type(type, opts={})
  doc = PMP::CollectionDocument.new(options.merge(root:root(opts)).merge(opts))
  doc.links['profile'] = Link.new(href: profile_href_for_type(type), type: "application/vnd.collection.doc+json")
  doc
end

#new_root(opts = {}) ⇒ Object



28
29
30
31
# File 'lib/pmp/client.rb', line 28

def new_root(opts={})
  root_options = options.merge(opts).merge(href: endpoint)
  PMP::CollectionDocument.new(root_options).tap{|r| r.root = r }
end

#profile_href_for_type(type) ⇒ Object

private



41
42
43
# File 'lib/pmp/client.rb', line 41

def profile_href_for_type(type)
  "#{endpoint}profiles/#{type}"
end

#root(opts = {}) ⇒ Object



23
24
25
26
# File 'lib/pmp/client.rb', line 23

def root(opts={})
  @root = nil if (opts != {})
  @root ||= new_root(opts)
end

#token(opts = {}) ⇒ Object



18
19
20
21
# File 'lib/pmp/client.rb', line 18

def token(opts={})
  @token = nil if (opts != {})
  @token ||= PMP::Token.new(options.merge(opts)).get_token
end