maremma 4.7 → 4.9

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/Gemfile.lock CHANGED
@@ -1,76 +1,81 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- maremma (4.7)
4
+ maremma (4.9)
5
5
  activesupport (>= 4.2.5)
6
6
  addressable (>= 2.3.6)
7
7
  builder (~> 3.2, >= 3.2.2)
8
+ charlock_holmes (~> 0.7.7)
8
9
  excon (~> 0.71.0)
9
- faraday (= 0.17.0)
10
+ faraday (~> 0.17.3)
10
11
  faraday-encoding (~> 0.0.4)
11
- faraday_middleware (~> 0.13.1)
12
- nokogiri (~> 1.10.4)
12
+ faraday_middleware (~> 0.14.0)
13
+ nokogiri (~> 1.11.2)
13
14
  oj (>= 2.8.3)
14
15
  oj_mimic_json (~> 1.0, >= 1.0.1)
15
16
 
16
17
  GEM
17
18
  remote: https://rubygems.org/
18
19
  specs:
19
- activesupport (6.0.2.2)
20
+ activesupport (6.1.3.2)
20
21
  concurrent-ruby (~> 1.0, >= 1.0.2)
21
- i18n (>= 0.7, < 2)
22
- minitest (~> 5.1)
23
- tzinfo (~> 1.1)
24
- zeitwerk (~> 2.2)
22
+ i18n (>= 1.6, < 2)
23
+ minitest (>= 5.1)
24
+ tzinfo (~> 2.0)
25
+ zeitwerk (~> 2.3)
25
26
  addressable (2.7.0)
26
27
  public_suffix (>= 2.0.2, < 5.0)
27
- ast (2.4.0)
28
+ ast (2.4.2)
28
29
  builder (3.2.4)
29
- concurrent-ruby (1.1.6)
30
- crack (0.4.3)
31
- safe_yaml (~> 1.0.0)
32
- diff-lcs (1.3)
33
- docile (1.3.2)
30
+ charlock_holmes (0.7.7)
31
+ concurrent-ruby (1.1.9)
32
+ crack (0.4.5)
33
+ rexml
34
+ diff-lcs (1.4.4)
35
+ docile (1.4.0)
34
36
  excon (0.71.1)
35
- faraday (0.17.0)
37
+ faraday (0.17.4)
36
38
  multipart-post (>= 1.2, < 3)
37
39
  faraday-encoding (0.0.5)
38
40
  faraday
39
- faraday_middleware (0.13.1)
41
+ faraday_middleware (0.14.0)
40
42
  faraday (>= 0.7.4, < 1.0)
41
43
  hashdiff (1.0.1)
42
- i18n (1.8.2)
44
+ i18n (1.8.10)
43
45
  concurrent-ruby (~> 1.0)
44
46
  jaro_winkler (1.5.4)
45
- mini_portile2 (2.4.0)
46
- minitest (5.14.0)
47
+ mini_portile2 (2.5.3)
48
+ minitest (5.14.4)
47
49
  multipart-post (2.1.1)
48
- nokogiri (1.10.9)
49
- mini_portile2 (~> 2.4.0)
50
- oj (3.10.5)
50
+ nokogiri (1.11.7)
51
+ mini_portile2 (~> 2.5.0)
52
+ racc (~> 1.4)
53
+ oj (3.11.5)
51
54
  oj_mimic_json (1.0.1)
52
- parallel (1.19.1)
53
- parser (2.7.0.5)
54
- ast (~> 2.4.0)
55
- public_suffix (4.0.3)
56
- rack (2.2.2)
55
+ parallel (1.20.1)
56
+ parser (3.0.1.1)
57
+ ast (~> 2.4.1)
58
+ public_suffix (4.0.6)
59
+ racc (1.5.2)
60
+ rack (2.2.3)
57
61
  rack-test (0.8.3)
58
62
  rack (>= 1.0, < 3)
59
63
  rainbow (3.0.0)
60
- rake (13.0.1)
61
- rspec (3.9.0)
62
- rspec-core (~> 3.9.0)
63
- rspec-expectations (~> 3.9.0)
64
- rspec-mocks (~> 3.9.0)
65
- rspec-core (3.9.1)
66
- rspec-support (~> 3.9.1)
67
- rspec-expectations (3.9.1)
64
+ rake (13.0.3)
65
+ rexml (3.2.5)
66
+ rspec (3.10.0)
67
+ rspec-core (~> 3.10.0)
68
+ rspec-expectations (~> 3.10.0)
69
+ rspec-mocks (~> 3.10.0)
70
+ rspec-core (3.10.1)
71
+ rspec-support (~> 3.10.0)
72
+ rspec-expectations (3.10.1)
68
73
  diff-lcs (>= 1.2.0, < 2.0)
69
- rspec-support (~> 3.9.0)
70
- rspec-mocks (3.9.1)
74
+ rspec-support (~> 3.10.0)
75
+ rspec-mocks (3.10.2)
71
76
  diff-lcs (>= 1.2.0, < 2.0)
72
- rspec-support (~> 3.9.0)
73
- rspec-support (3.9.2)
77
+ rspec-support (~> 3.10.0)
78
+ rspec-support (3.10.2)
74
79
  rubocop (0.77.0)
75
80
  jaro_winkler (~> 1.5.1)
76
81
  parallel (~> 1.10)
@@ -78,24 +83,24 @@ GEM
78
83
  rainbow (>= 2.2.2, < 4.0)
79
84
  ruby-progressbar (~> 1.7)
80
85
  unicode-display_width (>= 1.4.0, < 1.7)
81
- rubocop-performance (1.5.2)
86
+ rubocop-performance (1.6.1)
82
87
  rubocop (>= 0.71.0)
83
- ruby-progressbar (1.10.1)
84
- safe_yaml (1.0.5)
85
- simplecov (0.18.5)
88
+ ruby-progressbar (1.11.0)
89
+ simplecov (0.21.2)
86
90
  docile (~> 1.1)
87
91
  simplecov-html (~> 0.11)
88
- simplecov-html (0.12.2)
89
- thread_safe (0.3.6)
90
- tzinfo (1.2.6)
91
- thread_safe (~> 0.1)
92
+ simplecov_json_formatter (~> 0.1)
93
+ simplecov-html (0.12.3)
94
+ simplecov_json_formatter (0.1.3)
95
+ tzinfo (2.0.4)
96
+ concurrent-ruby (~> 1.0)
92
97
  unicode-display_width (1.6.1)
93
98
  vcr (3.0.3)
94
- webmock (3.8.3)
99
+ webmock (3.13.0)
95
100
  addressable (>= 2.3.6)
96
101
  crack (>= 0.3.2)
97
102
  hashdiff (>= 0.4.0, < 2.0.0)
98
- zeitwerk (2.3.0)
103
+ zeitwerk (2.4.2)
99
104
 
100
105
  PLATFORMS
101
106
  ruby
@@ -113,4 +118,4 @@ DEPENDENCIES
113
118
  webmock (~> 3.0, >= 3.0.1)
114
119
 
115
120
  BUNDLED WITH
116
- 2.1.4
121
+ 2.2.19
data/lib/maremma.rb CHANGED
@@ -11,10 +11,11 @@ require "uri"
11
11
  require "addressable/uri"
12
12
  require "maremma/xml_converter"
13
13
  require "maremma/version"
14
+ require "charlock_holmes"
14
15
 
15
16
  module Maremma
16
17
  DEFAULT_TIMEOUT = 60
