Sha256: 7f68e7e3b3f271e5eaaadcfdb2cec967d5c9ce0510f355e587f894a077e3f81b

Contents?: true

Size: 1.14 KB

Versions: 6

Compression:

Stored size: 1.14 KB

Contents

# -*- encoding: utf-8 -*-

module PMP
  class Client

    include Configuration

    def initialize(options={}, &block)
      apply_configuration(options)
      yield(self) if block_given?
    end

    def credentials(opts={})
      @credentials = nil if (opts != {})
      @credentials ||= PMP::Credential.new(options.merge(opts))
    end

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

    def root(opts={})
      @root = nil if (opts != {})
      opts = options.merge(href: endpoint).merge(opts)
      @root ||= PMP::CollectionDocument.new(opts)
    end

    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

    # private

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

    # assume you want to make a call on the root doc for stuff it can do
    def method_missing(method, *args)
      self.root.send(method, *args)
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pmp-0.3.2 lib/pmp/client.rb
pmp-0.3.1 lib/pmp/client.rb
pmp-0.3.0 lib/pmp/client.rb
pmp-0.2.4 lib/pmp/client.rb
pmp-0.2.3 lib/pmp/client.rb
pmp-0.2.2 lib/pmp/client.rb