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



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(options.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(options.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 = options.merge(href: endpoint).merge(opts)
  @root ||= PMP::CollectionDocument.new(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