maremma 2.5.4 → 3.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.
data/spec/maremma_spec.rb CHANGED
@@ -11,27 +11,30 @@ describe Maremma do
11
11
  it "get json" do
12
12
  stub = stub_request(:get, url).to_return(:body => data.to_json, :status => 200, :headers => { "Content-Type" => "application/json" })
13
13
  response = subject.get(url)
14
- expect(response).to eq("data" => data, "headers"=>{"Content-Type"=>"application/json"})
14
+ expect(response.body).to eq("data" => data)
15
+ expect(response.headers).to eq("Content-Type"=>"application/json")
15
16
  expect(stub).to have_been_requested
16
17
  end
17
18
 
18
19
  it "get xml" do
19
20
  stub = stub_request(:get, url).to_return(:body => data.to_xml, :status => 200, :headers => { "Content-Type" => "application/xml" })
20
21
  response = subject.get(url, accept: 'xml')
21
- expect(response).to eq("data"=>data, "headers"=>{"Content-Type"=>"application/xml"})
22
+ expect(response.body).to eq("data"=>data)
23
+ expect(response.headers).to eq("Content-Type"=>"application/xml")
22
24
  expect(stub).to have_been_requested
23
25
  end
24
26
 
25
27
  it "get html" do
26
28
  stub = stub_request(:get, url).to_return(:body => data.to_s, :status => 200, :headers => { "Content-Type" => "text/html" })
27
29
  response = subject.get(url, accept: 'html')
28
- expect(response).to eq("data" => data.to_s, "headers"=>{"Content-Type"=>"text/html"})
30
+ expect(response.body).to eq("data" => data.to_s)
31
+ expect(response.headers).to eq("Content-Type"=>"text/html")
29
32
  expect(stub).to have_been_requested
30
33
  end
31
34
 
32
35
  it "post xml" do
33
36
  stub = stub_request(:post, url).with(:body => post_data.to_xml).to_return(:body => data.to_xml, :status => 200, :headers => { "Content-Type" => "text/html" })
34
- subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(Hash.from_xml(response.to_s)["hash"]).to eq(data) }
37
+ subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(Hash.from_xml(response.body.to_s)["hash"]).to eq(data) }
35
38
  expect(stub).to have_been_requested
36
39
  end
37
40
 
@@ -47,10 +50,19 @@ describe Maremma do
47
50
  url = "https://search.datacite.org/api?" + URI.encode_www_form(params)
48
51
  expect(url).to eq("https://search.datacite.org/api?q=*%3A*&fl=doi%2Ctitle%2Cdescription%2Cpublisher%2CpublicationYear%2CresourceType%2CresourceTypeGeneral%2CrightsURI%2Cdatacentre_symbol%2Cxml%2Cminted%2Cupdated&fq=has_metadata%3Atrue&fq=is_active%3Atrue&facet=true&facet.field=resourceType_facet&facet.field=publicationYear&facet.field=datacentre_facet&facet.limit=10&f.resourceType_facet.facet.limit=15&wt=json")
49
52
  response = subject.get(url)
50
- facet_fields = response.fetch("data", {}).fetch("facet_counts", {}).fetch("facet_fields", {})
51
- expect(facet_fields["datacentre_facet"].each_slice(2).first).to eq(["CDL.DPLANET - Data-Planet", 866179])
52
- expect(facet_fields["resourceType_facet"].each_slice(2).first).to eq(["Dataset", 2868231])
53
- expect(facet_fields["publicationYear"].each_slice(2).first).to eq(["2015", 2048329])
53
+ facet_fields = response.body.fetch("data", {}).fetch("facet_counts", {}).fetch("facet_fields", {})
54
+ expect(facet_fields["datacentre_facet"].each_slice(2).first).to eq(["CDL.DPLANET - Data-Planet", 866368])
55
+ expect(facet_fields["resourceType_facet"].each_slice(2).first).to eq(["Dataset", 2875784])
56
+ expect(facet_fields["publicationYear"].each_slice(2).first).to eq(["2015", 2050685])
57
+ end
58
+
59
+ it "get json with meta hash" do
60
+ data = { "data" => { "name" => "Jack" }, "meta" => { "count" => 12 }}
61
+ stub = stub_request(:get, url).to_return(:body => data.to_json, :status => 200, :headers => { "Content-Type" => "application/json" })
62
+ response = subject.get(url)
63
+ expect(response.body).to eq("data"=>{"name"=>"Jack"}, "meta"=>{"count"=>12})
64
+ expect(response.headers).to eq("Content-Type"=>"application/json")
65
+ expect(stub).to have_been_requested
54
66
  end
