pmp 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c72afc8f62a4b52dbd5c64cda59ae156da8ad2db
4
- data.tar.gz: 1ac3fbe0675362c8df8fb638d183bde8ace6d84f
3
+ metadata.gz: 8e96a6950ad0285f1269552f82ec2ceb83abc756
4
+ data.tar.gz: c0d564eb5a48aa79242bba4033acff0c38c207ab
5
5
  SHA512:
6
- metadata.gz: 41c25310c5905255a64b395dbf1d1c2a88422e1804547cb886b4083f2828a52d9519f31e7f7f97c955238c94ef7a7ba4ce56b3192617becbd38235fcdb87726e
7
- data.tar.gz: 83d27763b3c57efe0d1477c2aebddcff4d2aedd968dc5b5564d8abeebaea8440ad6064eddaea06f7f4ffc19b2ccd0df801da2a2c6193fc105fcf3d4221e56c03
6
+ metadata.gz: ffef1af394ef66319065fa9d09c76211bc7a6f48bf897cc0b4b878057856b08f450bb7851786cda12709003c8ecf3faaff02543ae8fbc337acf8ac49763f582d
7
+ data.tar.gz: 07f5be73a5e7749597080b8c16af46e9cb6a1050e80a6b37961158dc46cd90f54adfd62392d7147166f389233a1b45f09450acc1a422b3e5235da1261ee32ddd
data/README.md CHANGED
@@ -110,7 +110,7 @@ doc.title = "this is another awesome example, cool?"
110
110
  doc.adding_an_attribute = "this will get saved as a new attribute adding-an-attribute"
111
111
 
112
112
  # can add links (doesn't check schema yet)
113
- doc.links['some-new-link'] = PMP::Link.new(doc, {href:'http://somenewlink.io'})
113
+ doc.links['some-new-link'] = PMP::Link.new({href:'http://somenewlink.io'})
114
114
  new_link = doc.some_new_link
115
115
 
116
116
  # save changes
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'pmp'
6
+
7
+ # ------------------------------------------------------------------------------
8
+ # Setup: Make sure you can make a client with id and secret
9
+ # ------------------------------------------------------------------------------
10
+ client_id = ENV['PMP_CLIENT_ID']
11
+ client_secret = ENV['PMP_CLIENT_SECRET']
12
+
13
+ raise "PMP_CLIENT_ID PMP_CLIENT_SECRET not set" unless client_id && client_secret
14
+
15
+ # doing this against the sandbox for now
16
+ endpoint = 'https://api-sandbox.pmp.io/'
17
+
18
+ # make a new client, assume id and secret are in the env
19
+ pmp = PMP::Client.new(client_id: client_id, client_secret: client_secret, endpoint: endpoint)
20
+
21
+
22
+ # ------------------------------------------------------------------------------
23
+ # Step 1: Make 3 orgs that will end up with different permissions
24
+ # ------------------------------------------------------------------------------
25
+ organizations = (0..2).map do |index|
26
+ # make a new 'organization' of profile type user
27
+ org = pmp.doc_of_type('user')
28
+
29
+ org.title = "pmp ruby example, permissions: org #{index}"
30
+ org.tags = ['pmp_example_permissions']
31
+ org.auth = {
32
+ user: "pmp_ruby_org_#{index}",
33
+ password: SecureRandom.uuid,
34
+ scope: 'write'
35
+ }
36
+ org.save
37
+ org
38
+ end
39
+ puts "Step 1 complete: organizations: #{organzations.to_json}\n\n"
40
+
41
+
42
+ # ------------------------------------------------------------------------------
43
+ # Step 2: Make 4 permission groups, 0:[0,1], 1:[0], 2:[1], and an empty group 3:[]
44
+ # ------------------------------------------------------------------------------
45
+ group_orgs = [ [0,1], [0], [1], [] ]
46
+ permission_groups = group_orgs.collect do |orgs|
47
+ group = pmp.doc_of_type('group')
48
+ group.tags = ['pmp_example_permissions']
49
+ group.title = "pmp ruby example, permissions: permission group #{orgs.inspect}"
50
+ group.links['item'] = orgs.map{|o| PMP::Link(href: organization[o].href)} if (orgs.size > 0)
51
+ group.save
52
+ group
53
+ end
54
+
55
+ puts "Step 2 complete: permission_groups: #{permission_groups.to_json}\n\n"
56
+
57
+ # ------------------------------------------------------------------------------
58
+ # Step 3: Make docs to be protected
59
+ # ------------------------------------------------------------------------------
60
+ documents = (0..3).collect do |index|
61
+ doc = pmp.doc_of_type('story')
62
+ doc.tags = ['pmp_example_permissions']
63
+ doc.title = "pmp ruby example, permissions: story #{index}"
64
+ end
65
+
66
+ documents[0].links['permission'] = { href: permission_groups[0].href, operation: 'read' }
67
+
68
+ documents[1].links['permission'] = [
69
+ {
70
+ href: permission_groups[2].href,
71
+ operation: 'read',
72
+ blacklist: true
73
+ },
74
+ {
75
+ href: permission_groups[1].href,
76
+ operation: 'read'
77
+ },
78
+ ]
79
+
80
+ documents[3].links['permission'] = { href: permission_groups[3].href, operation: 'read' }
81
+
82
+ documents.each{|d| d.save }
83
+
84
+
85
+ # ------------------------------------------------------------------------------
86
+ # Step 4: Make credentials for each org
87
+ # ------------------------------------------------------------------------------
88
+ credentials = organizations.map do |org|
89
+ pmp.credentials.create(user: org.auth['user'], password: org.auth['password'])
90
+ end
data/lib/pmp.rb CHANGED
@@ -16,6 +16,7 @@ require 'pmp/link'
16
16
  require 'pmp/collection_document'
