pmp 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/example/permissions.rb +67 -14
 - data/example/permissions_result.txt +1077 -0
 - data/lib/pmp.rb +1 -0
 - data/lib/pmp/client.rb +1 -1
 - data/lib/pmp/collection_document.rb +18 -10
 - data/lib/pmp/configuration.rb +14 -4
 - data/lib/pmp/connection.rb +1 -1
 - data/lib/pmp/credential.rb +1 -1
 - data/lib/pmp/link.rb +2 -2
 - data/lib/pmp/version.rb +1 -1
 - data/spec/collection_document_spec.rb +1 -1
 - data/spec/pmp_spec.rb +12 -0
 - metadata +5 -2
 
    
        data/lib/pmp.rb
    CHANGED
    
    
    
        data/lib/pmp/client.rb
    CHANGED
    
    | 
         @@ -27,7 +27,7 @@ module PMP 
     | 
|
| 
       27 
27 
     | 
    
         
             
                end
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
       29 
29 
     | 
    
         
             
                def doc_of_type(type, opts={})
         
     | 
| 
       30 
     | 
    
         
            -
                  doc = PMP::CollectionDocument.new(options.merge(opts))
         
     | 
| 
      
 30 
     | 
    
         
            +
                  doc = PMP::CollectionDocument.new(options.merge(root:root(opts)).merge(opts))
         
     | 
| 
       31 
31 
     | 
    
         
             
                  doc.links['profile'] = Link.new(href: profile_href_for_type(type), type: "application/vnd.pmp.collection.doc+json")
         
     | 
| 
       32 
32 
     | 
    
         
             
                  doc
         
     | 
| 
       33 
33 
     | 
    
         
             
                end
         
     | 
| 
         @@ -39,16 +39,17 @@ module PMP 
     | 
|
| 
       39 
39 
     | 
    
         
             
                # TODO: check if this is a json string or hash, for now assume it has been mashified
         
     | 
| 
       40 
40 
     | 
    
         
             
                def initialize(options={}, &block)
         
     | 
| 
       41 
41 
     | 
    
         
             
                  super()
         
     | 
| 
      
 42 
     | 
    
         
            +
                  apply_configuration(options)
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                  self.root     = current_options.delete(:root)
         
     | 
| 
      
 45 
     | 
    
         
            +
                  self.href     = current_options.delete(:href)
         
     | 
| 
      
 46 
     | 
    
         
            +
                  self.version  = current_options.delete(:version) || '1.0'
         
     | 
| 
       42 
47 
     | 
    
         | 
| 
       43 
48 
     | 
    
         
             
                  self.links    = PMP::Links.new(self)
         
     | 
| 
       44 
     | 
    
         
            -
                  self.version  = options.delete(:version) || '1.0'
         
     | 
| 
       45 
     | 
    
         
            -
                  self.href     = options.delete(:href)
         
     | 
| 
       46 
49 
     | 
    
         | 
| 
       47 
50 
     | 
    
         
             
                  # if there is a doc to be had, pull it out
         
     | 
| 
       48 
     | 
    
         
            -
                  self.response =  
     | 
| 
       49 
     | 
    
         
            -
                  self.original =  
     | 
| 
       50 
     | 
    
         
            -
             
     | 
| 
       51 
     | 
    
         
            -
                  apply_configuration(options)
         
     | 
| 
      
 51 
     | 
    
         
            +
                  self.response = current_options.delete(:response)
         
     | 
| 
      
 52 
     | 
    
         
            +
                  self.original = current_options.delete(:document)
         
     | 
| 
       52 
53 
     | 
    
         | 
| 
       53 
54 
     | 
    
         
             
                  yield(self) if block_given?
         
     | 
| 
       54 
55 
     | 
    
         
             
                end
         
     | 
| 
         @@ -100,14 +101,21 @@ module PMP 
     | 
|
| 
       100 
101 
     | 
    
         
             
                end
         
     | 
| 
       101 
102 
     | 
    
         | 
| 
       102 
103 
     | 
    
         
             
                def edit_link(method)
         
     | 
| 
       103 
     | 
    
         
            -
                  # first, need the root, use the endpoint
         
     | 
| 
       104 
104 
     | 
    
         
             
                  link = root_document.edit['urn:pmp:form:documentsave']
         
     | 
| 
       105 
105 
     | 
    
         
             
                  raise "Edit link does not specify saving via #{method}" unless (link && link.hints.allow.include?(method))
         
     | 
| 
       106 
106 
     | 
    
         
             
                  link
         
     | 
| 
       107 
107 
     | 
    
         
             
                end
         
     | 
