restful_resource 2.13.4 → 2.14.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 811b916cd8a44f9a8c94185176a2a99e55719dbe7320c8772efb856a5fb17229
4
- data.tar.gz: '08eec998987cefdee15d7816c5b3ee801d9a7f0e5f5f609d5ee5fade7ad6ee7b'
3
+ metadata.gz: 9f2c32b411aee9609b0df3982688270ef55fe0ba8f8e15c472f6ec16d5562104
4
+ data.tar.gz: 71978eaef61ece9aba34fecf03268d83fb1e6d24c81cd4922eebcecc683f2431
5
5
  SHA512:
6
- metadata.gz: 6a1bc2e111f392ec4d50a41225b1534b1a6f19bc36d730cbad3047b793624fc0022d9d293be7578ed9886eceb90ed744a94daa7b4239cd68ed83fefe78f982c5
7
- data.tar.gz: 84684eba6db73549f8b116d7637e2502b7a6721214c10bc1aab4c0adff1a6aca6755a104efb57ea11f9ed7195502aa9177a3b9bd83c8f04f51083e2155ce86dd
6
+ metadata.gz: 06e10e1280f1d428c879366832f6ec9d74105a9c77c958e82734ffb41f01b1590544023f385f69b148bbc9c57577c58493c65d97e901d2eba30cbb292380e769
7
+ data.tar.gz: 04a45aca352e95e2ef502ae084c1546f828a833bacbc18fb6a3ee053689aefad8b2cce6d79b891c4cc6ed4e30b0b4faf8c2238f6791700c0d88d38b48ab91fc1
data/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
1
  # Changelog
2
+ 2.14
3
+ ---
4
+
5
+ - Added support for default headers when configuring a `RestfulResource::Base`
6
+
2
7
  2.13.4
3
8
  ---
4
9
 
@@ -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
 
@@ -92,7 +92,9 @@ module RestfulResource
92
92
  timeout: nil,
93
93
  open_timeout: nil,
94
94
  faraday_config: nil,
95
- faraday_options: {})
95
+ faraday_options: {},
96
+ default_headers: {}
97
+ )
96
98
  api_name = instrumentation[:api_name] ||= 'api'
97
99
  instrumentation[:request_instrument_name] ||= "http.#{api_name}"
98
100
  instrumentation[:cache_instrument_name] ||= "http_cache.#{api_name}"
@@ -123,6 +125,8 @@ module RestfulResource
123
125
  faraday_options: faraday_options
124
126
  )
125
127
 
128
+ @connection.headers.merge!(default_headers)
129
+
126
130
  if auth_token
127
131
  @connection.headers[:authorization] = "Bearer #{auth_token}"
128
132
  elsif username && password
@@ -1,3 +1,3 @@
1
1
  module RestfulResource
2
- VERSION = '2.13.4'.freeze
2
+ VERSION = '2.14.0'.freeze
3
3
  end
@@ -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(username: username,
397
- password: password,
398
- auth_token: auth_token,
399
- logger: logger,
400
- cache_store: cache_store,
401
- instrumentation: instrumentation,
402
- timeout: timeout,
403
- open_timeout: open_timeout,
404
- faraday_config: faraday_config,
405
- faraday_options: faraday_options
406
- )
407
-
408
- client.configure(base_url: 'http://foo.bar',
409
- username: username,
410
- password: password,
411
- auth_token: auth_token,
412
- logger: logger,
413
- cache_store: cache_store,
414
- instrumentation: instrumentation,
415
- timeout: timeout,
416
- open_timeout: open_timeout,
417
- faraday_config: faraday_config,
418
- faraday_options: faraday_options
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.13.4
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: 2023-03-02 00:00:00.000000000 Z
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