17
17
 
18
18
  require 'pmp/token'
19
+ require 'pmp/credential'
19
20
  require 'pmp/client'
20
21
 
21
22
  module PMP
data/lib/pmp/client.rb CHANGED
@@ -10,13 +10,29 @@ module PMP
10
10
  yield(self) if block_given?
11
11
  end
12
12
 
13
+ def credentials(opts={})
14
+ @credentials ||= PMP::Credential.new(options.merge(opts))
15
+ end
16
+
13
17
  def token(opts={})
14
18
  @token ||= PMP::Token.new(options.merge(opts)).get_token
15
19
  end
16
20
 
17
- def root(opts={}, &block)
21
+ def root(opts={})
18
22
  opts = options.merge(href: endpoint).merge(opts)
19
- @root ||= PMP::CollectionDocument.new(opts, &block)
23
+ @root ||= PMP::CollectionDocument.new(opts)
24
+ end
25
+
26
+ def doc_of_type(type, opts={})
27
+ doc = PMP::CollectionDocument.new(options.merge(opts))
28
+ doc.links['profile'] = Link.new(href: profile_href_for_type(type), type: "application/vnd.pmp.collection.doc+json")
29
+ doc
30
+ end
31
+
32
+ # private
33
+
34
+ def profile_href_for_type(type)
35
+ "#{endpoint}profiles/#{type}"
20
36
  end
21
37
 
22
38
  end
@@ -87,9 +87,9 @@ module PMP
87
87
 
88
88
  def save
89
89
  set_guid_if_blank
90
-
91
90
  url = edit_link('PUT').where(guid: self.guid).url
92
- request(:put, url, self)
91
+ response = request(:put, url, self)
92
+ self.href = response.body['url']
93
93
  end
94
94
 
95
95
  def delete
@@ -114,8 +114,18 @@ module PMP
114
114
  !!self.loaded
115
115
  end
116
116
 
117
+ def setup_oauth_token
118
+ if !oauth_token
119
+ token = PMP::Token.new(options).get_token
120
+ self.oauth_token = token.token
121
+ end
122
+ end
123
+
117
124
  # url includes any params - full url
118
125
  def request(method, url, body=nil) # :nodoc:
126
+
127
+ setup_oauth_token
128
+
119
129
  raw = connection(options.merge({url: url})).send(method) do |request|
120
130
  if [:post, :put].include?(method.to_sym) && !body.blank?
121
131
  request.body = body.is_a?(String) ? body : body.to_json
@@ -131,7 +141,11 @@ module PMP
131
141
  end
132
142
 
133
143
  def method_missing(method, *args)
134
- load if (method.to_s.last != '=') && !loaded?
144
+ if (method.to_s.last != '=') && !loaded?
145
+ load
146
+ return self.send(method, *args) if self.respond_to?(method)
147
+ end
148
+
135
149
  super
136
150
  end
137
151
 
@@ -8,6 +8,8 @@ module PMP
8
8
  extend ActiveSupport::Concern
9
9
 
10
10
  VALID_OPTIONS_KEYS = [
11
+ :user,
12
+ :password,
11
13
  :client_id,
12
14
  :client_secret,
13
15
  :oauth_token,
@@ -72,12 +74,6 @@ module PMP
72
74
  self
73
75
  end
74
76
 
75
- def options
76
- options = {}
77
- VALID_OPTIONS_KEYS.each { |k| options[k] = send(k) }
78
- options
79
- end
80
-
81
77
  module ClassMethods
82
78
 
83
79
  def keys
@@ -14,13 +14,22 @@ module PMP
14
14
  :adapter,
15
15
  :ssl,
16
16
  :oauth_token,
17
+ :basic_auth,
18
+ :user,
19
+ :password,
17
20
  :debug
18
21
  ].freeze
19
22
 
20
23
  def connection(options={})
21
24
  opts = process_options(options)
22
25
  Faraday::Connection.new(opts) do |faraday|
23
- faraday.request :authorization, 'Bearer', opts[:oauth_token] unless opts[:oauth_token].nil?
26
+
27
+ if opts[:basic_auth] && opts[:user] && opts[:password]
28
+ faraday.request :basic_auth, opts[:user], opts[:password]
29
+ elsif opts[:oauth_token]
30
+ faraday.request :authorization, 'Bearer', opts[:oauth_token]
31
+ end
32
+
24
33
  faraday.request :url_encoded
25
34
  faraday.request :multipart
26
35
 
@@ -0,0 +1,55 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'oauth2'
4
+
5
+ module PMP
6
+ class Credential
7
+
8
+ include Configuration
9
+ include Connection
10
+
11
+ CREDENTIAL_PARAMS = [:scope, :token_expires_in, :label]
12
+
13
+ def initialize(options={}, &block)
14
+ apply_configuration(options)
15
+
16
+ yield(self) if block_given?
17
+ end
18
+
19
+ def list
20
+ response = request(:get, credentials_url)
21
+ response.body
22
+ end
23
+
24
+ def create(params={})
25
+ response = request(:post, credentials_url, create_params(params))
26
+ response.body
27
+ end
28
+
29
+ def create_params(params={})
30
+ HashWithIndifferentAccess.new({
31
+ scope: 'read',
32
+ token_expires_in: 60*60*24*30,
33
+ label: "#{user}: #{Time.now}"
34
+ }).merge(params.select{|k,v| CREDENTIAL_PARAMS.include?(k.to_sym)})
35
+ end
36
+
37
+ def request(method, url, body={}) # :nodoc:
38
+
39
+ headers = {
40
+ 'Accept' => "*/*",
41
+ 'Content-Type' => [:put, :post].include?(method) ? "application/x-www-form-urlencoded" : nil
42
+ }
43
+
44
+ conn_opts = options.merge({headers: headers, basic_auth: true})
45
+
46
+ raw = connection(conn_opts).send(method, url, body)
47
+ PMP::Response.new(raw, {method: method, url: url, body: body})
48
+ end
49
+
50
+ def credentials_url
51
+ "#{endpoint}auth/credentials"
52
+ end
53
+
54
+ end
55
+ end
data/lib/pmp/link.rb CHANGED
@@ -25,9 +25,9 @@ module PMP
25
25
 