| 
       108 
108 
     | 
    
         | 
| 
      
 109 
     | 
    
         
            +
                def root
         
     | 
| 
      
 110 
     | 
    
         
            +
                  @root
         
     | 
| 
      
 111 
     | 
    
         
            +
                end
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                def root=(r)
         
     | 
| 
      
 114 
     | 
    
         
            +
                  @root
         
     | 
| 
      
 115 
     | 
    
         
            +
                end
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
       109 
117 
     | 
    
         
             
                def root_document
         
     | 
| 
       110 
     | 
    
         
            -
                  PMP::CollectionDocument.new( 
     | 
| 
      
 118 
     | 
    
         
            +
                  @root ||= PMP::CollectionDocument.new(current_options.merge(href: endpoint))
         
     | 
| 
       111 
119 
     | 
    
         
             
                end
         
     | 
| 
       112 
120 
     | 
    
         | 
| 
       113 
121 
     | 
    
         
             
                def loaded?
         
     | 
| 
         @@ -116,7 +124,7 @@ module PMP 
     | 
|
| 
       116 
124 
     | 
    
         | 
| 
       117 
125 
     | 
    
         
             
                def setup_oauth_token
         
     | 
| 
       118 
126 
     | 
    
         
             
                  if !oauth_token
         
     | 
| 
       119 
     | 
    
         
            -
                    token = PMP::Token.new( 
     | 
| 
      
 127 
     | 
    
         
            +
                    token = PMP::Token.new(current_options).get_token
         
     | 
| 
       120 
128 
     | 
    
         
             
                    self.oauth_token = token.token
         
     | 
| 
       121 
129 
     | 
    
         
             
                  end
         
     | 
| 
       122 
130 
     | 
    
         
             
                end
         
     | 
| 
         @@ -127,7 +135,7 @@ module PMP 
     | 
|
| 
       127 
135 
     | 
    
         
             
                  setup_oauth_token
         
     | 
| 
       128 
136 
     | 
    
         | 
| 
       129 
137 
     | 
    
         
             
                  begin
         
     | 
| 
       130 
     | 
    
         
            -
                    raw = connection( 
     | 
| 
      
 138 
     | 
    
         
            +
                    raw = connection(current_options.merge({url: url})).send(method) do |request|
         
     | 
| 
       131 
139 
     | 
    
         
             
                      if [:post, :put].include?(method.to_sym) && !body.blank?
         
     | 
| 
       132 
140 
     | 
    
         
             
                        request.body = body.is_a?(String) ? body : body.to_json
         
     | 
| 
       133 
141 
     | 
    
         
             
                      end
         
     | 
    
        data/lib/pmp/configuration.rb
    CHANGED
    
    | 
         @@ -38,20 +38,26 @@ module PMP 
     | 
|
| 
       38 
38 
     | 
    
         | 
| 
       39 
39 
     | 
    
         
             
                included do
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
                  attr_accessor : 
     | 
| 
      
 41 
     | 
    
         
            +
                  attr_accessor :current_options
         
     | 
| 
       42 
42 
     | 
    
         | 
| 
       43 
43 
     | 
    
         
             
                  VALID_OPTIONS_KEYS.each do |key|
         
     | 
| 
       44 
44 
     | 
    
         
             
                    define_method "#{key}=" do |arg|
         
     | 
| 
       45 
45 
     | 
    
         
             
                      self.instance_variable_set("@#{key}", arg)
         
     | 
| 
       46 
     | 
    
         
            -
                      self. 
     | 
| 
      
 46 
     | 
    
         
            +
                      self.current_options.merge!({:"#{key}" => arg})
         
     | 
| 
       47 
47 
     | 
    
         
             
                    end
         
     | 
| 
       48 
48 
     | 
    
         
             
                  end
         
     | 
| 
       49 
49 
     | 
    
         | 
| 
       50 
50 
     | 
    
         
             
                end
         
     | 
| 
       51 
51 
     | 
    
         | 
| 
      
 52 
     | 
    
         
            +
                def options
         
     | 
| 
      
 53 
     | 
    
         
            +
                  options = {}
         
     | 
| 
      
 54 
     | 
    
         
            +
                  VALID_OPTIONS_KEYS.each { |k| options[k] = send(k) }
         
     | 
| 
      
 55 
     | 
    
         
            +
                  options
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
       52 
58 
     | 
    
         
             
                def apply_configuration(opts={})
         
     | 
| 
       53 
     | 
    
         
            -
                   
     | 
| 
       54 
     | 
    
         
            -
                  self. 
     | 
| 
      
 59 
     | 
    
         
            +
                  options = PMP.options.merge(opts)
         
     | 
| 
      
 60 
     | 
    
         
            +
                  self.current_options = options
         
     | 
| 
       55 
61 
     | 
    
         
             
                  VALID_OPTIONS_KEYS.each do |key|
         
     | 
| 
       56 
62 
     | 
    
         
             
                    send("#{key}=", options[key])
         
     | 
| 
       57 
63 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -74,6 +80,10 @@ module PMP 
     | 
|
| 
       74 
80 
     | 
    
         
             
                  self
         
     | 
| 
       75 
81 
     | 
    
         
             
                end
         
     | 
| 
       76 
82 
     | 
    
         | 
| 
      
 83 
     | 
    
         
            +
                def self.extended(base)
         
     | 
| 
      
 84 
     | 
    
         
            +
                  base.reset!
         
     | 
| 
      
 85 
     | 
    
         
            +
                end
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
       77 
87 
     | 
    
         
             
                module ClassMethods
         
     | 
| 
       78 
88 
     | 
    
         | 
| 
       79 
89 
     | 
    
         
             
                  def keys
         
     | 
    
        data/lib/pmp/connection.rb
    CHANGED
    
    | 
         @@ -34,9 +34,9 @@ module PMP 
     | 
|
| 
       34 
34 
     | 
    
         
             
                    faraday.request :url_encoded
         
     | 
| 
       35 
35 
     | 
    
         | 
| 
       36 
36 
     | 
    
         
             
                    faraday.response :mashify
         
     | 
| 
       37 
     | 
    
         
            -
                    faraday.response :logger if opts[:debug]
         
     | 
| 
       38 
37 
     | 
    
         
             
                    faraday.response :json
         
     | 
| 
       39 
38 
     | 
    
         
             
                    faraday.response :raise_error
         
     | 
| 
      
 39 
     | 
    
         
            +
                    faraday.response :logger if opts[:debug]
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
41 
     | 
    
         
             
                    faraday.adapter opts[:adapter]
         
     | 
| 
       42 
42 
     | 
    
         
             
                  end
         
     | 
    
        data/lib/pmp/credential.rb
    CHANGED
    
    | 
         @@ -41,7 +41,7 @@ module PMP 
     | 
|
| 
       41 
41 
     | 
    
         
             
                    'Content-Type' => [:put, :post].include?(method) ? "application/x-www-form-urlencoded" : nil
         
     | 
| 
       42 
42 
     | 
    
         
             
                  }
         
     | 
| 
       43 
43 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
                  conn_opts =  
     | 
| 
      
 44 
     | 
    
         
            +
                  conn_opts = current_options.merge({headers: headers, basic_auth: true})
         
     | 
| 
       45 
45 
     | 
    
         | 
| 
       46 
46 
     | 
    
         
             
                  raw = connection(conn_opts).send(method, url, body)
         
     | 
| 
       47 
47 
     | 
    
         
             
                  PMP::Response.new(raw, {method: method, url: url, body: body})
         
     | 
    
        data/lib/pmp/link.rb
    CHANGED
    
    | 
         @@ -44,7 +44,7 @@ module PMP 
     | 
|
| 
       44 
44 
     | 
    
         
             
                  self.class.new(attributes.merge({'params'=>params}), parent)
         
     | 
| 
       45 
45 
     | 
    
         
             
                end
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
     | 
    
         
            -
                def as_json
         
     | 
| 
      
 47 
     | 
    
         
            +
                def as_json(options={})
         
     | 
| 
       48 
48 
     | 
    
         
             
                  extract_attributes
         
     | 
| 
       49 
49 
     | 
    
         
             
                end
         
     | 
| 
       50 
50 
     | 
    
         | 
| 
         @@ -58,7 +58,7 @@ module PMP 
     | 
|
| 
       58 
58 
     | 
    
         
             
                  # puts "retrieve method: #{method}"
         
     | 
| 
       59 
59 
     | 
    
         
             
                  # puts "retrieve url: #{url}"
         
     | 
| 
       60 
60 
     | 
    
         
             
                  # response = parent.request((method || 'get').to_sym, url)
         
     | 
| 
       61 
     | 
    
         
            -
                  PMP::CollectionDocument.new(parent.options.merge(href: url))
         
     | 
| 
      
 61 
     | 
    
         
            +
                  @doc ||= PMP::CollectionDocument.new(parent.options.merge(href: url, root: parent.root))
         
     | 
| 
       62 
62 
     | 
    
         
             
                end
         
     | 
| 
       63 
63 
     | 
    
         | 
| 
       64 
64 
     | 
    
         
             
                def method_missing(method, *args)
         
     | 
    
        data/lib/pmp/version.rb
    CHANGED
    
    
| 
         @@ -170,7 +170,7 @@ describe PMP::CollectionDocument do 
     | 
|
| 
       170 
170 
     | 
    
         
             
                it "should handle 404 results on a search" do
         
     | 
| 
       171 
171 
     | 
    
         | 
| 
       172 
172 
     | 
    
         
             
                  stub_request(:get, "https://api-sandbox.pmp.io/docs").
         
     | 
| 
       173 
     | 
    
         
            -
                    with(:headers => {'Accept'=>'application/vnd.pmp.collection.doc+json', 'Authorization'=>'Bearer thisisatesttoken', 'Content-Type'=>'application/vnd.pmp.collection.doc+json', 'Host'=>'api-sandbox.pmp.io:443' 
     | 
| 
      
 173 
     | 
    
         
            +
                    with(:headers => {'Accept'=>'application/vnd.pmp.collection.doc+json', 'Authorization'=>'Bearer thisisatesttoken', 'Content-Type'=>'application/vnd.pmp.collection.doc+json', 'Host'=>'api-sandbox.pmp.io:443'}).
         
     | 
| 
       174 
174 
     | 
    
         
             
                    to_return(:status=>404, :body=>"Not Found", :remote_ip=>"107.20.158.113", :headers=>{"Access-Control-Allow-Headers"=>"origin, x-http-method-override, accept, content-type, authorization, x-pingother", "Access-Control-Allow-Methods"=>"GET,OPTIONS,HEAD,PUT,POST,DELETE,PATCH", "Access-Control-Allow-Origin"=>"*", "Content-Type"=>"application/vnd.pmp.collection.doc+json", "Date"=>"Thu, 24 Oct 2013 17:20:04 GMT", "Vary"=>"Accept-Encoding", "X-Powered-By"=>"Express", "X-Response-Time"=>"18ms", "Content-Length"=>"9", "Connection"=>"keep-alive"})
         
     | 
| 
       175 
175 
     | 
    
         | 
| 
       176 
176 
     | 
    
         
             
                  @doc.query["urn:pmp:query:docs"].items.must_equal []
         
     | 
    
        data/spec/pmp_spec.rb
    ADDED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: pmp
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 0.2. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.2.2
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Andrew Kuklewicz
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire: 
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2013-10- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2013-10-25 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: bundler
         
     | 
| 
         @@ -278,6 +278,7 @@ files: 
     | 
|
| 
       278 
278 
     | 
    
         
             
            - README.md
         
     | 
| 
       279 
279 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       280 
280 
     | 
    
         
             
            - example/permissions.rb
         
     | 
| 
      
 281 
     | 
    
         
            +
            - example/permissions_result.txt
         
     | 
| 
       281 
282 
     | 
    
         
             
            - lib/pmp.rb
         
     | 
| 
       282 
283 
     | 
    
         
             
            - lib/pmp/client.rb
         
     | 
| 
       283 
284 
     | 
    
         
             
            - lib/pmp/collection_document.rb
         
     | 
| 
         @@ -303,6 +304,7 @@ files: 
     | 
|
| 
       303 
304 
     | 
    
         
             
            - spec/link_spec.rb
         
     | 
| 
       304 
305 
     | 
    
         
             
            - spec/links_spec.rb
         
     | 
| 
       305 
306 
     | 
    
         
             
            - spec/parser_spec.rb
         
     | 
| 
      
 307 
     | 
    
         
            +
            - spec/pmp_spec.rb
         
     | 
| 
       306 
308 
     | 
    
         
             
            - spec/response_spec.rb
         
     | 
| 
       307 
309 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       308 
310 
     | 
    
         
             
            - spec/token_spec.rb
         
     | 
| 
         @@ -343,6 +345,7 @@ test_files: 
     | 
|
| 
       343 
345 
     | 
    
         
             
            - spec/link_spec.rb
         
     | 
| 
       344 
346 
     | 
    
         
             
            - spec/links_spec.rb
         
     | 
| 
       345 
347 
     | 
    
         
             
            - spec/parser_spec.rb
         
     | 
| 
      
 348 
     | 
    
         
            +
            - spec/pmp_spec.rb
         
     | 
| 
       346 
349 
     | 
    
         
             
            - spec/response_spec.rb
         
     | 
| 
       347 
350 
     | 
    
         
             
            - spec/spec_helper.rb
         
     | 
| 
       348 
351 
     | 
    
         
             
            - spec/token_spec.rb
         
     |