pmp 0.3.2 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a47c78760623b6ac3b5a2d94856ab3805a10ca60
4
- data.tar.gz: cb6374e79fabe5c1a54ef29b7157ff10e1999980
3
+ metadata.gz: 5cce90ecfafd14dcd4d8a6806bef81fdd182df3c
4
+ data.tar.gz: cf0030b9a98badfd1e1c1a773632c1a56575c40a
5
5
  SHA512:
6
- metadata.gz: 12c57ef346ba305cc1c0f638d539db6a5bbecd56ffd3bd02cb40714dcd55baa9b2e8279e4d86c0c8119466a90bcc695fc9078ab84c68343bd65b4898dd3c23db
7
- data.tar.gz: c64f50f97ef3f06401f639fb85cc7631f54ecf015dbbb92a8e34f5b358e1f9a17974908a17c603860a23647abce66c6b0f373df9ad3992f62ddd0956e48a3eb4
6
+ metadata.gz: e9f447c64eea0f8b6a371d0175ad0050e9d52c1dbc0633458e99366a122bef942b2500dd2bdc7cca5907661b062ebd523ba6a56ad5e57d2edcf85661585da339
7
+ data.tar.gz: 84b56b31009fe0f3e69134a39d1463649e8676290fbbb6f137eb20cc0e92726d7d1317bb5c37722229e869e1d41fadc494e3e0bb299615e87d568a4a2b06dc5b
@@ -16,7 +16,7 @@ Step 1 complete: organizations: [
16
16
  "profile": [
17
17
  {
18
18
  "href": "https://api-sandbox.pmp.io/profiles/user",
19
- "type": "application/vnd.pmp.collection.doc+json"
19
+ "type": "application/vnd.collection.doc+json"
20
20
  }
21
21
  ]
22
22
  },
@@ -39,7 +39,7 @@ Step 1 complete: organizations: [
39
39
  "profile": [
40
40
  {
41
41
  "href": "https://api-sandbox.pmp.io/profiles/user",
42
- "type": "application/vnd.pmp.collection.doc+json"
42
+ "type": "application/vnd.collection.doc+json"
43
43
  }
44
44
  ]
45
45
  },
@@ -62,7 +62,7 @@ Step 1 complete: organizations: [
62
62
  "profile": [
63
63
  {
64
64
  "href": "https://api-sandbox.pmp.io/profiles/user",
65
- "type": "application/vnd.pmp.collection.doc+json"
65
+ "type": "application/vnd.collection.doc+json"
66
66
  }
67
67
  ]
68
68
  },