26
26
  attr_accessor :params
27
27
 
28
- def initialize(parent=nil, link={})
28
+ def initialize(link={}, parent=nil)
29
29
  super()
30
- self.parent = parent || PMP::CollectionDocument.new
30
+ self.parent = parent || link.delete('parent') || PMP::CollectionDocument.new
31
31
  self.params = link.delete('params') || {}
32
32
  # puts "params: #{params.inspect}"
33
33
  parse_attributes(link)
@@ -41,7 +41,7 @@ module PMP
41
41
  end
42
42
 
43
43
  def where(params={})
44
- self.class.new(parent, attributes.merge({'params'=>params}))
44
+ self.class.new(attributes.merge({'params'=>params}), parent)
45
45
  end
46
46
 
47
47
  def as_json
data/lib/pmp/links.rb CHANGED
@@ -14,7 +14,26 @@ module PMP
14
14
 
15
15
  def []=(k, link)
16
16
  super
17
- parent.send("#{to_ruby_safe_name(k)}=", link)
17
+ set_parent(link)
18
+ add_link_name(k)
19
+ end
20
+
21
+ def add_link_name(name)
22
+ name = name.to_sym
23
+ unless parent.respond_to?(name)
24
+ parent.define_singleton_method(name) { self.links[name] }
25
+ parent.define_singleton_method("#{name}=") { |x| puts "setter: #{self.inspect}"; self.links[name] = x }
26
+ end
27
+ end
28
+
29
+ def set_parent(link)
30
+ if link.respond_to?(:parent)
31
+ link.parent = self.parent
32
+ elsif link.is_a?(Hash)
33
+ link.values.each{|l| set_parent(l)}
34
+ elsif link.is_a?(Enumerable)
35
+ link.each{|l| set_parent(l)}
36
+ end
18
37
  end
19
38
 
20
39
  end
data/lib/pmp/parser.rb CHANGED
@@ -63,7 +63,7 @@ module PMP
63
63
 
64
64
  def parse_links(document)
65
65
  Array(document).each do |k,v|
66
- link = parse_link(k,v)
66
+ link = parse_link(k,v)
67
67
  if link
68
68
  self.links[k] = link
69
69
  end
@@ -74,18 +74,18 @@ module PMP
74
74
  if ['query', 'edit', 'navigation'].include?(name.to_s)
75
75
  parse_links_list(info)
76
76
  elsif !info.is_a?(Array)
77
- Link.new(self, info)
77
+ Link.new(info)
78
78
  elsif info.size == 1
79
- Link.new(self, info.first)
79
+ Link.new(info.first)
80
80
  elsif info.size > 0
81
- info.map{|l| Link.new(self, l)}
81
+ info.map{|l| Link.new(l)}
82
82
  end
83
83
  end
84
84
 
85
85
  def parse_links_list(links)
86
86
  links.inject({}) do |results, query|
87
87
  rel = query['rels'].first
88
- results[rel] = Link.new(self, query)
88
+ results[rel] = Link.new(query)
89
89
  results
90
90
  end
91
91
  end
data/lib/pmp/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  module PMP
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
data/pmp.gemspec CHANGED
@@ -27,7 +27,6 @@ Gem::Specification.new do |gem|
27
27
  gem.add_development_dependency('guard-bundler')
28
28
  gem.add_development_dependency('guard-minitest')
29
29
  gem.add_development_dependency('simplecov')
30
- gem.add_development_dependency('simplecov-gem-adapter')
31
30
 
32
31
  gem.add_runtime_dependency('faraday')
33
32
  gem.add_runtime_dependency('faraday_middleware')
data/spec/client_spec.rb CHANGED
@@ -5,7 +5,7 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
5
5
  describe PMP::Client do
6
6
 
7
7
  before(:each) {
8
- @pmp = PMP::Client.new
8
+ @pmp = PMP::Client.new(oauth_token: 'thisisatestvalueonly')
9
9
  }
10
10
 
11
11
  it "make with options and pass along" do