17
- ALLOWED_CONTENT_TAGS = %w(strong em b i code pre sub sup br)
18
+ ALLOWED_CONTENT_TAGS = %w(strong em b i code pre sub sup br).freeze
18
19
  NETWORKABLE_EXCEPTIONS = [Faraday::ClientError,
19
20
  Faraday::TimeoutError,
20
21
  Faraday::ResourceNotFound,
@@ -24,37 +25,40 @@ module Maremma
24
25
  Encoding::UndefinedConversionError,
25
26
  ArgumentError,
26
27
  NoMethodError,
27
- TypeError]
28
+ TypeError].freeze
28
29
 
29
30
  # ActiveSupport::XmlMini.backend = "Nokogiri"
30
31
 
31
- def self.post(url, options={})
32
- self.method(url, options.merge(method: "post"))
32
+ def self.post(url, options = {})
33
+ method(url, options.merge(method: "post"))
33
34
  end
34
35
 
35
- def self.put(url, options={})
36
- self.method(url, options.merge(method: "put"))
36
+ def self.put(url, options = {})
37
+ method(url, options.merge(method: "put"))
37
38
  end
38
39
 
39
- def self.patch(url, options={})
40
- self.method(url, options.merge(method: "patch"))
40
+ def self.patch(url, options = {})
41
+ method(url, options.merge(method: "patch"))
41
42
  end
42
43
 
43
- def self.delete(url, options={})
44
- self.method(url, options.merge(method: "delete"))
44
+ def self.delete(url, options = {})
45
+ method(url, options.merge(method: "delete"))
45
46
  end
46
47
 
47
- def self.get(url, options={})
48
- self.method(url, options.merge(method: "get"))
48
+ def self.get(url, options = {})
49
+ method(url, options.merge(method: "get"))
49
50
  end
50
51
 
51
- def self.head(url, options={})
52
- self.method(url, options.merge(method: "head"))
52
+ def self.head(url, options = {})
53
+ method(url, options.merge(method: "head"))
53
54
  end
54
55
 
55
- def self.method(url, options={})
56
+ def self.method(url, options = {})
56
57
  is_valid_url?(url)
57
58
 
59
+ # normalize url
60
+ url = Addressable::URI.parse(url).normalize
61
+
58
62
  options[:data] ||= {}
59
63
  options[:headers] = set_request_headers(url, options)
60
64
 
@@ -63,23 +67,29 @@ module Maremma
63
67
  conn.options[:timeout] = options[:timeout] || DEFAULT_TIMEOUT
64
68
 
65
69
  response = case options[:method]
66
- when "get" then conn.get url, {}, options[:headers] do |request|
67
- request.headers["Host"] = URI.parse(url.to_s).host
68
- end
69
- when "post" then conn.post url, {}, options[:headers] do |request|
70
- request.body = options[:data]
71
- request.headers["Host"] = URI.parse(url.to_s).host
72
- end
73
- when "put" then conn.put url, {}, options[:headers] do |request|
74
- request.body = options[:data]
75
- request.headers["Host"] = URI.parse(url.to_s).host
76
- end
77
- when "patch" then conn.patch url, {}, options[:headers] do |request|
78
- request.body = options[:data]
79
- request.headers["Host"] = URI.parse(url.to_s).host
80
- end
81
- when "delete" then conn.delete url, {}, options[:headers]
82
- when "head" then conn.head url, {}, options[:headers]
70
+ when "get"
71
+ conn.get url, {}, options[:headers] do |request|
72
+ request.headers["Host"] = URI.parse(url.to_s).host
73
+ end
74
+ when "post"
75
+ conn.post url, {}, options[:headers] do |request|
76
+ request.body = options[:data]
77
+ request.headers["Host"] = URI.parse(url.to_s).host
78
+ end
79
+ when "put"
80
+ conn.put url, {}, options[:headers] do |request|
81
+ request.body = options[:data]
82
+ request.headers["Host"] = URI.parse(url.to_s).host
83
+ end
84
+ when "patch"
85
+ conn.patch url, {}, options[:headers] do |request|
86
+ request.body = options[:data]
87
+ request.headers["Host"] = URI.parse(url.to_s).host
88
+ end
89
+ when "delete"
90
+ conn.delete url, {}, options[:headers]
91
+ when "head"
92
+ conn.head url, {}, options[:headers]
83
93
  end
84
94
 
85
95
  # return error if we are close to the rate limit, if supported in headers
@@ -99,8 +109,8 @@ module Maremma
99
109
  headers: response.headers,
100
110
  status: response.status,
101
111
  url: response.env[:url].to_s)