55
67
  end
56
68
 
@@ -58,27 +70,30 @@ describe Maremma do
58
70
  it "get json" do
59
71
  stub = stub_request(:get, url).to_return(:body => nil, :status => 200, :headers => { "Content-Type" => "application/json" })
60
72
  response = subject.get(url)
61
- expect(response).to eq("data"=>nil, "headers"=>{"Content-Type"=>"application/json"})
73
+ expect(response.body).to eq("data"=>nil)
74
+ expect(response.headers).to eq("Content-Type"=>"application/json")
62
75
  expect(stub).to have_been_requested
63
76
  end
64
77
 
65
78
  it "get xml" do
66
79
  stub = stub_request(:get, url).to_return(:body => nil, :status => 200, :headers => { "Content-Type" => "application/xml" })
67
80
  response = subject.get(url, accept: 'xml')
68
- expect(response).to eq("data"=>nil, "headers"=>{"Content-Type"=>"application/xml"})
81
+ expect(response.body).to eq("data"=>nil)
82
+ expect(response.headers).to eq("Content-Type"=>"application/xml")
69
83
  expect(stub).to have_been_requested
70
84
  end
71
85
 
72
86
  it "get html" do
73
87
  stub = stub_request(:get, url).to_return(:body => nil, :status => 200, :headers => { "Content-Type" => "text/html" })
74
88
  response = subject.get(url, accept: 'html')
75
- expect(response).to eq("data" => nil, "headers"=>{"Content-Type"=>"text/html"})
89
+ expect(response.body).to eq("data" => nil)
90
+ expect(response.headers).to eq("Content-Type"=>"text/html")
76
91
  expect(stub).to have_been_requested
77
92
  end
78
93
 
79
94
  it "post xml" do
80
95
  stub = stub_request(:post, url).with(:body => post_data.to_xml).to_return(:body => nil, :status => 200, :headers => { "Content-Type" => "application/xml" })
81
- subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response).to eq("data" => nil) }
96
+ subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response.body).to eq("data" => nil) }
82
97
  expect(stub).to have_been_requested
83
98
  end
84
99
  end
@@ -88,19 +103,22 @@ describe Maremma do
88
103
 
89
104
  it "get json" do
90
105
  stub = stub_request(:get, url).to_return(:body => error.to_json, :status => [404], :headers => { "Content-Type" => "application/json" })
91
- expect(subject.get(url)).to eq(error)
106
+ response = subject.get(url, accept: 'json')
107
+ expect(response.body).to eq(error)
92
108
  expect(stub).to have_been_requested
93
109
  end
94
110
 
95
111
  it "get xml" do
96
112
  stub = stub_request(:get, url).to_return(:body => error.to_xml, :status => [404], :headers => { "Content-Type" => "application/xml" })
97
- expect(subject.get(url, accept: 'xml')).to eq(error)
113
+ response = subject.get(url, accept: 'xml')
114
+ expect(response.body).to eq(error)
98
115
  expect(stub).to have_been_requested
99
116
  end
100
117
 
101
118
  it "get html" do
102
119
  stub = stub_request(:get, url).to_return(:body => error.to_s, :status => [404], :headers => { "Content-Type" => "text/html" })
103
- expect(subject.get(url, accept: 'html')).to eq(error)
120
+ response = subject.get(url, accept: 'html')
121
+ expect(response.body).to eq(error)
104
122
  expect(stub).to have_been_requested
105
123
  end
106
124
 
@@ -115,27 +133,27 @@ describe Maremma do
115
133
  it "get json" do
116
134
  stub = stub_request(:get, url).to_return(:status => [408])
117
135
  response = subject.get(url)
118
- expect(response).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
136
+ expect(response.body).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
119
137
  expect(stub).to have_been_requested
120
138
  end
121
139
 
122
140
  it "get xml" do