@@ -90,7 +90,7 @@ Step 2 complete: permission_groups: [
90
90
  "profile": [
91
91
  {
92
92
  "href": "https://api-sandbox.pmp.io/profiles/group",
93
- "type": "application/vnd.pmp.collection.doc+json"
93
+ "type": "application/vnd.collection.doc+json"
94
94
  }
95
95
  ],
96
96
  "item": [
@@ -116,7 +116,7 @@ Step 2 complete: permission_groups: [
116
116
  "profile": [
117
117
  {
118
118
  "href": "https://api-sandbox.pmp.io/profiles/group",
119
- "type": "application/vnd.pmp.collection.doc+json"
119
+ "type": "application/vnd.collection.doc+json"
120
120
  }
121
121
  ],
122
122
  "item": [
@@ -139,7 +139,7 @@ Step 2 complete: permission_groups: [
139
139
  "profile": [
140
140
  {
141
141
  "href": "https://api-sandbox.pmp.io/profiles/group",
142
- "type": "application/vnd.pmp.collection.doc+json"
142
+ "type": "application/vnd.collection.doc+json"
143
143
  }
144
144
  ],
145
145
  "item": [
@@ -162,7 +162,7 @@ Step 2 complete: permission_groups: [
162
162
  "profile": [
163
163
  {
164
164
  "href": "https://api-sandbox.pmp.io/profiles/group",
165
- "type": "application/vnd.pmp.collection.doc+json"
165
+ "type": "application/vnd.collection.doc+json"
166
166
  }
167
167
  ]
168
168
  },
@@ -185,7 +185,7 @@ Step 3 complete: documents: [
185
185
  "profile": [
186
186
  {
187
187
  "href": "https://api-sandbox.pmp.io/profiles/story",
188
- "type": "application/vnd.pmp.collection.doc+json"
188
+ "type": "application/vnd.collection.doc+json"
189
189
  }
190
190
  ],
191
191
  "permission": [
@@ -210,7 +210,7 @@ Step 3 complete: documents: [
210
210
  "profile": [
211
211
  {
212
212
  "href": "https://api-sandbox.pmp.io/profiles/story",
213
- "type": "application/vnd.pmp.collection.doc+json"
213
+ "type": "application/vnd.collection.doc+json"
214
214
  }
215
215
  ],
216
216
  "permission": [
@@ -240,7 +240,7 @@ Step 3 complete: documents: [
240
240
  "profile": [
241
241
  {
242
242
  "href": "https://api-sandbox.pmp.io/profiles/story",
243
- "type": "application/vnd.pmp.collection.doc+json"
243
+ "type": "application/vnd.collection.doc+json"
244
244
  }
245
245
  ]
246
246
  },
@@ -259,7 +259,7 @@ Step 3 complete: documents: [
259
259
  "profile": [
260
260
  {
261
261
  "href": "https://api-sandbox.pmp.io/profiles/story",
262
- "type": "application/vnd.pmp.collection.doc+json"
262
+ "type": "application/vnd.collection.doc+json"
263
263
  }
264
264
  ],
265
265
  "permission": [
@@ -490,7 +490,7 @@ retrieved: {
490
490
  },
491
491
  "hints": {
492
492
  "formats": [
493
- "application/vnd.pmp.collection.doc+json"
493
+ "application/vnd.collection.doc+json"
494
494
  ],
495
495
  "allow": [
496
496
  "PUT",
@@ -510,7 +510,7 @@ retrieved: {
510
510
  },
511
511
  "hints": {
512
512
  "formats": [
513
- "application/vnd.pmp.collection.doc+json"
513
+ "application/vnd.collection.doc+json"
514
514
  ],
515
515
  "allow": [
516
516
  "PUT",
@@ -742,7 +742,7 @@ retrieved: {
742
742
  },
743
743
  "hints": {
744
744
  "formats": [
745
- "application/vnd.pmp.collection.doc+json"
745
+ "application/vnd.collection.doc+json"
746
746
  ],
747
747
  "allow": [
748
748
  "PUT",
@@ -762,7 +762,7 @@ retrieved: {
762
762
  },
763
763
  "hints": {
764
764
  "formats": [
765
- "application/vnd.pmp.collection.doc+json"
765
+ "application/vnd.collection.doc+json"
766
766
  ],
767
767
  "allow": [
768
768
  "PUT",
@@ -991,7 +991,7 @@ retrieved: {
991
991
  },
992
992
  "hints": {
993
993
  "formats": [
994
- "application/vnd.pmp.collection.doc+json"
994
+ "application/vnd.collection.doc+json"
995
995
  ],
996
996
  "allow": [
997
997
  "PUT",
@@ -1011,7 +1011,7 @@ retrieved: {
1011
1011
  },
1012
1012
  "hints": {
1013
1013
  "formats": [
1014
- "application/vnd.pmp.collection.doc+json"
1014
+ "application/vnd.collection.doc+json"
1015
1015
  ],
1016
1016
  "allow": [
1017
1017
  "PUT",
data/lib/pmp/client.rb CHANGED
@@ -28,7 +28,7 @@ module PMP
28
28
 
29
29
  def doc_of_type(type, opts={})
30
30
  doc = PMP::CollectionDocument.new(options.merge(root:root(opts)).merge(opts))
31
- doc.links['profile'] = Link.new(href: profile_href_for_type(type), type: "application/vnd.pmp.collection.doc+json")
31
+ doc.links['profile'] = Link.new(href: profile_href_for_type(type), type: "application/vnd.collection.doc+json")
32
32
  doc
33
33
  end
34
34
 
@@ -3,7 +3,7 @@ require 'ostruct'
3
3
  module PMP
4
4
 
5
5
  # Using OpenStruct for now - perhaps use ActiveModel? hmm...
6
- class CollectionDocument < OpenStruct
6
+ class CollectionDocument
7
7
 
8
8
  include Configuration
9
9
  include Connection
@@ -27,6 +27,9 @@ module PMP
27
27
  # has this resource actually been loaded from remote url or json document?
28
28
  attr_accessor :loaded
29
29
 
30
+ # private var to save attributes obj, to handle object attributes
31
+ attr_accessor :attributes
32
+
30
33
  # private var to save links obj, to handle link additions
31
34
  attr_accessor :links
32
35
 
@@ -38,18 +41,18 @@ module PMP
38
41
  # assumption is that doc is a parsed json doc confirming to collection.doc+json
39
42
  # TODO: check if this is a json string or hash, for now assume it has been mashified
40
43
  def initialize(options={}, &block)
41
- super()
42
44
  apply_configuration(options)
43
45
 
44
- self.root = current_options.delete(:root)
45
- self.href = current_options.delete(:href)
46
- self.version = current_options.delete(:version) || '1.0'
47
-
48
- self.links = PMP::Links.new(self)
49
-
46
+ self.root = current_options.delete(:root)
47
+ self.href = current_options.delete(:href)
48
+ self.version = current_options.delete(:version) || '1.0'
49
+
50
+ self.attributes = OpenStruct.new
51
+ self.links = PMP::Links.new(self)
52
+
50
53
  # if there is a doc to be had, pull it out
51
- self.response = current_options.delete(:response)
52
- self.original = current_options.delete(:document)
54
+ self.response = current_options.delete(:response)
55
+ self.original = current_options.delete(:document)
53
56
 
54
57
  yield(self) if block_given?
55
58
  end
@@ -59,10 +62,6 @@ module PMP
59
62
  @items ||= []
60
63
  end
61
64
 
62
- def attributes
63
- HashWithIndifferentAccess.new(marshal_dump.delete_if{|k,v| links.keys.include?(k.to_s)})
64
- end
65
-
66
65
  def response=(resp)
67
66
  unless (!resp || loaded?)
68
67
  @response = resp
@@ -89,7 +88,7 @@ module PMP
89
88
  def save
90
89
  set_guid_if_blank
91
90
  url = edit_link('PUT').where(guid: self.guid).url
92
- response = request(:put, url, self)
91
+ self.response = request(:put, url, self)
93
92
  self.href = response.body['url']
94
93
  end
95
94
 
@@ -101,7 +100,7 @@ module PMP
101
100
  end
102
101
 
103
102
  def edit_link(method)
104
- link = root_document.edit['urn:pmp:form:documentsave']
103
+ link = root_document.edit['urn:collectiondoc:form:documentsave']
105
104
  raise "Edit link does not specify saving via #{method}" unless (link && link.hints.allow.include?(method))
106
105
  link
107
106
  end
@@ -123,7 +122,7 @@ module PMP
123
122
  end
124
123
 
125
124
  def setup_oauth_token
126
- if !oauth_token
125
+ if !oauth_token && current_options[:client_id] && current_options[:client_secret]
127
126
  token = PMP::Token.new(current_options).get_token
128
127
  self.oauth_token = token.token
129
128
  self.token_type = token.params['token_type']
@@ -138,7 +137,7 @@ module PMP
138
137
  begin
139
138
  raw = connection(current_options.merge({url: url})).send(method) do |request|
140
139
  if [:post, :put].include?(method.to_sym) && !body.blank?
141
- request.body = body.is_a?(String) ? body : body.to_json
140
+ request.body = PMP::CollectionDocument.to_persist_json(body)
142
141
  end
143
142
  end
144
143
  rescue Faraday::Error::ResourceNotFound=>not_found_ex
@@ -153,17 +152,29 @@ module PMP
153
152
  PMP::Response.new(raw, {method: method, url: url, body: body})
154
153
  end
155
154
 
155
+ # static method to filter out static parts of c.doc+j hash before PUT/POST to PMP server
156
+ # in the future this should be fixed in PMP API to no longer be necessary
157
+ def self.to_persist_json(body)
158
+ return body.to_s if body.is_a?(String) || !body.respond_to?(:as_json)
159
+
160
+ result = body.as_json.select! { |k,v| %w(attributes links).include?(k) }
161
+ result['attributes'].reject! { |k,v| %w(created modified).include?(k) }
162
+ result['links'].reject! { |k,v| %w(creator query edit auth).include?(k) }
163
+
164
+ result.to_json
165
+ end
166
+
167
+ def attributes_map
168
+ HashWithIndifferentAccess.new(attributes.marshal_dump)
169
+ end
170
+
156
171
  def set_guid_if_blank
157
172
  self.guid = SecureRandom.uuid if guid.blank?
158
173
  end
159
174
 
160
175
  def method_missing(method, *args)
161
- if (method.to_s.last != '=') && !loaded?
162
- load
163
- return self.send(method, *args) if self.respond_to?(method)
164
- end
165
-
166
- super
176
+ load if (method.to_s.last != '=')
177
+ respond_to?(method) ? send(method, *args) : attributes.send(method, *args)
167
178
  end
168
179
 
169
180
  end
@@ -45,8 +45,8 @@ module PMP
45
45
  :headers => {
46
46
  # generic http headers
47
47
  'User-Agent' => opts[:user_agent],
48
- 'Accept' => "application/vnd.pmp.collection.doc+json",
49
- 'Content-Type' => "application/vnd.pmp.collection.doc+json"
48
+ 'Accept' => "application/vnd.collection.doc+json",
49
+ 'Content-Type' => "application/vnd.collection.doc+json"
50
50
  },
51
51
  :ssl => {:verify => false},
52
52
  :url => opts[:endpoint]
@@ -22,7 +22,12 @@ module PMP
22
22
  end
23
23
 
24
24
  def create(params={})
25
- response = request(:post, credentials_url, create_params(params))
25
+ response = request(:post, create_credentials_url, create_params(params))
26
+ response.body
27
+ end
28
+
29
+ def destroy(client_id)
30
+ response = request(:delete, remove_credentials_url(client_id))
26
31
  response.body
27
32
  end
28
33
 
@@ -51,5 +56,18 @@ module PMP
51
56
  "#{endpoint}auth/credentials"
52
57
  end
53
58
 
59
+ def create_credentials_url
60
+ root_document.auth['urn:collectiondoc:form:createcredentials'].url
61
+ end
62
+
63
+ def remove_credentials_url(client_id)
64
+ link = root_document.auth['urn:collectiondoc:form:removecredentials']
65
+ link.where(client_id: client_id).url
66
+ end
67
+
68
+ def root_document
69
+ @root ||= PMP::CollectionDocument.new(current_options.merge(href: endpoint))
70
+ end
71
+
54
72
  end
55
73
  end
data/lib/pmp/link.rb CHANGED
@@ -9,7 +9,7 @@ require 'ostruct'
9
9
  # :href_vars, # { "collection": "https://github.com/publicmediaplatform/pmpdocs/wiki/Content-Retrieval" }
10
10
  # :hreflang, # Language of the linked document
11
11
  # :hints, # Hints about interacting with the link, such as HTTP methods, e.g. "hints": { "allow": ["GET", "PUT", "DELETE"] }
12
- # :rels, # [ "urn:pmp:query:users" ]
12
+ # :rels, # [ "urn:collectiondoc:query:users" ]
13
13
  # :method, # http method - get, post, put, etc.
14
14
  # :type, # 'image/png' - mime type of linked resource
15
15
  # :title, # name/title of thing linked in
@@ -34,14 +34,8 @@ module PMP
34
34
  [:href, :href_template, :method].each{|m| self.send("#{m}=", nil) unless respond_to?(m)}
35
35
  end
36
36
 
37
- def attributes
38
- attrs = HashWithIndifferentAccess.new(marshal_dump)
39
- attrs.delete(attrs[:href_template].blank? ? :href_template : :href)
40
- attrs
41
- end
42
-
43
37
  def where(params={})
44
- self.class.new(attributes.merge({'params'=>params}), parent)
38
+ self.class.new(attributes_map.merge({'params'=>params}), parent)
45
39
  end
46
40
 
47
41
  def as_json(options={})
@@ -61,6 +55,12 @@ module PMP
61
55
  @doc ||= PMP::CollectionDocument.new(parent.options.merge(href: url, root: parent.root))
62
56
  end
63
57
 
58
+ def attributes_map
59
+ attrs = HashWithIndifferentAccess.new(marshal_dump)
60
+ attrs.delete(attrs[:href_template].blank? ? :href_template : :href)
61
+ attrs
62
+ end
63
+
64
64
  def method_missing(method, *args)
65
65
  # puts "mm: #{method}"
66
66
  # this is a method the link supports, call the link
data/lib/pmp/links.rb CHANGED
@@ -22,7 +22,7 @@ module PMP
22
22
  name = name.to_sym
23
23
  unless parent.respond_to?(name)
24
24
  parent.define_singleton_method(name) { self.links[name] }
25
- parent.define_singleton_method("#{name}=") { |x| puts "setter: #{self.inspect}"; self.links[name] = x }
25
+ parent.define_singleton_method("#{name}=") { |x| self.links[name] = x }
26
26
  end
27
27
  end
28
28
 
data/lib/pmp/parser.rb CHANGED
@@ -15,7 +15,7 @@ module PMP
15
15
  end
16
16
 
17
17
  def extract_attributes(obj=self)
18
- obj.attributes.inject({}) do |result, pair|
18
+ obj.attributes_map.inject({}) do |result, pair|
19
19
  value = pair.last
20
20
  name = to_json_key_name(pair.first)
21
21
  result[name] = value
@@ -71,7 +71,7 @@ module PMP
71
71
  end
72
72
 
73
73
  def parse_link(name, info)
74
- if ['query', 'edit', 'navigation'].include?(name.to_s)
74
+ if ['query', 'edit', 'navigation', 'auth'].include?(name.to_s)
75
75
  parse_links_list(info)
76
76
  elsif !info.is_a?(Array)
77
77
  Link.new(info)
data/lib/pmp/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  module PMP
4
- VERSION = "0.3.2"
4
+ VERSION = "0.4.0"
5
5
  end
data/spec/client_spec.rb CHANGED
@@ -24,7 +24,7 @@ describe PMP::Client do
24
24
  root_doc = json_file(:collection_root)
25
25
 
26
26
  stub_request(:get, "https://api.pmp.io/").
27
- with(:headers => {'Accept'=>'application/vnd.pmp.collection.doc+json', 'Content-Type'=>'application/vnd.pmp.collection.doc+json', 'Host'=>'api.pmp.io:443'}).
27
+ with(:headers => {'Accept'=>'application/vnd.collection.doc+json', 'Content-Type'=>'application/vnd.collection.doc+json', 'Host'=>'api.pmp.io:443'}).
28
28
  to_return(:status => 200, :body => root_doc, :headers => {})
29
29
 
30
30
  @root = @pmp.root
@@ -35,7 +35,7 @@ describe PMP::Client do
35
35
  root_doc = json_file(:collection_root)
36
36
 
37
37
  stub_request(:get, "https://api.pmp.io/").
38
- with(:headers => {'Accept'=>'application/vnd.pmp.collection.doc+json', 'Content-Type'=>'application/vnd.pmp.collection.doc+json', 'Host'=>'api.pmp.io:443'}).
38
+ with(:headers => {'Accept'=>'application/vnd.collection.doc+json', 'Content-Type'=>'application/vnd.collection.doc+json', 'Host'=>'api.pmp.io:443'}).
39
39
  to_return(:status => 200, :body => root_doc, :headers => {})
40
40
 
41
41
  @pmp.creator.first.must_be_instance_of PMP::Link
@@ -26,7 +26,7 @@ describe PMP::CollectionDocument do
26
26
  it "should default href to endpoint" do
27
27
  @doc.href.must_be_nil
28
28
  @doc.href = "https://api.pmp.io/"
29
- @doc.href.must_equal "https://api.pmp.io/"
29
+ @doc.href.must_equal "https://api.pmp.io/"
30
30
  end
31
31
  end
32
32
 
@@ -78,8 +78,8 @@ describe PMP::CollectionDocument do
78
78
  end
79
79
 
80
80
  it "provides list of attributes (not links)" do
81
- @doc.attributes.keys.must_be :include?, 'title'
82
- @doc.attributes.keys.wont_be :include?, 'self'
81
+ @doc.attributes_map.keys.must_be :include?, 'title'
82
+ @doc.attributes_map.keys.wont_be :include?, 'self'
83
83
  end
84
84
 
85
85
  end
@@ -90,7 +90,7 @@ describe PMP::CollectionDocument do
90
90
  root_doc = json_file(:collection_root)
91
91
 
92
92
  stub_request(:get, "https://api.pmp.io/").
93
- with(:headers => {'Accept'=>'application/vnd.pmp.collection.doc+json', 'Authorization'=>'Bearer thisisatesttoken', 'Content-Type'=>'application/vnd.pmp.collection.doc+json', 'Host'=>'api.pmp.io:443'}).
93
+ with(:headers => {'Accept'=>'application/vnd.collection.doc+json', 'Authorization'=>'Bearer thisisatesttoken', 'Content-Type'=>'application/vnd.collection.doc+json', 'Host'=>'api.pmp.io:443'}).
94
94
  to_return(:status => 200, :body => root_doc, :headers => {})
95
95
 
96
96
  @doc = PMP::CollectionDocument.new(oauth_token: 'thisisatesttoken', href: "https://api.pmp.io/", client_id: "fake", client_secret: "fake")
@@ -139,7 +139,7 @@ describe PMP::CollectionDocument do
139
139
 
140
140
  it "should provide a list of links" do
141
141
  @doc.load
142
- @doc.links.keys.sort.must_equal ["creator", "edit", "navigation", "query"]
142
+ @doc.links.keys.sort.must_equal ["auth", "bookmark", "creator", "edit", "item", "navigation", "query"]
143
143
  @doc.links['creator'].first.must_be_instance_of PMP::Link
144
144
  end
145
145
 
@@ -151,7 +151,7 @@ describe PMP::CollectionDocument do
151
151
  root_doc = json_file(:collection_root)
152
152
 
153
153
  stub_request(:get, "https://api.pmp.io/").
154
- with(:headers => {'Accept'=>'application/vnd.pmp.collection.doc+json', 'Authorization'=>'Bearer thisisatesttoken', 'Content-Type'=>'application/vnd.pmp.collection.doc+json', 'Host'=>'api.pmp.io:443'}).
154
+ with(:headers => {'Accept'=>'application/vnd.collection.doc+json', 'Authorization'=>'Bearer thisisatesttoken', 'Content-Type'=>'application/vnd.collection.doc+json', 'Host'=>'api.pmp.io:443'}).
155
155
  to_return(:status => 200, :body => root_doc, :headers => {})
156
156
 
157
157
  @doc = PMP::CollectionDocument.new(oauth_token: 'thisisatesttoken', href: "https://api.pmp.io/")
@@ -164,16 +164,16 @@ describe PMP::CollectionDocument do
164
164
 
165
165
  it "should get a query by rels" do
166
166
  queries = @doc.query
167
- queries["urn:pmp:query:docs"].must_be_instance_of PMP::Link
167
+ queries["urn:collectiondoc:query:docs"].must_be_instance_of PMP::Link
168
168
  end
169
169
 
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'}).
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"})
173
+ with(:headers => {'Accept'=>'application/vnd.collection.doc+json', 'Authorization'=>'Bearer thisisatesttoken', 'Content-Type'=>'application/vnd.collection.doc+json', 'Host'=>'api-sandbox.pmp.io:443'}).
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.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
- @doc.query["urn:pmp:query:docs"].items.must_equal []
176
+ @doc.query["urn:collectiondoc:query:docs"].items.must_equal []
177
177
  end
178
178
 
179
179
  end
@@ -199,12 +199,12 @@ describe PMP::CollectionDocument do
199
199
  # stub getting the root doc
200
200
  root_doc = json_file(:collection_root)
201
201
  stub_request(:get, "https://api.pmp.io/").
202
- with(:headers => {'Accept'=>'application/vnd.pmp.collection.doc+json', 'Content-Type'=>'application/vnd.pmp.collection.doc+json', 'Host'=>'api.pmp.io:443'}).
202
+ with(:headers => {'Accept'=>'application/vnd.collection.doc+json', 'Content-Type'=>'application/vnd.collection.doc+json', 'Host'=>'api.pmp.io:443'}).
203
203
  to_return(:status => 200, :body => root_doc, :headers => {})
204
204
 
205
205
  # stub saving the new doc
206
206
  stub_request(:put, "https://publish-sandbox.pmp.io/docs/c144e4df-021b-41e6-9cf3-42ac49bcbd42").
207
- with(:headers => {'Accept'=>'application/vnd.pmp.collection.doc+json', 'Content-Type'=>'application/vnd.pmp.collection.doc+json', 'Host'=>'publish-sandbox.pmp.io:443'}).
207
+ with(:headers => {'Accept'=>'application/vnd.collection.doc+json', 'Content-Type'=>'application/vnd.collection.doc+json', 'Host'=>'publish-sandbox.pmp.io:443'}).
208
208
  to_return(:status => 404, :body => '{"error":"FAIL"}')
209
209
 
210
210
  doc = PMP::CollectionDocument.new(oauth_token: 'thisisatestvalueonly')
@@ -217,21 +217,33 @@ describe PMP::CollectionDocument do
217
217
 
218
218
  # stub getting the root doc
219
219
  root_doc = json_file(:collection_root)
220
+
220
221
  stub_request(:get, "https://api.pmp.io/").
221
- with(:headers => {'Accept'=>'application/vnd.pmp.collection.doc+json', 'Content-Type'=>'application/vnd.pmp.collection.doc+json', 'Host'=>'api.pmp.io:443'}).
222
+ with(:headers => {'Accept'=>'application/vnd.collection.doc+json', 'Content-Type'=>'application/vnd.collection.doc+json', 'Host'=>'api.pmp.io:443'}).
222
223
  to_return(:status => 200, :body => root_doc, :headers => {})
223
224
 
224
- # stub saving the new doc
225
+ doc = PMP::CollectionDocument.new(oauth_token: 'thisisatestvalueonly')
226
+
227
+
225
228
  stub_request(:put, "https://publish-sandbox.pmp.io/docs/c144e4df-021b-41e6-9cf3-42ac49bcbd42").
226
- with(:headers => {'Accept'=>'application/vnd.pmp.collection.doc+json', 'Content-Type'=>'application/vnd.pmp.collection.doc+json', 'Host'=>'publish-sandbox.pmp.io:443'}).
229
+ with(:body => "{\"links\":{},\"attributes\":{\"guid\":\"c144e4df-021b-41e6-9cf3-42ac49bcbd42\",\"title\":\"testing\"}}",
230
+ :headers => {'Accept'=>'application/vnd.collection.doc+json', 'Authorization'=>'Bearer thisisatestvalueonly', 'Content-Type'=>'application/vnd.collection.doc+json', 'Host'=>'publish-sandbox.pmp.io:443'}).
227
231
  to_return(:status => 200, :body => '{"url":"https://api-sandbox.pmp.io/docs/c144e4df-021b-41e6-9cf3-42ac49bcbd42"}')
228
232
 
229
- doc = PMP::CollectionDocument.new(oauth_token: 'thisisatestvalueonly')
230
233
  doc.guid = "c144e4df-021b-41e6-9cf3-42ac49bcbd42"
231
234
  doc.title = "testing"
235
+ doc.wont_be :loaded
232
236
  doc.save
237
+
238
+ doc.must_be :loaded
233
239
  doc.href.must_equal "https://api-sandbox.pmp.io/docs/c144e4df-021b-41e6-9cf3-42ac49bcbd42"
234
240
 
241
+
242
+ stub_request(:put, "https://publish-sandbox.pmp.io/docs/c144e4df-021b-41e6-9cf3-42ac49bcbd42").
243
+ with(:body => "{\"links\":{},\"attributes\":{\"guid\":\"c144e4df-021b-41e6-9cf3-42ac49bcbd42\",\"title\":\"testing an update\"}}",
244
+ :headers => {'Accept'=>'application/vnd.collection.doc+json', 'Authorization'=>'Bearer thisisatestvalueonly', 'Content-Type'=>'application/vnd.collection.doc+json', 'Host'=>'publish-sandbox.pmp.io:443'}).
245
+ to_return(:status => 200, :body => '{"url":"https://api-sandbox.pmp.io/docs/c144e4df-021b-41e6-9cf3-42ac49bcbd42"}')
246
+
235
247
  doc.title.must_equal "testing"
236
248
  doc.title = "testing an update"
237
249
  doc.save
@@ -243,11 +255,11 @@ describe PMP::CollectionDocument do
243
255
  # stub getting the root doc
244
256
  root_doc = json_file(:collection_root)
245
257
  stub_request(:get, "https://api.pmp.io/").
246
- with(:headers => {'Accept'=>'application/vnd.pmp.collection.doc+json', 'Content-Type'=>'application/vnd.pmp.collection.doc+json', 'Host'=>'api.pmp.io:443'}).
258
+ with(:headers => {'Accept'=>'application/vnd.collection.doc+json', 'Content-Type'=>'application/vnd.collection.doc+json', 'Host'=>'api.pmp.io:443'}).
247
259
  to_return(:status => 200, :body => root_doc, :headers => {})
248
260
 
249
261
  stub_request(:delete, "https://publish-sandbox.pmp.io/docs/c144e4df-021b-41e6-9cf3-42ac49bcbd42").
250
- with(:headers => {'Accept'=>'application/vnd.pmp.collection.doc+json', 'Content-Type'=>'application/vnd.pmp.collection.doc+json', 'Host'=>'publish-sandbox.pmp.io:443'}).
262
+ with(:headers => {'Accept'=>'application/vnd.collection.doc+json', 'Content-Type'=>'application/vnd.collection.doc+json', 'Host'=>'publish-sandbox.pmp.io:443'}).
251
263
  to_return(:status => 204, :body => "", :headers => {})
252
264
 
253
265
  doc = PMP::CollectionDocument.new(oauth_token: 'thisisatestvalueonly')