102
- rescue *NETWORKABLE_EXCEPTIONS => error
103
- error_response = rescue_faraday_error(error, response)
112
+ rescue *NETWORKABLE_EXCEPTIONS => e
113
+ error_response = rescue_faraday_error(e, response)
104
114
  OpenStruct.new(body: error_response,
105
115
  status: error_response.fetch("errors", {}).first.fetch("status", 400),
106
116
  headers: response ? response.headers : nil,
@@ -134,7 +144,7 @@ module Maremma
134
144
  raise TypeError, "Invalid URL: #{url}" unless %w(http https).include?(parsed.scheme)
135
145
  end
136
146
 
137
- def self.set_request_headers(url, options={})
147
+ def self.set_request_headers(_url, options = {})
138
148
  header_options = { "html" => "text/html;charset=UTF-8",
139
149
  "xml" => "application/xml;charset=UTF-8",
140
150
  "json" => "application/json;charset=UTF-8" }
@@ -145,7 +155,7 @@ module Maremma
145
155
  headers["User-Agent"] = ENV["USER_AGENT"] || "Mozilla/5.0 (compatible; Maremma/#{Maremma::VERSION}; +https://github.com/datacite/maremma)"
146
156
 
147
157
  # set host, needed for some services behind proxy
148
- #headers["Host"] = URI.parse(url).host #if options[:host]
158
+ # headers["Host"] = URI.parse(url).host #if options[:host]
149
159
 
150
160
  # set Content-Type
151
161
  headers["Content-type"] = header_options.fetch(options[:content_type], options[:content_type]) if options[:content_type].present?
@@ -176,12 +186,12 @@ module Maremma
176
186
  if error.is_a?(Faraday::ResourceNotFound)
177
187
  { "errors" => [{ "status" => 404, "title" => "Not found" }] }
178
188
  elsif error.message == "the server responded with status 401" || error.try(:response) && error.response[:status] == 401
179
- { "errors" => [{ "status" => 401, "title" =>"Unauthorized" }] }
189
+ { "errors" => [{ "status" => 401, "title" => "Unauthorized" }] }
180
190
  elsif error.is_a?(Faraday::ConnectionFailed)
181
191
  { "errors" => [{ "status" => 403, "title" => parse_error_response(error.message) }] }
182
192
 
183
193
  elsif error.is_a?(Faraday::TimeoutError) || (error.try(:response) && error.response[:status] == 408)
184
- { "errors" => [{ "status" => 408, "title" =>"Request timeout" }] }
194
+ { "errors" => [{ "status" => 408, "title" => "Request timeout" }] }
185
195
  else
186
196
  status = response ? response.status : 400
187
197
  title = response ? parse_error_response(response.body) : parse_error_response(error.message)
@@ -189,7 +199,7 @@ module Maremma
189
199
  end
190
200
  end
191
201
 
192
- def self.parse_success_response(string, options={})
202
+ def self.parse_success_response(string, options = {})
193
203
  return nil if options[:method] == "head"
194
204
 
195
205
  string = parse_response(string, options)
@@ -219,11 +229,16 @@ module Maremma
219
229
  end
220
230
  end
221
231
 
222
- def self.parse_response(string, options={})
223
- string = string.dup.force_encoding("UTF-8")
224
- return string if options[:raw]
232
+ def self.parse_response(string, options = {})
233
+ detection = CharlockHolmes::EncodingDetector.detect(string)
234
+ utf8_encoded_content = CharlockHolmes::Converter.convert(string, detection[:encoding], "UTF-8")
235
+ return utf8_encoded_content if options[:raw]
225
236
 
226
- from_json(string) || from_xml(string) || from_string(string)
237
+ from_json(utf8_encoded_content) || from_xml(utf8_encoded_content) || from_string(utf8_encoded_content)
238
+ rescue ArgumentError
239
+ # handle U_STRING_NOT_TERMINATED_WARNING
240
+ from_json(string.force_encoding("UTF-8")) || from_xml(string.force_encoding("UTF-8")) ||
241
+ from_string(string.force_encoding("UTF-8"))
227
242
  end
228
243
 
229
244
  # currently supported by Twitter and Github
@@ -236,15 +251,13 @@ module Maremma
236
251
  # keep XML attributes, http://stackoverflow.com/a/10794044
237
252
  # escape tags allowed in content
238
253
  def self.from_xml(string)
239
- ALLOWED_CONTENT_TAGS.each do |tag|
254
+ ALLOWED_CONTENT_TAGS.each do |tag|
240
255
  string.gsub!("<#{tag}>", "&lt;#{tag}&gt;")
241
256
  string.gsub!("</#{tag}>", "&lt;/#{tag}&gt;")
242
257
  end
243
258
 
244
259
  if Nokogiri::XML(string, nil, "UTF-8").errors.empty?
245
260
  Hash.from_xml(string)
246
- else
247
- nil
248
261
  end
249
262
  end
250
263
 
@@ -1,3 +1,3 @@
1
1
  module Maremma
2
- VERSION = "4.7"
2
+ VERSION = "4.9".freeze
3
3
  end
data/maremma.gemspec CHANGED
@@ -21,11 +21,12 @@ Gem::Specification.new do |s|
21
21
  s.add_dependency "activesupport", ">= 4.2.5"
22
22
  s.add_dependency "addressable", ">= 2.3.6"
23
23
  s.add_dependency "builder", "~> 3.2", ">= 3.2.2"
24
+ s.add_dependency "charlock_holmes", "~> 0.7.7"
24
25
  s.add_dependency "excon", "~> 0.71.0"
25
- s.add_dependency "faraday", "0.17.0"
26
+ s.add_dependency "faraday", "~> 0.17.3"
26
27
  s.add_dependency "faraday-encoding", "~> 0.0.4"
27
- s.add_dependency "faraday_middleware", "~> 0.13.1"
28
- s.add_dependency "nokogiri", "~> 1.10.4"
28
+ s.add_dependency "faraday_middleware", "~> 0.14.0"
29
+ s.add_dependency "nokogiri", "~> 1.11.2"
29
30
  s.add_dependency "oj", ">= 2.8.3"
30
31
  s.add_dependency "oj_mimic_json", "~> 1.0", ">= 1.0.1"
31
32
  s.add_development_dependency "bundler", "~> 2.0"
@@ -37,5 +38,4 @@ Gem::Specification.new do |s|
37
38
  s.add_development_dependency "simplecov"
38
39
  s.add_development_dependency "vcr", "~> 3.0", ">= 3.0.3"
39
40
  s.add_development_dependency "webmock", "~> 3.0", ">= 3.0.1"
40
-
41
41
  end
data/spec/maremma_spec.rb CHANGED
@@ -11,26 +11,26 @@ describe Maremma do
11
11
 
12
12
  context "get" do
13
13
  it "get json" do
14
- stub = stub_request(:get, url).to_return(:body => data.to_json, :status => 200, :headers => { "Content-Type" => "application/json" })
14
+ stub = stub_request(:get, url).to_return(body: data.to_json, status: 200, headers: { "Content-Type" => "application/json" })
15
15
  response = subject.get(url)
16
16
  expect(response.body).to eq("data" => data)
17
- expect(response.headers).to eq("Content-Type"=>"application/json")
17
+ expect(response.headers).to eq("Content-Type" => "application/json")
18
18
  expect(stub).to have_been_requested
19
19
  end
20
20
 
21
21
  it "get xml" do
22
- stub = stub_request(:get, url).to_return(:body => data.to_xml, :status => 200, :headers => { "Content-Type" => "application/xml" })
22
+ stub = stub_request(:get, url).to_return(body: data.to_xml, status: 200, headers: { "Content-Type" => "application/xml" })
23
23
  response = subject.get(url, accept: "xml")
24
- expect(response.body).to eq("data"=>data)
25
- expect(response.headers).to eq("Content-Type"=>"application/xml")
24
+ expect(response.body).to eq("data" => data)
25
+ expect(response.headers).to eq("Content-Type" => "application/xml")
26
26
  expect(stub).to have_been_requested
27
27
  end
28
28
 
29
29
  it "get html" do
30
- stub = stub_request(:get, url).to_return(:body => data.to_s, :status => 200, :headers => { "Content-Type" => "text/html" })
30
+ stub = stub_request(:get, url).to_return(body: data.to_s, status: 200, headers: { "Content-Type" => "text/html" })
31
31
  response = subject.get(url, accept: "html")
32
32
  expect(response.body).to eq("data" => data.to_s)
33
- expect(response.headers).to eq("Content-Type"=>"text/html")
33
+ expect(response.headers).to eq("Content-Type" => "text/html")
34
34
  expect(stub).to have_been_requested
35
35
  end
36
36
 
@@ -53,19 +53,28 @@ describe Maremma do
53
53
  end
54
54
 
55
55
  it "get json with meta hash" do
56
- data = { "data" => { "name" => "Jack" }, "meta" => { "count" => 12 }}
57
- stub = stub_request(:get, url).to_return(:body => data.to_json, :status => 200, :headers => { "Content-Type" => "application/json" })
56
+ data = { "data" => { "name" => "Jack" }, "meta" => { "count" => 12 } }
57
+ stub = stub_request(:get, url).to_return(body: data.to_json, status: 200, headers: { "Content-Type" => "application/json" })
58
+ response = subject.get(url)
59
+ expect(response.body).to eq("data" => { "name" => "Jack" }, "meta" => { "count" => 12 })
60
+ expect(response.headers).to eq("Content-Type" => "application/json")
61
+ expect(stub).to have_been_requested
62
+ end
63
+
64
+ it "get json with umlaut" do
65
+ url = "https://api.ror.org/organizations?page=1&query=münster"
66
+ stub = stub_request(:get, url).to_return(body: data.to_json, status: 200, headers: { "Content-Type" => "application/json" })
58
67
  response = subject.get(url)
59
- expect(response.body).to eq("data"=>{"name"=>"Jack"}, "meta"=>{"count"=>12})
60
- expect(response.headers).to eq("Content-Type"=>"application/json")
68
+ expect(response.body).to eq("data" => data)
69
+ expect(response.headers).to eq("Content-Type" => "application/json")
61
70
  expect(stub).to have_been_requested
62
71
  end
63
72
 
64
73
  it "get xml raw" do
65
- stub = stub_request(:get, url).to_return(:body => data.to_xml, :status => 200, :headers => { "Content-Type" => "application/xml" })
74
+ stub = stub_request(:get, url).to_return(body: data.to_xml, status: 200, headers: { "Content-Type" => "application/xml" })
66
75
  response = subject.get(url, accept: "xml", raw: true)
67
- expect(response.body).to eq("data"=>data.to_xml)
68
- expect(response.headers).to eq("Content-Type"=>"application/xml")
76
+ expect(response.body).to eq("data" => data.to_xml)
77
+ expect(response.headers).to eq("Content-Type" => "application/xml")
69
78
  expect(stub).to have_been_requested
70
79
  end
71
80
 
@@ -87,23 +96,23 @@ describe Maremma do
87
96
 
88
97
  context "head" do
89
98
  it "head html" do
90
- stub = stub_request(:head, url).to_return(:status => 200, :headers => { "Content-Type" => "text/html" })
99
+ stub = stub_request(:head, url).to_return(status: 200, headers: { "Content-Type" => "text/html" })
91
100
  response = subject.head(url, accept: "html")
92
101
  expect(response.body).to be_nil
93
- expect(response.headers).to eq("Content-Type"=>"text/html")
102
+ expect(response.headers).to eq("Content-Type" => "text/html")
94
103
  expect(stub).to have_been_requested
95
104
  end
96
105
  end
97
106
 
98
107
  context "post" do
99
108
  it "post json" do
100
- stub = stub_request(:post, url).with(:body => post_data.to_json).to_return(:body => data.to_json, :status => 200, :headers => { "Content-Type" => "application/json" })
109
+ stub = stub_request(:post, url).with(body: post_data.to_json).to_return(body: data.to_json, status: 200, headers: { "Content-Type" => "application/json" })
101
110
  subject.post(url, content_type: "json", data: post_data.to_json) { |response| expect(response.body).to eq(2) }
102
111
  expect(stub).to have_been_requested
103
112
  end
104
113
 
105
114
  it "post xml" do
106
- stub = stub_request(:post, url).with(:body => post_data.to_xml).to_return(:body => data.to_xml, :status => 200, :headers => { "Content-Type" => "text/html" })
115
+ stub = stub_request(:post, url).with(body: post_data.to_xml).to_return(body: data.to_xml, status: 200, headers: { "Content-Type" => "text/html" })
107
116
  subject.post(url, content_type: "xml", data: post_data.to_xml) { |response| expect(Hash.from_xml(response.body.to_s)["hash"]).to eq(data) }
108
117
  expect(stub).to have_been_requested
109
118
  end
@@ -111,13 +120,13 @@ describe Maremma do
111
120
 
112
121
  context "put" do
113
122
  it "put json" do
114
- stub = stub_request(:put, url).with(:body => post_data.to_json).to_return(:body => data.to_json, :status => 200, :headers => { "Content-Type" => "application/json" })
123
+ stub = stub_request(:put, url).with(body: post_data.to_json).to_return(body: data.to_json, status: 200, headers: { "Content-Type" => "application/json" })
115
124
  subject.put(url, content_type: "json", data: post_data.to_json) { |response| expect(JSON.parse(response.body.to_s)).to eq(data) }
116
125
  expect(stub).to have_been_requested
117
126
  end
118
127
 
119
128
  it "put xml" do
120
- stub = stub_request(:put, url).with(:body => post_data.to_xml).to_return(:body => data.to_xml, :status => 200, :headers => { "Content-Type" => "text/html" })
129
+ stub = stub_request(:put, url).with(body: post_data.to_xml).to_return(body: data.to_xml, status: 200, headers: { "Content-Type" => "text/html" })
121
130
  subject.put(url, content_type: "xml", data: post_data.to_xml) { |response| expect(Hash.from_xml(response.body.to_s)["hash"]).to eq(data) }
122
131
  expect(stub).to have_been_requested
123
132
  end
@@ -125,13 +134,13 @@ describe Maremma do
125
134
 
126
135
  context "patch" do
127
136
  it "patch json" do
128
- stub = stub_request(:patch, url).with(:body => post_data.to_json).to_return(:body => data.to_json, :status => 200, :headers => { "Content-Type" => "application/json" })
137
+ stub = stub_request(:patch, url).with(body: post_data.to_json).to_return(body: data.to_json, status: 200, headers: { "Content-Type" => "application/json" })
129
138
  subject.patch(url, content_type: "json", data: post_data.to_json) { |response| expect(JSON.parse(response.body.to_s)).to eq(data) }
130
139
  expect(stub).to have_been_requested
131
140
  end
132
141
 
133
142
  it "patch xml" do
134
- stub = stub_request(:patch, url).with(:body => post_data.to_xml).to_return(:body => data.to_xml, :status => 200, :headers => { "Content-Type" => "text/html" })
143
+ stub = stub_request(:patch, url).with(body: post_data.to_xml).to_return(body: data.to_xml, status: 200, headers: { "Content-Type" => "text/html" })
135
144
  subject.patch(url, content_type: "xml", data: post_data.to_xml) { |response| expect(Hash.from_xml(response.body.to_s)["hash"]).to eq(data) }
136
145
  expect(stub).to have_been_requested
137
146
  end
@@ -139,125 +148,125 @@ describe Maremma do
139
148
 
140
149
  context "empty response" do
141
150
  it "get json" do
142
- stub = stub_request(:get, url).to_return(:body => nil, :status => 200, :headers => { "Content-Type" => "application/json" })
151
+ stub = stub_request(:get, url).to_return(body: nil, status: 200, headers: { "Content-Type" => "application/json" })
143
152
  response = subject.get(url)
144
- expect(response.body).to eq("data"=>nil)
145
- expect(response.headers).to eq("Content-Type"=>"application/json")
153
+ expect(response.body).to eq("data" => nil)
154
+ expect(response.headers).to eq("Content-Type" => "application/json")
146
155
  expect(stub).to have_been_requested
147
156
  end
148
157
 
149
158
  it "get xml" do
150
- stub = stub_request(:get, url).to_return(:body => nil, :status => 200, :headers => { "Content-Type" => "application/xml" })
159
+ stub = stub_request(:get, url).to_return(body: nil, status: 200, headers: { "Content-Type" => "application/xml" })
151
160
  response = subject.get(url, accept: "xml")
152
- expect(response.body).to eq("data"=>nil)
153
- expect(response.headers).to eq("Content-Type"=>"application/xml")
161
+ expect(response.body).to eq("data" => nil)
162
+ expect(response.headers).to eq("Content-Type" => "application/xml")
154
163
  expect(stub).to have_been_requested
155
164
  end
156
165
 
157
166
  it "get html" do
158
- stub = stub_request(:get, url).to_return(:body => nil, :status => 200, :headers => { "Content-Type" => "text/html" })
167
+ stub = stub_request(:get, url).to_return(body: nil, status: 200, headers: { "Content-Type" => "text/html" })
159
168
  response = subject.get(url, accept: "html")
160
169
  expect(response.body).to eq("data" => nil)
161
- expect(response.headers).to eq("Content-Type"=>"text/html")
170
+ expect(response.headers).to eq("Content-Type" => "text/html")
162
171
  expect(stub).to have_been_requested
163
172
  end
164
173
 
165
174
  it "post xml" do
166
- stub = stub_request(:post, url).with(:body => post_data.to_xml).to_return(:body => nil, :status => 200, :headers => { "Content-Type" => "application/xml" })
175
+ stub = stub_request(:post, url).with(body: post_data.to_xml).to_return(body: nil, status: 200, headers: { "Content-Type" => "application/xml" })
167
176
  subject.post(url, accept: "xml", data: post_data.to_xml) { |response| expect(response.body).to eq("data" => nil) }
168
177
  expect(stub).to have_been_requested
169
178
  end
170
179
 
171
180
  it "put xml" do
172
- stub = stub_request(:put, url).with(:body => post_data.to_xml).to_return(:body => nil, :status => 200, :headers => { "Content-Type" => "application/xml" })
181
+ stub = stub_request(:put, url).with(body: post_data.to_xml).to_return(body: nil, status: 200, headers: { "Content-Type" => "application/xml" })
173
182
  subject.put(url, accept: "xml", data: post_data.to_xml) { |response| expect(response.body).to eq("data" => nil) }
174
183
  expect(stub).to have_been_requested
175
184
  end
176
185
  end
177
186
 
178
187
  context "not found" do
179
- let(:error) { { "errors" => [{ "status" => 404, "title" => "Not found" }]} }
188
+ let(:error) { { "errors" => [{ "status" => 404, "title" => "Not found" }] } }
180
189
 
181
190
  it "get json" do
182
- stub = stub_request(:get, url).to_return(:body => error.to_json, :status => [404], :headers => { "Content-Type" => "application/json" })
191
+ stub = stub_request(:get, url).to_return(body: error.to_json, status: [404], headers: { "Content-Type" => "application/json" })
183
192
  response = subject.get(url, accept: "json")
184
193
  expect(response.body).to eq(error)
185
194
  expect(stub).to have_been_requested
186
195
  end
187
196
 
188
197
  it "get xml" do
189
- stub = stub_request(:get, url).to_return(:body => error.to_xml, :status => [404], :headers => { "Content-Type" => "application/xml" })
198
+ stub = stub_request(:get, url).to_return(body: error.to_xml, status: [404], headers: { "Content-Type" => "application/xml" })
190
199
  response = subject.get(url, accept: "xml")
191
200
  expect(response.body).to eq(error)
192
201
  expect(stub).to have_been_requested
193
202
  end
194
203
 
195
204
  it "get html" do
196
- stub = stub_request(:get, url).to_return(:body => error.to_s, :status => [404], :headers => { "Content-Type" => "text/html" })
205
+ stub = stub_request(:get, url).to_return(body: error.to_s, status: [404], headers: { "Content-Type" => "text/html" })
197
206
  response = subject.get(url, accept: "html")
198
207
  expect(response.body).to eq(error)
199
208
  expect(stub).to have_been_requested
200
209
  end
201
210
 
202
211
  it "head html" do
203
- stub = stub_request(:head, url).to_return(:body => error.to_s, :status => [404], :headers => { "Content-Type" => "text/html" })
212
+ stub = stub_request(:head, url).to_return(body: error.to_s, status: [404], headers: { "Content-Type" => "text/html" })
204
213
  response = subject.head(url, accept: "html")
205
214
  expect(response.status).to eq(404)
206
215
  expect(stub).to have_been_requested
207
216
  end
208
217
 
209
218
  it "post xml" do
210
- stub = stub_request(:post, url).with(:body => post_data.to_xml).to_return(:body => error.to_xml, :status => [404], :headers => { "Content-Type" => "application/xml" })
219
+ stub = stub_request(:post, url).with(body: post_data.to_xml).to_return(body: error.to_xml, status: [404], headers: { "Content-Type" => "application/xml" })
211
220
  subject.post(url, accept: "xml", data: post_data.to_xml) { |response| expect(Hash.from_xml(response.to_s)["hash"]).to eq(error) }
212
221
  expect(stub).to have_been_requested
213
222
  end
214
223
 
215
224
  it "put xml" do
216
- stub = stub_request(:put, url).with(:body => post_data.to_xml).to_return(:body => error.to_xml, :status => [404], :headers => { "Content-Type" => "application/xml" })
225
+ stub = stub_request(:put, url).with(body: post_data.to_xml).to_return(body: error.to_xml, status: [404], headers: { "Content-Type" => "application/xml" })
217
226
  subject.put(url, accept: "xml", data: post_data.to_xml) { |response| expect(Hash.from_xml(response.to_s)["hash"]).to eq(error) }
218
227
  expect(stub).to have_been_requested
219
228
  end
220
229
  end
221
230
 
222
231
  context "method not allowed" do
223
- let(:error) { { "errors" => [{ "status" => 405, "title" => "Method not allowed" }]} }
232
+ let(:error) { { "errors" => [{ "status" => 405, "title" => "Method not allowed" }] } }
224
233
 
225
234
  it "get json" do
226
- stub = stub_request(:get, url).to_return(:body => error.to_json, :status => [405], :headers => { "Content-Type" => "application/json" })
235
+ stub = stub_request(:get, url).to_return(body: error.to_json, status: [405], headers: { "Content-Type" => "application/json" })
227
236
  response = subject.get(url, accept: "json")
228
237
  expect(response.body).to eq(error)
229
238
  expect(stub).to have_been_requested
230
239
  end
231
240
 
232
241
  it "get xml" do
233
- stub = stub_request(:get, url).to_return(:body => error.to_xml, :status => [405], :headers => { "Content-Type" => "application/xml" })
242
+ stub = stub_request(:get, url).to_return(body: error.to_xml, status: [405], headers: { "Content-Type" => "application/xml" })
234
243
  response = subject.get(url, accept: "xml")
235
244
  expect(response.body).to eq(error)
236
245
  expect(stub).to have_been_requested
237
246
  end
238
247
 
239
248
  it "get html" do
240
- stub = stub_request(:get, url).to_return(:body => error.dig("errors", 0, "title"), :status => [405], :headers => { "Content-Type" => "text/html" })
249
+ stub = stub_request(:get, url).to_return(body: error.dig("errors", 0, "title"), status: [405], headers: { "Content-Type" => "text/html" })
241
250
  response = subject.get(url, accept: "html")
242
251
  expect(response.body).to eq(error)
243
252
  expect(stub).to have_been_requested
244
253
  end
245
254
 
246
255
  it "head html" do
247
- stub = stub_request(:head, url).to_return(:body => error.to_s, :status => [405], :headers => { "Content-Type" => "text/html" })
256
+ stub = stub_request(:head, url).to_return(body: error.to_s, status: [405], headers: { "Content-Type" => "text/html" })
248
257
  response = subject.head(url, accept: "html")
249
258
  expect(response.status).to eq(405)
250
259
  expect(stub).to have_been_requested
251
260
  end
252
261
 
253
262
  it "post xml" do
254
- stub = stub_request(:post, url).with(:body => post_data.to_xml).to_return(:body => error.to_xml, :status => [405], :headers => { "Content-Type" => "application/xml" })
263
+ stub = stub_request(:post, url).with(body: post_data.to_xml).to_return(body: error.to_xml, status: [405], headers: { "Content-Type" => "application/xml" })
255
264
  subject.post(url, accept: "xml", data: post_data.to_xml) { |response| expect(Hash.from_xml(response.to_s)["hash"]).to eq(error) }
256
265
  expect(stub).to have_been_requested
257
266
  end
258
267
 
259
268
  it "put xml" do
260
- stub = stub_request(:put, url).with(:body => post_data.to_xml).to_return(:body => error.to_xml, :status => [405], :headers => { "Content-Type" => "application/xml" })
269
+ stub = stub_request(:put, url).with(body: post_data.to_xml).to_return(body: error.to_xml, status: [405], headers: { "Content-Type" => "application/xml" })
261
270
  subject.put(url, accept: "xml", data: post_data.to_xml) { |response| expect(Hash.from_xml(response.to_s)["hash"]).to eq(error) }
262
271
  expect(stub).to have_been_requested
263
272
  end
@@ -265,41 +274,41 @@ describe Maremma do
265
274
 
266
275
  context "request timeout" do
267
276
  it "get json" do
268
- stub = stub_request(:get, url).to_return(:status => [408])
277
+ stub = stub_request(:get, url).to_return(status: [408])
269
278
  response = subject.get(url)
270
- expect(response.body).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
279
+ expect(response.body).to eq("errors" => [{ "status" => 408, "title" => "Request timeout" }])
271
280
  expect(stub).to have_been_requested
272
281
  end
273
282
 
274
283
  it "get xml" do
275
- stub = stub_request(:get, url).to_return(:status => [408])
284
+ stub = stub_request(:get, url).to_return(status: [408])
276
285
  response = subject.get(url, accept: "xml")
277
- expect(response.body).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
286
+ expect(response.body).to eq("errors" => [{ "status" => 408, "title" => "Request timeout" }])
278
287
  expect(stub).to have_been_requested
279
288
  end
280
289
 
281
290
  it "get html" do
282
- stub = stub_request(:get, url).to_return(:status => [408])
291
+ stub = stub_request(:get, url).to_return(status: [408])
283
292
  response = subject.get(url, accept: "html")
284
- expect(response.body).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
293
+ expect(response.body).to eq("errors" => [{ "status" => 408, "title" => "Request timeout" }])
285
294
  expect(stub).to have_been_requested
286
295
  end
287
296
 
288
297
  it "head html" do
289
- stub = stub_request(:head, url).to_return(:status => [408])
298
+ stub = stub_request(:head, url).to_return(status: [408])
290
299
  response = subject.head(url, accept: "html")
291
300
  expect(response.status).to eq(408)
292
301
  expect(stub).to have_been_requested
293
302
  end
294
303
 
295
304
  it "post xml" do
296
- stub = stub_request(:post, url).with(:body => post_data.to_xml).to_return(:status => [408])
305
+ stub = stub_request(:post, url).with(body: post_data.to_xml).to_return(status: [408])
297
306
  subject.post(url, accept: "xml", data: post_data.to_xml) { |response| expect(response.body).to be_nil }
298
307
  expect(stub).to have_been_requested
299
308
  end
300
309
 
301
310
  it "put xml" do
302
- stub = stub_request(:put, url).with(:body => post_data.to_xml).to_return(:status => [408])
311
+ stub = stub_request(:put, url).with(body: post_data.to_xml).to_return(status: [408])
303
312
  subject.put(url, accept: "xml", data: post_data.to_xml) { |response| expect(response.body).to be_nil }
304
313
  expect(stub).to have_been_requested
305
314
  end
@@ -307,10 +316,10 @@ describe Maremma do
307
316
 
308
317
  context "delete" do
309
318
  it "delete" do
310
- stub = stub_request(:delete, url).to_return(:status => 204, :headers => { "Content-Type" => "text/html" })
319
+ stub = stub_request(:delete, url).to_return(status: 204, headers: { "Content-Type" => "text/html" })
311
320
  response = subject.delete(url)
312
- expect(response.body).to eq("data"=>nil)
313
- expect(response.headers).to eq("Content-Type"=>"text/html")
321
+ expect(response.body).to eq("data" => nil)
322
+ expect(response.headers).to eq("Content-Type" => "text/html")
314
323
  expect(response.status).to eq(204)
315
324
  expect(stub).to have_been_requested
316
325
  end
@@ -320,32 +329,32 @@ describe Maremma do
320
329
  it "get json" do
321
330
  stub = stub_request(:get, url).to_raise(Faraday::ConnectionFailed.new("Connection refused - connect(2)"))
322
331
  response = subject.get(url)
323
- expect(response.body).to eq("errors"=>[{"status"=>403, "title"=>"Connection refused - connect(2)"}])
332
+ expect(response.body).to eq("errors" => [{ "status" => 403, "title" => "Connection refused - connect(2)" }])
324
333
  expect(stub).to have_been_requested
325
334
  end
326
335
 
327
336
  it "get xml" do
328
337
  stub = stub_request(:get, url).to_raise(Faraday::ConnectionFailed.new("Connection refused - connect(2)"))
329
338
  response = subject.get(url, accept: "xml")
330
- expect(response.body).to eq("errors"=>[{"status"=>403, "title"=>"Connection refused - connect(2)"}])
339
+ expect(response.body).to eq("errors" => [{ "status" => 403, "title" => "Connection refused - connect(2)" }])
331
340
  expect(stub).to have_been_requested
332
341
  end
333
342
 
334
343
  it "get html" do
335
344
  stub = stub_request(:get, url).to_raise(Faraday::ConnectionFailed.new("Connection refused - connect(2)"))
336
345
  response = subject.get(url, accept: "html")
337
- expect(response.body).to eq("errors"=>[{"status"=>403, "title"=>"Connection refused - connect(2)"}])
346
+ expect(response.body).to eq("errors" => [{ "status" => 403, "title" => "Connection refused - connect(2)" }])
338
347
  expect(stub).to have_been_requested
339
348
  end
340
349
 
341
350
  it "post xml" do
342
- stub = stub_request(:post, url).with(:body => post_data.to_xml).to_raise(Faraday::ConnectionFailed.new("Connection refused - connect(2)"))
351
+ stub = stub_request(:post, url).with(body: post_data.to_xml).to_raise(Faraday::ConnectionFailed.new("Connection refused - connect(2)"))
343
352
  subject.post(url, accept: "xml", data: post_data.to_xml) { |response| expect(response.body).to be_nil }
344
353
  expect(stub).to have_been_requested
345
354
  end
346
355
 
347
356
  it "put xml" do
348
- stub = stub_request(:put, url).with(:body => post_data.to_xml).to_raise(Faraday::ConnectionFailed.new("Connection refused - connect(2)"))
357
+ stub = stub_request(:put, url).with(body: post_data.to_xml).to_raise(Faraday::ConnectionFailed.new("Connection refused - connect(2)"))
349
358
  subject.put(url, accept: "xml", data: post_data.to_xml) { |response| expect(response.body).to be_nil }
350
359
  expect(stub).to have_been_requested
351
360
  end
@@ -353,40 +362,40 @@ describe Maremma do
353
362
 
354
363
  context "unauthorized" do
355
364
  it "get json" do
356
- stub = stub_request(:get, url).to_raise(Faraday::Error::ClientError.new("the server responded with status 401"))
365
+ stub = stub_request(:get, url).to_raise(Faraday::ClientError.new("the server responded with status 401"))
357
366
  response = subject.get(url)
358
- expect(response.body).to eq("errors"=>[{"status"=>401, "title"=>"Unauthorized"}])
367
+ expect(response.body).to eq("errors" => [{ "status" => 401, "title" => "Unauthorized" }])
359
368
  expect(stub).to have_been_requested
360
369
  end
361
370
 
362
371
  it "get xml" do
363
- stub = stub_request(:get, url).to_raise(Faraday::Error::ClientError.new("the server responded with status 401"))
372
+ stub = stub_request(:get, url).to_raise(Faraday::ClientError.new("the server responded with status 401"))
364
373
  response = subject.get(url, accept: "xml")
365
- expect(response.body).to eq("errors"=>[{"status"=>401, "title"=>"Unauthorized"}])
374
+ expect(response.body).to eq("errors" => [{ "status" => 401, "title" => "Unauthorized" }])
366
375
  expect(stub).to have_been_requested
367
376
  end
368
377
 
369
378
  it "get html" do
370
- stub = stub_request(:get, url).to_raise(Faraday::Error::ClientError.new("the server responded with status 401"))
379
+ stub = stub_request(:get, url).to_raise(Faraday::ClientError.new("the server responded with status 401"))
371
380
  response = subject.get(url, accept: "html")
372
- expect(response.body).to eq("errors"=>[{"status"=>401, "title"=>"Unauthorized"}])
381
+ expect(response.body).to eq("errors" => [{ "status" => 401, "title" => "Unauthorized" }])
373
382
  expect(stub).to have_been_requested
374
383
  end
375
384
 
376
385
  it "post xml" do
377
- stub = stub_request(:post, url).with(:body => post_data.to_xml).to_raise(Faraday::Error::ClientError.new("the server responded with status 401"))
386
+ stub = stub_request(:post, url).with(body: post_data.to_xml).to_raise(Faraday::ClientError.new("the server responded with status 401"))
378
387
  subject.post(url, accept: "xml", data: post_data.to_xml) do |response|
379
388
  expect(response.body).to be_nil
380
- expect(response.status).to eq("errors"=>[{"status"=>401, "title"=>"Unauthorized"}])
389
+ expect(response.status).to eq("errors" => [{ "status" => 401, "title" => "Unauthorized" }])
381
390
  end
382
391
  expect(stub).to have_been_requested
383
392
  end
384
393
 
385
394
  it "put xml" do
386
- stub = stub_request(:put, url).with(:body => post_data.to_xml).to_raise(Faraday::Error::ClientError.new("the server responded with status 401"))
395
+ stub = stub_request(:put, url).with(body: post_data.to_xml).to_raise(Faraday::ClientError.new("the server responded with status 401"))
387
396
  subject.put(url, accept: "xml", data: post_data.to_xml) do |response|
388
397
  expect(response.body).to be_nil
389
- expect(response.status).to eq("errors"=>[{"status"=>401, "title"=>"Unauthorized"}])
398
+ expect(response.status).to eq("errors" => [{ "status" => 401, "title" => "Unauthorized" }])
390
399
  end
391
400
  expect(stub).to have_been_requested
392
401
  end
@@ -396,32 +405,32 @@ describe Maremma do
396
405
  it "get json" do
397
406
  stub = stub_request(:get, url).to_timeout
398
407
  response = subject.get(url)
399
- expect(response.body).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
408
+ expect(response.body).to eq("errors" => [{ "status" => 408, "title" => "Request timeout" }])
400
409
  expect(stub).to have_been_requested
401
410
  end
402
411
 
403
412
  it "get xml" do
404
413
  stub = stub_request(:get, url).to_timeout
405
414
  response = subject.get(url, accept: "xml")
406
- expect(response.body).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
415
+ expect(response.body).to eq("errors" => [{ "status" => 408, "title" => "Request timeout" }])
407
416
  expect(stub).to have_been_requested
408
417
  end
409
418
 
410
419
  it "get html" do
411
420
  stub = stub_request(:get, url).to_timeout
412
421
  response = subject.get(url, accept: "html")
413
- expect(response.body).to eq("errors"=>[{"status"=>408, "title"=>"Request timeout"}])
422
+ expect(response.body).to eq("errors" => [{ "status" => 408, "title" => "Request timeout" }])
414
423
  expect(stub).to have_been_requested
415
424
  end
416
425
 
417
426
  it "post xml" do
418
- stub = stub_request(:post, url).with(:body => post_data.to_xml).to_timeout
427
+ stub = stub_request(:post, url).with(body: post_data.to_xml).to_timeout
419
428
  subject.post(url, accept: "xml", data: post_data.to_xml) { |response| expect(response.body).to be_nil }
420
429
  expect(stub).to have_been_requested
421
430
  end
422
431
 
423
432
  it "put xml" do
424
- stub = stub_request(:put, url).with(:body => post_data.to_xml).to_timeout
433
+ stub = stub_request(:put, url).with(body: post_data.to_xml).to_timeout
425
434
  subject.put(url, accept: "xml", data: post_data.to_xml) { |response| expect(response.body).to be_nil }
426
435
  expect(stub).to have_been_requested
427
436
  end
@@ -431,34 +440,34 @@ describe Maremma do
431
440
  it "get json" do
432
441
  stub = stub_request(:get, url).to_return(status: 200, headers: { "X-Rate-Limit-Remaining" => 2 })
433
442
  response = subject.get(url)
434
- expect(response.body).to eq("errors"=>[{"status"=>429, "title"=>"Too many requests"}])
443
+ expect(response.body).to eq("errors" => [{ "status" => 429, "title" => "Too many requests" }])
435
444
  expect(stub).to have_been_requested
436
445
  end
437
446
 
438
447
  it "get xml" do
439
448
  stub = stub_request(:get, url).to_return(status: 200, headers: { "X-Rate-Limit-Remaining" => 2 })
440
449
  response = subject.get(url, accept: "xml")
441
- expect(response.body).to eq("errors"=>[{"status"=>429, "title"=>"Too many requests"}])
450
+ expect(response.body).to eq("errors" => [{ "status" => 429, "title" => "Too many requests" }])
442
451
  expect(stub).to have_been_requested
443
452
  end
444
453
 
445
454
  it "get html" do
446
455
  stub = stub_request(:get, url).to_return(status: 200, headers: { "X-Rate-Limit-Remaining" => 2 })
447
456
  response = subject.get(url, accept: "html")
448
- expect(response.body).to eq("errors"=>[{"status"=>429, "title"=>"Too many requests"}])
457
+ expect(response.body).to eq("errors" => [{ "status" => 429, "title" => "Too many requests" }])
449
458
  expect(stub).to have_been_requested
450
459
  end
451
460
 
452
461
  it "post xml" do
453
- stub = stub_request(:post, url).with(:body => post_data.to_xml)
454
- .to_return(status: 200, headers: { "X-Rate-Limit-Remaining" => 3 })
462
+ stub = stub_request(:post, url).with(body: post_data.to_xml).
463
+ to_return(status: 200, headers: { "X-Rate-Limit-Remaining" => 3 })
455
464
  subject.post(url, accept: "xml", data: post_data.to_xml) { |response| expect(response.body).to be_nil }
456
465
  expect(stub).to have_been_requested
457
466
  end
458
467
 
459
468
  it "put xml" do
460
- stub = stub_request(:put, url).with(:body => post_data.to_xml)
461
- .to_return(status: 200, headers: { "X-Rate-Limit-Remaining" => 3 })
469
+ stub = stub_request(:put, url).with(body: post_data.to_xml).
470
+ to_return(status: 200, headers: { "X-Rate-Limit-Remaining" => 3 })
462
471
  subject.put(url, accept: "xml", data: post_data.to_xml) { |response| expect(response.body).to be_nil }
463
472
  expect(stub).to have_been_requested
464
473
  end
@@ -471,26 +480,26 @@ describe Maremma do
471
480
  stub_request(:get, url).to_return(status: 301, headers: { location: redirect_url })
472
481
  stub_request(:get, redirect_url).to_return(status: 200, body: "Test")
473
482
  response = subject.get(url)
474
- expect(response.body).to eq("data"=>"Test")
483
+ expect(response.body).to eq("data" => "Test")
475
484
  expect(response.url).to eq("http://www.example.org/redirect")
476
485
  end
477
486
 
478
487
  it "redirect four times" do
479
488
  stub_request(:get, url).to_return(status: 301, headers: { location: redirect_url })
480
489
  stub_request(:get, redirect_url).to_return(status: 301, headers: { location: redirect_url + "/x" })
481
- stub_request(:get, redirect_url+ "/x").to_return(status: 301, headers: { location: redirect_url + "/y" })
482
- stub_request(:get, redirect_url+ "/y").to_return(status: 301, headers: { location: redirect_url + "/z" })
490
+ stub_request(:get, redirect_url + "/x").to_return(status: 301, headers: { location: redirect_url + "/y" })
491
+ stub_request(:get, redirect_url + "/y").to_return(status: 301, headers: { location: redirect_url + "/z" })
483
492
  stub_request(:get, redirect_url + "/z").to_return(status: 200, body: "Test")
484
493
  response = subject.get(url)
485
- expect(response.body).to eq("data"=>"Test")
494
+ expect(response.body).to eq("data" => "Test")
486
495
  end
487
496
 
488
497
  it "redirect limit 1" do
489
498
  stub_request(:get, url).to_return(status: 301, headers: { location: redirect_url })
490
499
  stub_request(:get, redirect_url).to_return(status: 301, headers: { location: redirect_url + "/x" })
491
- stub_request(:get, redirect_url+ "/x").to_return(status: 301, headers: { location: redirect_url + "/y" })
500
+ stub_request(:get, redirect_url + "/x").to_return(status: 301, headers: { location: redirect_url + "/y" })
492
501
  response = subject.get(url, limit: 1)
493
- expect(response.body).to eq("errors"=>[{"status"=>400, "title"=>"too many redirects; last one to: http://www.example.org/redirect/x"}])
502
+ expect(response.body).to eq("errors" => [{ "status" => 400, "title" => "too many redirects; last one to: http://www.example.org/redirect/x" }])
494
503
  end
495
504
 
496
505
  it "redirect limit 0" do
@@ -553,7 +562,7 @@ describe Maremma do
553
562
 
554
563
  it "json not error" do
555
564
  string = "{ \"customError\": \"An error occured.\" }"
556
- expect(subject.parse_error_response(string)).to eq("customError"=>"An error occured.")
565
+ expect(subject.parse_error_response(string)).to eq("customError" => "An error occured.")
557
566
  end
558
567
 
559
568
  it "xml" do
@@ -565,27 +574,27 @@ describe Maremma do
565
574
  context "parse_success_response" do
566
575
  it "from_json" do
567
576
  string = "{ \"word\": \"abc\" }"
568
- expect(subject.parse_success_response(string)).to eq({ "data" => { "word"=>"abc" }})
577
+ expect(subject.parse_success_response(string)).to eq("data" => { "word" => "abc" })
569
578
  end
570
579
 
571
580
  it "from_json with data" do
572
581
  string = "{ \"data\": { \"word\": \"abc\" }}"
573
- expect(subject.parse_success_response(string)).to eq({"data"=>{"word"=>"abc"}})
582
+ expect(subject.parse_success_response(string)).to eq("data" => { "word" => "abc" })
574
583
  end
575
584
 
576
585
  it "from_json with data and meta" do
577
586
  string = "{ \"data\": { \"word\": \"abc\" }, \"meta\": { \"total\": 12 }}"
578
- expect(subject.parse_success_response(string)).to eq({"data"=>{"word"=>"abc"},"meta"=>{"total"=>12}})
587
+ expect(subject.parse_success_response(string)).to eq("data" => { "word" => "abc" }, "meta" => { "total" => 12 })
579
588
  end
580
589
 
581
590
  it "from_xml" do
582
591
  string = "<word>abc</word>"
583
- expect(subject.parse_success_response(string)).to eq("data"=>{"word"=>"abc"})
592
+ expect(subject.parse_success_response(string)).to eq("data" => { "word" => "abc" })
584
593
  end
585
594
 
586
595
  it "from_xml with attribute" do
587
596
  string = "<word type='small'>abc</word>"
588
- expect(subject.parse_success_response(string)).to eq("data"=>{"word"=>{"type"=>"small", "__content__"=>"abc"}})
597
+ expect(subject.parse_success_response(string)).to eq("data" => { "word" => { "type" => "small", "__content__" => "abc" } })
589
598
  end
590
599
 
591
600
  # it "from_xml with allowed content attributes" do
@@ -595,22 +604,22 @@ describe Maremma do
595
604
 
596
605
  it "from_xml with attribute type string" do
597
606
  string = "<crm-item name='publisher-name' type='string'>eLife Sciences Publications, Ltd</crm-item>"
598
- expect(subject.parse_success_response(string)).to eq("data"=>{"crm_item"=>"eLife Sciences Publications, Ltd"})
607
+ expect(subject.parse_success_response(string)).to eq("data" => { "crm_item" => "eLife Sciences Publications, Ltd" })
599
608
  end
600
609
 
601
610
  it "from_xml with mixed attribute" do
602
611
  string = "<word type='small'>abc<footnote>1</footnote></word>"
603
- expect(subject.parse_success_response(string)).to eq("data"=>{"word"=>{"type"=>"small", "footnote"=>"1", "__content__"=>"abc"}})
612
+ expect(subject.parse_success_response(string)).to eq("data" => { "word" => { "type" => "small", "footnote" => "1", "__content__" => "abc" } })
604
613
  end
605
614
 
606
615
  it "from_string" do
607
616
  string = "abc"
608
- expect(subject.parse_success_response(string)).to eq("data"=>"abc")
617
+ expect(subject.parse_success_response(string)).to eq("data" => "abc")
609
618
  end
610
619
 
611
620
  it "from_string with utf-8" do
612
621
  string = "fön "
613
- expect(subject.parse_success_response(string)).to eq("data"=>"fön")
622
+ expect(subject.parse_success_response(string)).to eq("data" => "fön")
614
623
  end
615
624
  end
616
625
 
@@ -664,7 +673,7 @@ describe Maremma do
664
673
 
665
674
  it "github_token" do
666
675
  options = { github_token: "12345" }
667
- expect(subject.set_request_headers(url, options)).to eq("User-Agent"=>"Mozilla/5.0 (compatible; Maremma/#{Maremma::VERSION}; +https://github.com/datacite/maremma)", "Accept"=>accept_header, "Authorization"=>"Token 12345")
676
+ expect(subject.set_request_headers(url, options)).to eq("User-Agent" => "Mozilla/5.0 (compatible; Maremma/#{Maremma::VERSION}; +https://github.com/datacite/maremma)", "Accept" => accept_header, "Authorization" => "Token 12345")
668
677
  end
669
678
 
670
679
  it "basic" do
@@ -688,7 +697,7 @@ describe Maremma do
688
697
  expect(response.status).to eq(200)
689
698
  doc = Nokogiri::XML(response.body.fetch("data", nil), nil, "UTF-8")
690
699
  nodeset = doc.css("script")
691
- string = nodeset.find { |element| element["type"] == "application/ld+json" }
700
+ string = nodeset.detect { |element| element["type"] == "application/ld+json" }
692
701
  json = JSON.parse(string)
693
702
  expect(json["@id"]).to eq("https://doi.org/10.3334/ORNLDAAC/1339")
694
703
  end
@@ -699,10 +708,10 @@ describe Maremma do
699
708
  expect(response.status).to eq(200)
700
709
  doc = Nokogiri::XML(response.body.fetch("data", nil), nil, "UTF-8")
701
710
  nodeset = doc.css("script")
702
- string = nodeset.find { |element| element["type"] == "application/ld+json" }
711
+ string = nodeset.detect { |element| element["type"] == "application/ld+json" }
703
712
  json = JSON.parse(string)
704
713
  expect(json["@id"]).to eq("https://doi.org/10.3334/ORNLDAAC/1339")
705
- end
714
+ end
706
715
  end
707
716
 
708
717
  context "ssl verify", vcr: true do
@@ -714,7 +723,7 @@ describe Maremma do
714
723
 
715
724
  it "self-signed" do
716
725
  url = "https://38.100.138.135:8000/api/handles/10.5281/ZENODO.21430?index=1"
717
- options = { ssl_self_signed: true}
726
+ options = { ssl_self_signed: true }
718
727
  response = subject.get(url, options)
719
728
  expect(response.status).to eq(200)
720
729
  expect(response.body.dig("data", "values", 0, "data", "value")).to eq("https://zenodo.org/record/21430")