123
141
  stub = stub_request(:get, url).to_return(:status => [408])
124
142
  response = subject.get(url, accept: 'xml')
125
- expect(response).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
143
+ expect(response.body).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
126
144
  expect(stub).to have_been_requested
127
145
  end
128
146
 
129
147
  it "get html" do
130
148
  stub = stub_request(:get, url).to_return(:status => [408])
131
149
  response = subject.get(url, accept: 'html')
132
- expect(response).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
150
+ expect(response.body).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
133
151
  expect(stub).to have_been_requested
134
152
  end
135
153
 
136
154
  it "post xml" do
137
155
  stub = stub_request(:post, url).with(:body => post_data.to_xml).to_return(:status => [408])
138
- subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response).to be_nil }
156
+ subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response.body).to be_nil }
139
157
  expect(stub).to have_been_requested
140
158
  end
141
159
  end
@@ -144,7 +162,7 @@ describe Maremma do
144
162
  it "head" do
145
163
  stub = stub_request(:head, url).to_return(:status => 200, :headers => { "Content-Type" => "application/json" })
146
164
  response = subject.head(url)
147
- expect(response).to eq("headers"=>{"Content-Type"=>"application/json"})
165
+ expect(response.headers).to eq("Content-Type"=>"application/json")
148
166
  expect(stub).to have_been_requested
149
167
  end
150
168
  end
@@ -153,7 +171,8 @@ describe Maremma do
153
171
  it "delete" do
154
172
  stub = stub_request(:delete, url).to_return(:status => 204, :headers => { "Content-Type" => "text/html" })
155
173
  response = subject.delete(url)
156
- expect(response).to eq("data"=>nil, "headers"=>{"Content-Type"=>"text/html"})
174
+ expect(response.body).to eq("data"=>nil)
175
+ expect(response.headers).to eq("Content-Type"=>"text/html")
157
176
  expect(stub).to have_been_requested
158
177
  end
159
178
  end
@@ -162,27 +181,27 @@ describe Maremma do
162
181
  it "get json" do
163
182
  stub = stub_request(:get, url).to_raise(Faraday::ConnectionFailed.new("Connection refused - connect(2)"))
164
183
  response = subject.get(url)
165
- expect(response).to eq("errors"=>[{"status"=>"403", "title"=>"Connection refused - connect(2)"}])
184
+ expect(response.body).to eq("errors"=>[{"status"=>"403", "title"=>"Connection refused - connect(2)"}])
166
185
  expect(stub).to have_been_requested
167
186
  end
168
187
 
169
188
  it "get xml" do
170
189
  stub = stub_request(:get, url).to_raise(Faraday::ConnectionFailed.new("Connection refused - connect(2)"))
171
190
  response = subject.get(url, accept: 'xml')
172
- expect(response).to eq("errors"=>[{"status"=>"403", "title"=>"Connection refused - connect(2)"}])
191
+ expect(response.body).to eq("errors"=>[{"status"=>"403", "title"=>"Connection refused - connect(2)"}])
173
192
  expect(stub).to have_been_requested
174
193
  end
175
194
 
176
195
  it "get html" do
177
196
  stub = stub_request(:get, url).to_raise(Faraday::ConnectionFailed.new("Connection refused - connect(2)"))
178
197
  response = subject.get(url, accept: 'html')
179
- expect(response).to eq("errors"=>[{"status"=>"403", "title"=>"Connection refused - connect(2)"}])
198
+ expect(response.body).to eq("errors"=>[{"status"=>"403", "title"=>"Connection refused - connect(2)"}])
180
199
  expect(stub).to have_been_requested
181
200
  end
182
201
 
183
202
  it "post xml" do
184
203
  stub = stub_request(:post, url).with(:body => post_data.to_xml).to_raise(Faraday::ConnectionFailed.new("Connection refused - connect(2)"))
185
- subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response).to be_nil }
204
+ subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response.body).to be_nil }
186
205
  expect(stub).to have_been_requested
187
206
  end
188
207
  end
@@ -191,27 +210,27 @@ describe Maremma do
191
210
  it "get json" do
192
211
  stub = stub_request(:get, url).to_timeout
193
212
  response = subject.get(url)
194
- expect(response).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
213
+ expect(response.body).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
195
214
  expect(stub).to have_been_requested
