restful_resource 2.13.3 → 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: f578b915d89258f07c42764c2145d2c2d312a5c433150b8ffc9aaf0928ac9afd
4
- data.tar.gz: 474ee1332121730907f668e7f27f8e9eedd68c97039a5460be734bf8eaf32611
3
+ metadata.gz: 9f2c32b411aee9609b0df3982688270ef55fe0ba8f8e15c472f6ec16d5562104
4
+ data.tar.gz: 71978eaef61ece9aba34fecf03268d83fb1e6d24c81cd4922eebcecc683f2431
5
5
  SHA512:
6
- metadata.gz: 200b5161e691223658fdc487251f1136b13a099c7bc59fef225080455c40d720239d6a6924b3935edc5bcf9aa42e8668d71983955aa04c1e8e049879f170e5db
7
- data.tar.gz: e28af4d1460c452b0a51d966e3899a0ded290dc79177d85b320d94a22b4d61a88a2a1acae1b5179021bba6c6f925b0c8d3923875a9fdbcbf8a60335dbc8f4239
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
- def assign_response(response = nil)
15
- @response = if response
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
@@ -1,3 +1,3 @@
1
1
  module RestfulResource
2
- VERSION = '2.13.3'.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.3
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: 2022-11-01 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