@@ -32,4 +32,42 @@ describe PMP::Client do
32
32
  @root.creator.must_be_instance_of PMP::Link
33
33
  end
34
34
 
35
+ it "gets a credentials object" do
36
+ @pmp.credentials.wont_be_nil
37
+ end
38
+
39
+ it "gets a token object" do
40
+
41
+ access_token = "thisisnotanaccesstokenno"
42
+ response_body = {
43
+ access_token: access_token,
44
+ token_type: "Bearer",
45
+ token_issue_date: DateTime.now,
46
+ token_expires_in: 24*60*60
47
+ }.to_json
48
+
49
+ stub_request(:post, "https://api.pmp.io/auth/access_token").
50
+ with(:body => {"grant_type"=>"client_credentials"},
51
+ :headers => {'Accept'=>'application/json', 'Authorization'=>'Basic dGhpc2lzbm90YS1yZWFsLWNsaWVudC1pZC1zb3Zlcnlzb3JyeTp0aGlzaXNub3RhcmVhbHNlY3JldGVpdGhlcg==', 'Content-Type'=>'application/x-www-form-urlencoded', 'Host'=>'api.pmp.io:443'}).
52
+ to_return(:status => 200, :body => response_body, :headers => {'Content-Type' => 'application/json; charset=utf-8'})
53
+
54
+
55
+
56
+ client_id = "thisisnota-real-client-id-soverysorry"
57
+ client_secret = "thisisnotarealsecreteither"
58
+
59
+ pmp = PMP::Client.new(client_id: client_id, client_secret: client_secret)
60
+
61
+ pmp.token.wont_be_nil
62
+ end
63
+
64
+ it "creates profile uri for type" do
65
+ @pmp.profile_href_for_type('foo').must_equal("https://api.pmp.io/profiles/foo")
66
+ end
67
+
68
+ it "makes a doc of a profile type" do
69
+ user = @pmp.doc_of_type('user')
70
+ user.links['profile'].href.must_equal "https://api.pmp.io/profiles/user"
71
+ end
72
+
35
73
  end
@@ -140,7 +140,7 @@ describe PMP::CollectionDocument do
140
140
 
141
141
  it "should get the list of query links" do
142
142
  queries = @doc.query
143
- queries.must_be_instance_of Hash
143
+ queries.must_be_instance_of HashWithIndifferentAccess
144
144
  end
145
145
 
146
146
  it "should get a query by rels" do
@@ -159,6 +159,13 @@ describe PMP::CollectionDocument do
159
159
  doc.guid.wont_be_nil
160
160
  end
161
161
 
162
+ it "can add a new link" do
163
+ doc = PMP::CollectionDocument.new
164
+ link = PMP::Link.new(href: 'http://pmp.io/test')
165
+ doc.links['test'] = link
166
+ doc.test.must_equal link
167
+ end
168
+
162
169
  it "can save a new record" do
163
170
 
164
171
  # stub getting the root doc
@@ -170,12 +177,13 @@ describe PMP::CollectionDocument do
170
177
  # stub saving the new doc
171
178
  stub_request(:put, "https://publish-sandbox.pmp.io/docs/c144e4df-021b-41e6-9cf3-42ac49bcbd42").
172
179
  with(:headers => {'Accept'=>'application/vnd.pmp.collection.doc+json', 'Content-Type'=>'application/vnd.pmp.collection.doc+json', 'Host'=>'publish-sandbox.pmp.io:443'}).
173
- to_return(:status => 200, :body => '{"url":"https://publish-sandbox.pmp.io/docs/c144e4df-021b-41e6-9cf3-42ac49bcbd42"}')
180
+ to_return(:status => 200, :body => '{"url":"https://api-sandbox.pmp.io/docs/c144e4df-021b-41e6-9cf3-42ac49bcbd42"}')
174
181
 
175
- doc = PMP::CollectionDocument.new
182
+ doc = PMP::CollectionDocument.new(oauth_token: 'thisisatestvalueonly')
176
183
  doc.guid = "c144e4df-021b-41e6-9cf3-42ac49bcbd42"