196
215
  end
197
216
 
198
217
  it "get xml" do
199
218
  stub = stub_request(:get, url).to_timeout
200
219
  response = subject.get(url, accept: 'xml')
201
- expect(response).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
220
+ expect(response.body).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
202
221
  expect(stub).to have_been_requested
203
222
  end
204
223
 
205
224
  it "get html" do
206
225
  stub = stub_request(:get, url).to_timeout
207
226
  response = subject.get(url, accept: 'html')
208
- expect(response).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
227
+ expect(response.body).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
209
228
  expect(stub).to have_been_requested
210
229
  end
211
230
 
212
231
  it "post xml" do
213
232
  stub = stub_request(:post, url).with(:body => post_data.to_xml).to_timeout
214
- subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response).to be_nil }
233
+ subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response.body).to be_nil }
215
234
  expect(stub).to have_been_requested
216
235
  end
217
236
  end
@@ -220,28 +239,28 @@ describe Maremma do
220
239
  it "get json" do
221
240
  stub = stub_request(:get, url).to_return(status: 200, headers: { 'X-Rate-Limit-Remaining' => 3 })
222
241
  response = subject.get(url)
223
- expect(response).to eq("errors"=>[{"status"=>429, "title"=>"Too many requests"}])
242
+ expect(response.body).to eq("errors"=>[{"status"=>429, "title"=>"Too many requests"}])
224
243
  expect(stub).to have_been_requested
225
244
  end
226
245
 
227
246
  it "get xml" do
228
247
  stub = stub_request(:get, url).to_return(status: 200, headers: { 'X-Rate-Limit-Remaining' => 3 })
229
248
  response = subject.get(url, accept: 'xml')
230
- expect(response).to eq("errors"=>[{"status"=>429, "title"=>"Too many requests"}])
249
+ expect(response.body).to eq("errors"=>[{"status"=>429, "title"=>"Too many requests"}])
231
250
  expect(stub).to have_been_requested
232
251
  end
233
252
 
234
253
  it "get html" do
235
254
  stub = stub_request(:get, url).to_return(status: 200, headers: { 'X-Rate-Limit-Remaining' => 3 })
236
255
  response = subject.get(url, accept: 'html')
237
- expect(response).to eq("errors"=>[{"status"=>429, "title"=>"Too many requests"}])
256
+ expect(response.body).to eq("errors"=>[{"status"=>429, "title"=>"Too many requests"}])
238
257
  expect(stub).to have_been_requested
239
258
  end
240
259
 
241
260
  it "post xml" do
242
261
  stub = stub_request(:post, url).with(:body => post_data.to_xml)
243
262
  .to_return(status: 200, headers: { 'X-Rate-Limit-Remaining' => 3 })
244
- subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response).to be_nil }
263
+ subject.post(url, accept: 'xml', data: post_data.to_xml) { |response| expect(response.body).to be_nil }
245
264
  expect(stub).to have_been_requested
246
265
  end
247
266
  end
@@ -253,7 +272,7 @@ describe Maremma do
253
272
  stub_request(:get, url).to_return(status: 301, headers: { location: redirect_url })
254
273
  stub_request(:get, redirect_url).to_return(status: 200, body: "Test")
255
274
  response = subject.get(url)
256
- expect(response).to eq("data"=>"Test", "headers"=>{})
275
+ expect(response.body).to eq("data"=>"Test")
257
276
  end
258
277
 
259
278
  it "redirect four times" do
@@ -263,7 +282,7 @@ describe Maremma do
263
282
  stub_request(:get, redirect_url+ "/y").to_return(status: 301, headers: { location: redirect_url + "/z" })
264
283
  stub_request(:get, redirect_url + "/z").to_return(status: 200, body: "Test")
265
284
  response = subject.get(url)
266
- expect(response).to eq("data"=>"Test", "headers"=>{})
285
+ expect(response.body).to eq("data"=>"Test")
267
286
  end
268
287
 
269
288
  it "redirect limit 1" do
@@ -271,7 +290,7 @@ describe Maremma do
271
290
  stub_request(:get, redirect_url).to_return(status: 301, headers: { location: redirect_url + "/x" })
