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 +4 -4
- data/example/permissions_result.txt +17 -17
- data/lib/pmp/client.rb +1 -1
- data/lib/pmp/collection_document.rb +35 -24
- data/lib/pmp/connection.rb +2 -2
- data/lib/pmp/credential.rb +19 -1
- data/lib/pmp/link.rb +8 -8
- data/lib/pmp/links.rb +1 -1
- data/lib/pmp/parser.rb +2 -2
- data/lib/pmp/version.rb +1 -1
- data/spec/client_spec.rb +2 -2
- data/spec/collection_document_spec.rb +30 -18
- data/spec/connection_spec.rb +1 -1
- data/spec/credential_spec.rb +10 -4
- data/spec/fixtures/collection_query.json +636 -1056
- data/spec/fixtures/collection_root.json +284 -160
- data/spec/link_spec.rb +4 -4
- data/spec/parser_spec.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cce90ecfafd14dcd4d8a6806bef81fdd182df3c
|
4
|
+
data.tar.gz: cf0030b9a98badfd1e1c1a773632c1a56575c40a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
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
|
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
|
45
|
-
self.href
|
46
|
-
self.version
|
47
|
-
|
48
|
-
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
|
52
|
-
self.original
|
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:
|
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 =
|
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 != '=')
|
162
|
-
|
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
|
data/lib/pmp/connection.rb
CHANGED
@@ -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.
|
49
|
-
'Content-Type' => "application/vnd.
|
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]
|
data/lib/pmp/credential.rb
CHANGED
@@ -22,7 +22,12 @@ module PMP
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def create(params={})
|
25
|
-
response = request(:post,
|
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:
|
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(
|
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|
|
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.
|
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
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.
|
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.
|
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.
|
82
|
-
@doc.
|
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.
|
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.
|
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:
|
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.
|
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.
|
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:
|
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.
|
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.
|
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.
|
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
|
-
|
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(:
|
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.
|
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.
|
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')
|