177
184
  doc.title = "testing"
178
185
  doc.save
186
+ doc.href.must_equal "https://api-sandbox.pmp.io/docs/c144e4df-021b-41e6-9cf3-42ac49bcbd42"
179
187
  end
180
188
 
181
189
  it "can delete a record" do
@@ -190,7 +198,7 @@ describe PMP::CollectionDocument do
190
198
  with(:headers => {'Accept'=>'application/vnd.pmp.collection.doc+json', 'Content-Type'=>'application/vnd.pmp.collection.doc+json', 'Host'=>'publish-sandbox.pmp.io:443'}).
191
199
  to_return(:status => 204, :body => "", :headers => {})
192
200
 
193
- doc = PMP::CollectionDocument.new
201
+ doc = PMP::CollectionDocument.new(oauth_token: 'thisisatestvalueonly')
194
202
  doc.guid = "c144e4df-021b-41e6-9cf3-42ac49bcbd42"
195
203
  doc.delete
196
204
  end
@@ -15,28 +15,36 @@ end
15
15
  describe PMP::Configuration do
16
16
 
17
17
  before {
18
+ @tc = TestConfiguration.new
18
19
  @client_id = ENV['PMP_API_KEY'] || "pmp-test-key"
19
20
  @client_secret = ENV['PMP_API_SECRET'] || "pmp-test-secret"
20
21
  }
21
22
 
22
23
  it "is initialized with defaults" do
23
- tc = TestConfiguration.new
24
- tc.options.wont_be_nil
25
- tc.options.keys.sort.must_equal PMP::Configuration::VALID_OPTIONS_KEYS.sort
26
- tc.options[:endpoint].must_equal PMP::Configuration::DEFAULT_ENDPOINT
24
+ @tc.options.wont_be_nil
25
+ @tc.options.keys.sort.must_equal PMP::Configuration::VALID_OPTIONS_KEYS.sort
26
+ @tc.options[:endpoint].must_equal PMP::Configuration::DEFAULT_ENDPOINT
27
+ end
28
+
29
+ it "can use block to configure" do
30
+ @tc.endpoint.wont_equal 'foo'
31
+ @tc.configure {|c| c.endpoint = 'foo'}
32
+ @tc.endpoint.must_equal 'foo'
33
+ end
34
+
35
+ it "can provide a list of keys" do
36
+ TestConfiguration.keys.must_be_instance_of Array
27
37
  end
28
38
 
29
39
  it "can access configuration methods" do
30
- tc = TestConfiguration.new
31
- tc.endpoint.must_equal PMP::Configuration::DEFAULT_ENDPOINT
40
+ @tc.endpoint.must_equal PMP::Configuration::DEFAULT_ENDPOINT
32
41
  end
33
42
 
34
43
  it "can change config and see reflected in options" do
35
- tc = TestConfiguration.new
36
- tc.endpoint.must_equal PMP::Configuration::DEFAULT_ENDPOINT
37
- tc.endpoint = 'test'
38
- tc.endpoint.must_equal 'test'
39
- tc.options[:endpoint].must_equal 'test'
44
+ @tc.endpoint.must_equal PMP::Configuration::DEFAULT_ENDPOINT
45
+ @tc.endpoint = 'test'
46
+ @tc.endpoint.must_equal 'test'
47
+ @tc.options[:endpoint].must_equal 'test'
40
48
  end
41
49
 
42
50
  it "is initialized with specific values" do
