restful_resource 2.13.3 → 2.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/restful_resource/base.rb +5 -2
- data/lib/restful_resource/http_client.rb +11 -3
- data/lib/restful_resource/version.rb +1 -1
- data/spec/restful_resource/base_spec.rb +29 -24
- data/spec/restful_resource/http_client_spec.rb +12 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f2c32b411aee9609b0df3982688270ef55fe0ba8f8e15c472f6ec16d5562104
|
4
|
+
data.tar.gz: 71978eaef61ece9aba34fecf03268d83fb1e6d24c81cd4922eebcecc683f2431
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06e10e1280f1d428c879366832f6ec9d74105a9c77c958e82734ffb41f01b1590544023f385f69b148bbc9c57577c58493c65d97e901d2eba30cbb292380e769
|
7
|
+
data.tar.gz: 04a45aca352e95e2ef502ae084c1546f828a833bacbc18fb6a3ee053689aefad8b2cce6d79b891c4cc6ed4e30b0b4faf8c2238f6791700c0d88d38b48ab91fc1
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,14 @@
|
|
1
1
|
# Changelog
|
2
|
+
2.14
|
3
|
+
---
|
4
|
+
|
5
|
+
- Added support for default headers when configuring a `RestfulResource::Base`
|
6
|
+
|
7
|
+
2.13.4
|
8
|
+
---
|
9
|
+
|
10
|
+
- Support passing a an instance of `RestfulResource::Response` to the constructor for a `RestfulResource::HttpClient::HttpError`
|
11
|
+
|
2
12
|
2.13.3
|
3
13
|
---
|
4
14
|
|
@@ -12,7 +12,9 @@ module RestfulResource
|
|
12
12
|
timeout: nil,
|
13
13
|
open_timeout: nil,
|
14
14
|
faraday_config: nil,
|
15
|
-
faraday_options: {}
|
15
|
+
faraday_options: {},
|
16
|
+
default_headers: {}
|
17
|
+
)
|
16
18
|
|
17
19
|
@base_url = URI.parse(base_url)
|
18
20
|
|
@@ -25,7 +27,8 @@ module RestfulResource
|
|
25
27
|
open_timeout: open_timeout,
|
26
28
|
instrumentation: instrumentation,
|
27
29
|
faraday_config: faraday_config,
|
28
|
-
faraday_options: faraday_options
|
30
|
+
faraday_options: faraday_options,
|
31
|
+
default_headers: default_headers
|
29
32
|
)
|
30
33
|
end
|
31
34
|
|
@@ -11,8 +11,12 @@ module RestfulResource
|
|
11
11
|
@response = assign_response(response)
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
|
14
|
+
private
|
15
|
+
|
16
|
+
def assign_response(response)
|
17
|
+
@response = if response.is_a?(Response)
|
18
|
+
response
|
19
|
+
elsif response
|
16
20
|
Response.new(body: response[:body], headers: response[:headers], status: response[:status])
|
17
21
|
else
|
18
22
|
Response.new
|
@@ -88,7 +92,9 @@ module RestfulResource
|
|
88
92
|
timeout: nil,
|
89
93
|
open_timeout: nil,
|
90
94
|
faraday_config: nil,
|
91
|
-
faraday_options: {}
|
95
|
+
faraday_options: {},
|
96
|
+
default_headers: {}
|
97
|
+
)
|
92
98
|
api_name = instrumentation[:api_name] ||= 'api'
|
93
99
|
instrumentation[:request_instrument_name] ||= "http.#{api_name}"
|
94
100
|
instrumentation[:cache_instrument_name] ||= "http_cache.#{api_name}"
|
@@ -119,6 +125,8 @@ module RestfulResource
|
|
119
125
|
faraday_options: faraday_options
|
120
126
|
)
|
121
127
|
|
128
|
+
@connection.headers.merge!(default_headers)
|
129
|
+
|
122
130
|
if auth_token
|
123
131
|
@connection.headers[:authorization] = "Bearer #{auth_token}"
|
124
132
|
elsif username && password
|
@@ -390,33 +390,38 @@ RSpec.describe RestfulResource::Base do
|
|
390
390
|
let(:open_timeout) { double }
|
391
391
|
let(:faraday_config) { double }
|
392
392
|
let(:faraday_options) { double }
|
393
|
+
let(:default_headers) { double }
|
393
394
|
|
394
395
|
it 'passes arguments to HttpClient' do
|
395
396
|
client = Class.new(described_class)
|
396
|
-
expect(RestfulResource::HttpClient).to receive(:new).with(
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
397
|
+
expect(RestfulResource::HttpClient).to receive(:new).with(
|
398
|
+
username: username,
|
399
|
+
password: password,
|
400
|
+
auth_token: auth_token,
|
401
|
+
logger: logger,
|
402
|
+
cache_store: cache_store,
|
403
|
+
instrumentation: instrumentation,
|
404
|
+
timeout: timeout,
|
405
|
+
open_timeout: open_timeout,
|
406
|
+
faraday_config: faraday_config,
|
407
|
+
faraday_options: faraday_options,
|
408
|
+
default_headers: default_headers
|
409
|
+
)
|
410
|
+
|
411
|
+
client.configure(
|
412
|
+
base_url: 'http://foo.bar',
|
413
|
+
username: username,
|
414
|
+
password: password,
|
415
|
+
auth_token: auth_token,
|
416
|
+
logger: logger,
|
417
|
+
cache_store: cache_store,
|
418
|
+
instrumentation: instrumentation,
|
419
|
+
timeout: timeout,
|
420
|
+
open_timeout: open_timeout,
|
421
|
+
faraday_config: faraday_config,
|
422
|
+
faraday_options: faraday_options,
|
423
|
+
default_headers: default_headers
|
424
|
+
)
|
420
425
|
end
|
421
426
|
end
|
422
427
|
|
@@ -271,4 +271,16 @@ RSpec.describe RestfulResource::HttpClient do
|
|
271
271
|
expect(response.status).to eq 200
|
272
272
|
end
|
273
273
|
end
|
274
|
+
|
275
|
+
describe 'default headers' do
|
276
|
+
it 'uses default headers' do
|
277
|
+
connection = faraday_connection do |stubs|
|
278
|
+
stubs.get('http://httpbin.org/get', 'Foo' => 'bar') { |_env| [200, {}, nil] }
|
279
|
+
end
|
280
|
+
|
281
|
+
response = described_class.new(connection: connection, default_headers: { foo: 'bar' }).get('http://httpbin.org/get')
|
282
|
+
|
283
|
+
expect(response.status).to eq 200
|
284
|
+
end
|
285
|
+
end
|
274
286
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: restful_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.14.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Santoro
|
8
8
|
- Federico Rebora
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2023-09-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -297,7 +297,7 @@ homepage: http://www.github.com/carwow/restful_resource
|
|
297
297
|
licenses:
|
298
298
|
- MIT
|
299
299
|
metadata: {}
|
300
|
-
post_install_message:
|
300
|
+
post_install_message:
|
301
301
|
rdoc_options: []
|
302
302
|
require_paths:
|
303
303
|
- lib
|
@@ -313,7 +313,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
313
313
|
version: '0'
|
314
314
|
requirements: []
|
315
315
|
rubygems_version: 3.1.6
|
316
|
-
signing_key:
|
316
|
+
signing_key:
|
317
317
|
specification_version: 4
|
318
318
|
summary: A simple activerecord inspired rest resource base class implemented using
|
319
319
|
rest-client
|