pmp 0.2.3 → 0.2.4

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: ccd9974d908a4e63fce21f4e629dba99d8ffb964
4
- data.tar.gz: da91fd91c23b1c07091ded1f7f60d504c552e2a7
3
+ metadata.gz: e20dca7592de10022ded2bda390f2e172bc8f026
4
+ data.tar.gz: 704f4900aa8ebcb8af896682a2f3ed743f669fc0
5
5
  SHA512:
6
- metadata.gz: e57d28e41caf69a6d76732d59d8c0f05e5e0c0c1f61551fa5df046b4c945301e988dab00724ebc868b9ff144374dc01f3d86eb1919695103ca6216bfa1b96e54
7
- data.tar.gz: 39a229cd3c8f8f7d2fca39e3b9f7a3fc880a8d286c307af0b7b403ed389544c310e9063cd6ab898ee151ee4b76715204b95254bb11a6cdcdfc35667e1bd98bea
6
+ metadata.gz: c01ba49f3108680b8353355de2a5e4c4a646816e82a699bb00f0895e7513e074582e5ad3615f96545fb91923a7041e75c5c457cadffd5c3ee18d63d1ddf452df
7
+ data.tar.gz: ebb7db14d83f8b167c12df7552b5c662d635e0fe95e43e0e4321a4b3aaabec9c5012a87aa8f488b37172fbc6acb2bf0b4d01c019251058e62805e8fa13ddd8da
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/PRX/pmp.png)](https://travis-ci.org/PRX/pmp)
4
4
  [![Coverage Status](https://coveralls.io/repos/PRX/pmp/badge.png)](https://coveralls.io/r/PRX/pmp)
5
+ [![Code Climate](https://codeclimate.com/github/PRX/pmp.png)](https://codeclimate.com/github/PRX/pmp)
5
6
  [![Dependency Status](https://gemnasium.com/PRX/pmp.png)](https://gemnasium.com/PRX/pmp)
6
7
  [![Gem Version](https://badge.fury.io/rb/pmp.png)](http://badge.fury.io/rb/pmp)
7
8
 
@@ -25,24 +25,26 @@ module PMP
25
25
  opts = process_options(options)
26
26
  Faraday::Connection.new(opts) do |faraday|
27
27
 
28
- if opts[:basic_auth] && opts[:user] && opts[:password]
29
- faraday.request :basic_auth, opts[:user], opts[:password]
30
- elsif opts[:oauth_token]
31
- faraday.request :authorization, opts[:token_type], opts[:oauth_token]
32
- end
28
+ add_request_auth(opts, faraday)
33
29
 
34
- faraday.request :multipart
35
- faraday.request :url_encoded
30
+ [:multipart, :url_encoded].each{|mw| faraday.request(mw) }
31
+
32
+ [:mashify, :json, :raise_error].each{|mw| faraday.response(mw) }
36
33
 
37
- faraday.response :mashify
38
- faraday.response :json
39
- faraday.response :raise_error
40
34
  faraday.response :logger if opts[:debug]
41
35
 
42
36
  faraday.adapter opts[:adapter]
43
37
  end
44
38
  end
45
39
 
40
+ def add_request_auth(opts, faraday)
41
+ if opts[:basic_auth] && opts[:user] && opts[:password]
42
+ faraday.request :basic_auth, opts[:user], opts[:password]
43
+ elsif opts[:oauth_token]
44
+ faraday.request :authorization, opts[:token_type], opts[:oauth_token]
45
+ end
46
+ end
47
+
46
48
  def process_options(opts={})
47
49
  headers = opts.delete(:headers) || {}
48
50
  options = {
data/lib/pmp/link.rb CHANGED
@@ -69,8 +69,6 @@ module PMP
69
69
  method_last = method.to_s.last
70
70
  if method_last == '='
71
71
  super
72
- elsif self.respond_to?(method)
73
- self.send(method, *args)
74
72
  else
75
73
  # puts "mm retrieve and send: #{method}"
76
74
  self.retrieve.send(method, *args)
data/lib/pmp/token.rb CHANGED
@@ -36,13 +36,13 @@ module PMP
36
36
  def connection_options(opts={})
37
37
  headers = opts.delete(:headers) || {}
38
38
  options = {
39
- :headers => {
39
+ headers: {
40
40
  'User-Agent' => opts[:user_agent],
41
41
  'Accept' => 'application/json',
42
42
  'Content-Type' => 'application/x-www-form-urlencoded'
43
43
  },
44
- :ssl => {:verify => false},
45
- :url => opts[:endpoint]
44
+ ssl: {:verify => false},
45
+ url: opts[:endpoint]
46
46
  }.merge(opts)
47
47
  options[:headers] = options[:headers].merge(headers)
48
48
 
data/lib/pmp/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
3
  module PMP
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.4"
5
5
  end
@@ -194,7 +194,26 @@ describe PMP::CollectionDocument do
194
194
  doc.test.must_equal link
195
195
  end
196
196
 
197
- it "can save a new record" do
197
+ it "can save a record" do
198
+
199
+ # stub getting the root doc
200
+ root_doc = json_file(:collection_root)
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'}).
203
+ to_return(:status => 200, :body => root_doc, :headers => {})
204
+
205
+ # stub saving the new doc
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'}).
208
+ to_return(:status => 404, :body => '{"error":"FAIL"}')
209
+
210
+ doc = PMP::CollectionDocument.new(oauth_token: 'thisisatestvalueonly')
211
+ doc.guid = "c144e4df-021b-41e6-9cf3-42ac49bcbd42"
212
+ doc.title = "testing"
213
+ proc{ doc.save }.must_raise Faraday::Error::ResourceNotFound
214
+ end
215
+
216
+ it "should handle 404 results on a save" do
198
217
 
199
218
  # stub getting the root doc
200
219
  root_doc = json_file(:collection_root)
@@ -212,6 +231,11 @@ describe PMP::CollectionDocument do
212
231
  doc.title = "testing"
213
232
  doc.save
214
233
  doc.href.must_equal "https://api-sandbox.pmp.io/docs/c144e4df-021b-41e6-9cf3-42ac49bcbd42"
234
+
235
+ doc.title.must_equal "testing"
236
+ doc.title = "testing an update"
237
+ doc.save
238
+ doc.title.must_equal "testing an update"
215
239
  end
216
240
 
217
241
  it "can delete a record" do
@@ -0,0 +1,36 @@
1
+ {
2
+ "version": "1.0",
3
+ "attributes": {
4
+ "guid": "f84e9018-5c21-4b32-93f8-d519308620f0",
5
+ "title": "Peers Find Less Pressure Borrowing From Each Other",
6
+ "published": "2013-05-10T15:17:00.598Z",
7
+ "valid": {
8
+ "from": "2013-05-10T15:17:00.598Z",
9
+ "to": "2213-05-10T15:17:00.598Z"
10
+ },
11
+ "byline": "by SOME PERSON",
12
+ "hreflang": "en",
13
+ "description": "",
14
+ "contentencoded": "...",
15
+ "contenttemplated": "..."
16
+ },
17
+ "items": [],
18
+ "links": {
19
+ "profile": [
20
+ {
21
+ "href": "http://api-sandbox.pmp.io/profiles/story"
22
+ }
23
+ ],
24
+ "self": {
25
+ "href": "http://api-sandbox.pmp.io/docs/f84e9018-5c21-4b32-93f8-d519308620f0"
26
+ },
27
+ "collection": [
28
+ {
29
+ "href": "http://api-sandbox.pmp.io/docs/"
30
+ }
31
+ ],
32
+ "queries": [],
33
+ "edit-form": []
34
+ },
35
+ "error": {}
36
+ }
data/spec/parser_spec.rb CHANGED
@@ -28,6 +28,12 @@ describe PMP::Parser do
28
28
  tc.parse(nil)
29
29
  end
30
30
 
31
+ it "will parse links without array comtainer" do
32
+ tc = TestParser.new
33
+ tc.parse(json_fixture(:collection_links))
34
+ tc.links['self'].href.must_equal "http://api-sandbox.pmp.io/docs/f84e9018-5c21-4b32-93f8-d519308620f0"
35
+ end
36
+
31
37
  it "will un-parse to hash for json serialization" do
32
38
  tc = TestParser.new
33
39
  tc.parse(json_fixture(:collection_basic))
@@ -45,5 +51,13 @@ describe PMP::Parser do
45
51
  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
52
  end
47
53
 
54
+ it "will unparse links" do
55
+ tc = TestParser.new
56
+ tc.parse(json_fixture(:collection_root))
57
+ tc.links['test1'] = PMP::Link.new(href: 'https://api-sandbox.pmp.io/test1')
58
+ tc.links['test2'] = [PMP::Link.new(href: 'https://api-sandbox.pmp.io/test2a'), PMP::Link.new(href: 'https://api-sandbox.pmp.io/test2b')]
59
+ hash = tc.as_json
60
+ hash['links'].keys.sort.must_equal ["creator", "edit", "navigation", "query", "test1", "test2"]
61
+ end
48
62
 
49
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kuklewicz
@@ -299,6 +299,7 @@ files:
299
299
  - spec/connection_spec.rb
300
300
  - spec/credential_spec.rb
301
301
  - spec/fixtures/collection_basic.json
302
+ - spec/fixtures/collection_links.json
302
303
  - spec/fixtures/collection_query.json
303
304
  - spec/fixtures/collection_root.json
304
305
  - spec/link_spec.rb
@@ -340,6 +341,7 @@ test_files:
340
341
  - spec/connection_spec.rb
341
342
  - spec/credential_spec.rb
342
343
  - spec/fixtures/collection_basic.json
344
+ - spec/fixtures/collection_links.json
343
345
  - spec/fixtures/collection_query.json
344
346
  - spec/fixtures/collection_root.json
345
347
  - spec/link_spec.rb