@@ -0,0 +1,70 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
4
+
5
+ require 'pmp/credential'
6
+
7
+ require 'webmock/minitest'
8
+
9
+ describe PMP::Credential do
10
+
11
+ before(:each) {
12
+ @credential = PMP::Credential.new(user: "test", password: "password", endpoint: "https://api-sandbox.pmp.io/")
13
+ }
14
+
15
+ it "has the user and password in the config" do
16
+ @credential.user.must_equal 'test'
17
+ @credential.password.must_equal 'password'
18
+ end
19
+
20
+ it "gets the base path for this subclass of API" do
21
+ credential = PMP::Credential.new
22
+ credential.credentials_url.must_equal "https://api.pmp.io/auth/credentials"
23
+ end
24
+
25
+ it "create a credential" do
26
+ response_body = {
27
+ client_id: "thisisnota-real-client-id-soverysorry",
28
+ client_secret: "thisisnotarealsecreteither",
29
+ token_expires_in: 1209600,
30
+ scope: "write"
31
+ }.to_json
32
+
33
+ stub_request(:post, "https://api-sandbox.pmp.io/auth/credentials").
34
+ with(:body => {"label"=>"what", "scope"=>"read", "token_expires_in"=>"2592000"},
35
+ :headers => {'Accept'=>'*/*', 'Authorization'=>'Basic dGVzdDpwYXNzd29yZA==', 'Content-Type'=>'application/x-www-form-urlencoded', 'Host'=>'api-sandbox.pmp.io:443'}).
36
+ to_return(:status => 200, :body => response_body, :headers => {})
37
+
38
+ new_creds = @credential.create(label: 'what')
39
+ new_creds.client_id.must_equal "thisisnota-real-client-id-soverysorry"
40
+ end
41
+
42
+ it "list credentials" do
43
+
44
+ response_body = {
45
+ clients: [
46
+ {
47
+ client_id: "thisisnota-real-client-id-soverysorry1",
48
+ client_secret: "thisisnotarealsecreteither1",
49
+ label: "label 1",
50
+ token_expires_in: 1209600,
51
+ scope: "write"
52
+ },
53
+ {
54
+ client_id: "thisisnota-real-client-id-soverysorry2",
55
+ client_secret: "thisisnotarealsecreteither2",
56
+ label: "label 2",
57
+ token_expires_in: 1209600,
58
+ scope: "read"
59
+ }
60
+ ]
61
+ }.to_json
62
+
63
+ stub_request(:get, "https://api-sandbox.pmp.io/auth/credentials").
64
+ with(:headers => {'Accept'=>'*/*', 'Authorization'=>'Basic dGVzdDpwYXNzd29yZA==', 'Content-Type'=>'', 'Host'=>'api-sandbox.pmp.io:443'}).
65
+ to_return(:status => 200, :body => response_body, :headers => {})
66
+
67
+ all_creds = @credential.list
68
+ end
69
+
70
+ end
data/spec/link_spec.rb CHANGED
@@ -9,9 +9,9 @@ require 'webmock/minitest'
9
9
  describe PMP::Link do
10
10
 
11
11
  before(:each) {
12
- @parent = Minitest::Mock.new
12
+ @parent = PMP::CollectionDocument.new(oauth_token:'thisisnotarealtoken')
13
13
  @info = {'href' => 'http://api-sandbox.pmp.io/docs/'}
14
- @link = PMP::Link.new(@parent, @info)
14
+ @link = PMP::Link.new(@info, @parent)
15
15
  }
16
16
 
17
17
  it "can create a new link" do
@@ -21,9 +21,9 @@ describe PMP::Link do
21
21
  it "has a parent" do
22
22
  @link = PMP::Link.new
23
23
  @link.parent.wont_be_nil
24
-
25
- @link = PMP::Link.new({}, @info)
26
- @link.parent.must_equal({})
24
+ parent = PMP::CollectionDocument.new
25
+ @link = PMP::Link.new(@info, parent)
26
+ @link.parent.must_equal(parent)
27
27
  end
28
28
 
29
29
  it "can save params to attributes" do
@@ -48,7 +48,7 @@ describe PMP::Link do
48
48
  end
49
49
 
50
50
  it "can get a link for templated href" do
51
- @link = PMP::Link.new(@parent, query_document_info)
51
+ @link = PMP::Link.new(query_document_info, @parent)
52
52
  @link.hints.must_equal query_document_info['hints']
53
53
  @link.url.must_equal "https://api-sandbox.pmp.io/docs"
54
54
  @link.where('limit' => 10).url.must_equal "https://api-sandbox.pmp.io/docs?limit=10"
