maremma 4.7.2 → 4.9.3

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