272
291
  stub_request(:get, redirect_url+ "/x").to_return(status: 301, headers: { location: redirect_url + "/y" })
273
292
  response = subject.get(url, limit: 1)
274
- expect(response).to eq("errors"=>[{"status"=>400, "title"=>"too many redirects; last one to: http://www.example.org/redirect/x"}])
293
+ expect(response.body).to eq("errors"=>[{"status"=>400, "title"=>"too many redirects; last one to: http://www.example.org/redirect/x"}])
275
294
  end
276
295
  end
277
296
 
@@ -279,7 +298,7 @@ describe Maremma do
279
298
  it "redirects to URL", vcr: true do
280
299
  url = "https://doi.org/10.5281/ZENODO.21430"
281
300
  response = subject.get(url)
282
- doc = Nokogiri::HTML(response.fetch("data", ""))
301
+ doc = Nokogiri::HTML(response.body.fetch("data", ""))
283
302
  title = doc.at_css("head title").text
284
303
  expect(title).to eq("DataCite-ORCID: 1.0 | Zenodo")
285
304
  end
@@ -287,7 +306,13 @@ describe Maremma do
287
306
  it "returns content as bibtex", vcr: true do
288
307
  url = "https://doi.org/10.5281/ZENODO.21430"
289
308
  response = subject.get(url, accept: "application/x-bibtex")
290
- expect(response.fetch("data", nil)).to eq("@misc{https://doi.org/10.5281/ZENODO.21430,\n doi = {10.5281/ZENODO.21430},\n url = {https://doi.org/10.5281/ZENODO.21430},\n author = {Martin Fenner and Karl Jonathan Ward and Gudmundur A. Thorisson and Robert Peters},\n publisher = {Zenodo},\n title = {DataCite-ORCID: 1.0},\n year = {2015}\n}")
309
+ expect(response.body.fetch("data", nil)).to eq("@misc{https://doi.org/10.5281/ZENODO.21430,\n doi = {10.5281/ZENODO.21430},\n url = {https://doi.org/10.5281/ZENODO.21430},\n author = {Martin Fenner and Karl Jonathan Ward and Gudmundur A. Thorisson and Robert Peters},\n publisher = {Zenodo},\n title = {DataCite-ORCID: 1.0},\n year = {2015}\n}")
310
+ end
311
+
312
+ it "returns content as APA-formatted citation", vcr: true do
313
+ url = "https://doi.org/10.5281/ZENODO.21430"
314
+ response = subject.get(url, accept: "text/x-bibliography; style=apa")
315
+ expect(response.body.fetch("data", nil)).to eq("Martin Fenner, Karl Jonathan Ward, Gudmundur A. Thorisson, & Robert Peters. (2015). DataCite-ORCID: 1.0. Zenodo. https://doi.org/10.5281/ZENODO.21430")
291
316
  end
292
317
  end
293
318
 
@@ -295,7 +320,7 @@ describe Maremma do
295
320
  it "parses link headers", vcr: true do
296
321
  url = "https://search.datacite.org/works/10.5281/ZENODO.21430"
297
322
  response = subject.get(url)
298
- headers = response.fetch("headers", {}).fetch("Link", "").split(", ")
323
+ headers = response.headers.fetch("Link", "").split(", ")
299
324
  expect(headers.first).to eq("<https://doi.org/10.5281/ZENODO.21430> ; rel=\"identifier\"")
300
325
  end
301
326
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maremma
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.4
4
+ version: '3.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Fenner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-23 00:00:00.000000000 Z
11
+ date: 2016-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -286,6 +286,7 @@ files:
286
286
  - lib/maremma/version.rb
287
287
  - maremma.gemspec
288
288
  - spec/fixtures/vcr_cassettes/Maremma/content_negotiation/redirects_to_URL.yml
289
+ - spec/fixtures/vcr_cassettes/Maremma/content_negotiation/returns_content_as_APA-formatted_citation.yml
289
290
  - spec/fixtures/vcr_cassettes/Maremma/content_negotiation/returns_content_as_bibtex.yml
290
291
  - spec/fixtures/vcr_cassettes/Maremma/get/get_json_with_params.yml
291
292
  - spec/fixtures/vcr_cassettes/Maremma/link_headers/parses_link_headers.yml