@@ -63,7 +63,7 @@ describe PMP::Link do
63
63
  with(:headers => {'Accept'=>'application/vnd.pmp.collection.doc+json', 'Content-Type'=>'application/vnd.pmp.collection.doc+json', 'Host'=>'api-sandbox.pmp.io:443'}).
64
64
  to_return(:status => 200, :body => link_doc, :headers => {})
65
65
 
66
- @link = PMP::Link.new(nil, query_document_info)
66
+ @link = PMP::Link.new(query_document_info, @parent)
67
67
  docs = @link.where(limit: 10, tag: 'test')
68
68
  docs.must_be_instance_of PMP::Link
69
69
  guids = docs.items.collect(&:guid).sort
data/spec/links_spec.rb CHANGED
@@ -8,8 +8,9 @@ require 'pmp/links'
8
8
  describe PMP::Links do
9
9
 
10
10
  before(:each) {
11
- @parent = Minitest::Mock.new
11
+ @parent = PMP::CollectionDocument.new
12
12
  @links = PMP::Links.new(@parent)
13
+ @parent.links = @links
13
14
  }
14
15
 
15
16
  it "can create a new links obj" do
@@ -23,9 +24,9 @@ describe PMP::Links do
23
24
 
24
25
  it "can have a link assigned" do
25
26
  link = {}
26
- @parent.expect(:foo=, link, Array(Object))
27
27
  @links['foo'] = link
28
28
  @links['foo'].must_equal link
29
+ @parent.foo.must_equal link
29
30
  end
30
31
 
31
- end
32
+ end
data/spec/parser_spec.rb CHANGED
@@ -41,7 +41,7 @@ describe PMP::Parser do
41
41
  it "parses query links into a hash based on rels" do
42
42
  tc = TestParser.new
43
43
  tc.parse(json_fixture(:collection_root))
44
- tc.query.must_be_instance_of Hash
44
+ tc.query.must_be_instance_of HashWithIndifferentAccess
45
45
  tc.query.keys.sort.must_equal ["urn:pmp:hreftpl:docs", "urn:pmp:hreftpl:profiles", "urn:pmp:hreftpl:schemas", "urn:pmp:query:docs", "urn:pmp:query:groups", "urn:pmp:query:guids", "urn:pmp:query:users"]
46
46
  end
47
47
 
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.1.3
4
+ version: 0.2.0
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-18 00:00:00.000000000 Z
11
+ date: 2013-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,20 +136,6 @@ dependencies:
136
136
  - - '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: simplecov-gem-adapter
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - '>='
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - '>='
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: faraday
155
141
  requirement: !ruby/object:Gem::Requirement
@@ -277,11 +263,13 @@ files:
277
263
  - LICENSE.txt
278
264
  - README.md
279
265
  - Rakefile
266
+ - example/permissions.rb
280
267
  - lib/pmp.rb
281
268
  - lib/pmp/client.rb
282
269
  - lib/pmp/collection_document.rb
283
270
  - lib/pmp/configuration.rb
284
271
  - lib/pmp/connection.rb
272
+ - lib/pmp/credential.rb
285
273
  - lib/pmp/link.rb
286
274
  - lib/pmp/links.rb
287
275
  - lib/pmp/parser.rb
@@ -294,6 +282,7 @@ files:
294
282
  - spec/collection_document_spec.rb
295
283
  - spec/configuration_spec.rb
296
284
  - spec/connection_spec.rb
285
+ - spec/credential_spec.rb
297
286
  - spec/fixtures/collection_basic.json
298
287
  - spec/fixtures/collection_query.json
299
288
  - spec/fixtures/collection_root.json
@@ -333,6 +322,7 @@ test_files:
333
322
  - spec/collection_document_spec.rb
334
323
  - spec/configuration_spec.rb
335
324
  - spec/connection_spec.rb
325
+ - spec/credential_spec.rb
336
326
  - spec/fixtures/collection_basic.json
337
327
  - spec/fixtures/collection_query.json
338
328
  - spec/fixtures/collection_root.json