restful_resource 2.5.3 → 2.6.1

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: 4e46af8066f1ca4d4e59dae90cd6283676f65e146ed62ab56c506eeafb189b95
4
- data.tar.gz: fdbb7277f080e8c00ff73e5b01f26954d67dd04189456a4500276b0a435b8a41
3
+ metadata.gz: 015747ee95ac4e52617a009da36dcccb671aa6f8437662287f9dadf951f2049e
4
+ data.tar.gz: c27835d8a584d1d5c228725892ceca06cb215cbdee088d7c2b6884228371aab1
5
5
  SHA512:
6
- metadata.gz: 2039984d78d5131c8a88cb45fd7cc65a2626b2d2bee7977642ce10d84fd19f8d158ef7a7202f07e36dbf5ba4404cbf772f2f56f0f92497d1571f60f052dcfc68
7
- data.tar.gz: c382b0c2d0f1f4901a990ef771104d0350536e6bd773bed632dcfc74d4f090577044b255bf49544fc2939ff9848d60efdbd020d0f55d16f6bb1db5e70e06eb8a
6
+ metadata.gz: 9d987975b117009d80e0179663ab643a24d055220b01f149be44d12024968732166ec9a589d9517f27150630a8794b0e2557b8fe72ff332be8a3472dab74deb6
7
+ data.tar.gz: 1cebc647b6ddfca2d0fee0ab9bb9d32ef1820f3d06d613a7417b38f9c28617569bfcfe3f6dac7fe71eff47c8c8b7041876cbc54a90fb6d78438e39ae720cac13
data/.circleci/config.yml CHANGED
@@ -7,7 +7,9 @@ jobs:
7
7
  - checkout
8
8
  - run:
9
9
  name: Bundle Install
10
- command: bundle check || bundle install
10
+ command: |
11
+ gem install bundler && \
12
+ bundle check || bundle install
11
13
  - run:
12
14
  name: Run rspec in parallel
13
15
  command: |
@@ -18,3 +20,10 @@ jobs:
18
20
  $(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
19
21
  - store_test_results:
20
22
  path: test_results
23
+
24
+
25
+ workflows:
26
+ version: 2
27
+ build:
28
+ jobs:
29
+ - build
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
data/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ 2.6.1
4
+ ---
5
+ - Support only `faraday-0.15.x`
6
+ - `0.16.x` breaks `faraday-http-cache`
7
+
8
+ 2.6.0 (yanked)
9
+ ---
10
+
11
+ - Upgrade to `faraday-0.16.x`
12
+ - Add `X-Client-Timeout` header on requests if a client timeout is set
13
+
14
+ 2.5.3
15
+ ---
16
+
17
+ - Raise `RestfulResource::HttpClient::GatewayTimeout` when response status is `504`
18
+
19
+
20
+ 2.5.2
21
+ ---
22
+
23
+ - Add ability to set `timeout` and `open_timeout` options on connection
24
+
3
25
  2.5.1
4
26
  ---
5
27
 
data/Gemfile.lock ADDED
@@ -0,0 +1,113 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ restful_resource (2.6.1)
5
+ activesupport
6
+ faraday (~> 0.15.0)
7
+ faraday-cdn-metrics
8
+ faraday-encoding
9
+ faraday-http-cache
10
+ faraday_middleware
11
+ link_header
12
+ rack
13
+ typhoeus
14
+
15
+ GEM
16
+ remote: https://rubygems.org/
17
+ specs:
18
+ activesupport (6.0.0)
19
+ concurrent-ruby (~> 1.0, >= 1.0.2)
20
+ i18n (>= 0.7, < 2)
21
+ minitest (~> 5.1)
22
+ tzinfo (~> 1.1)
23
+ zeitwerk (~> 2.1, >= 2.1.8)
24
+ ast (2.4.0)
25
+ carwow_rubocop (3.0.3)
26
+ rubocop (>= 0.68)
27
+ rubocop-performance
28
+ rubocop-rspec
29
+ coderay (1.1.2)
30
+ concurrent-ruby (1.1.5)
31
+ diff-lcs (1.3)
32
+ ethon (0.12.0)
33
+ ffi (>= 1.3.0)
34
+ faraday (0.15.4)
35
+ multipart-post (>= 1.2, < 3)
36
+ faraday-cdn-metrics (0.1.0)
37
+ faraday (~> 0.11)
38
+ faraday-encoding (0.0.5)
39
+ faraday
40
+ faraday-http-cache (2.0.0)
41
+ faraday (~> 0.8)
42
+ faraday_middleware (0.13.1)
43
+ faraday (>= 0.7.4, < 1.0)
44
+ ffi (1.11.1)
45
+ i18n (1.6.0)
46
+ concurrent-ruby (~> 1.0)
47
+ jaro_winkler (1.5.3)
48
+ link_header (0.0.8)
49
+ method_source (0.9.2)
50
+ minitest (5.12.2)
51
+ multipart-post (2.1.1)
52
+ parallel (1.17.0)
53
+ parser (2.6.3.0)
54
+ ast (~> 2.4.0)
55
+ pry (0.12.2)
56
+ coderay (~> 1.1.0)
57
+ method_source (~> 0.9.0)
58
+ rack (2.0.7)
59
+ rainbow (3.0.0)
60
+ rake (12.3.3)
61
+ rspec (3.8.0)
62
+ rspec-core (~> 3.8.0)
63
+ rspec-expectations (~> 3.8.0)
64
+ rspec-mocks (~> 3.8.0)
65
+ rspec-core (3.8.2)
66
+ rspec-support (~> 3.8.0)
67
+ rspec-expectations (3.8.4)
68
+ diff-lcs (>= 1.2.0, < 2.0)
69
+ rspec-support (~> 3.8.0)
70
+ rspec-its (1.3.0)
71
+ rspec-core (>= 3.0.0)
72
+ rspec-expectations (>= 3.0.0)
73
+ rspec-mocks (3.8.1)
74
+ diff-lcs (>= 1.2.0, < 2.0)
75
+ rspec-support (~> 3.8.0)
76
+ rspec-support (3.8.2)
77
+ rspec_junit_formatter (0.4.1)
78
+ rspec-core (>= 2, < 4, != 2.12.0)
79
+ rubocop (0.73.0)
80
+ jaro_winkler (~> 1.5.1)
81
+ parallel (~> 1.10)
82
+ parser (>= 2.6)
83
+ rainbow (>= 2.2.2, < 4.0)
84
+ ruby-progressbar (~> 1.7)
85
+ unicode-display_width (>= 1.4.0, < 1.7)
86
+ rubocop-performance (1.4.1)
87
+ rubocop (>= 0.71.0)
88
+ rubocop-rspec (1.34.1)
89
+ rubocop (>= 0.60.0)
90
+ ruby-progressbar (1.10.1)
91
+ thread_safe (0.3.6)
92
+ typhoeus (1.3.1)
93
+ ethon (>= 0.9.0)
94
+ tzinfo (1.2.5)
95
+ thread_safe (~> 0.1)
96
+ unicode-display_width (1.6.0)
97
+ zeitwerk (2.1.10)
98
+
99
+ PLATFORMS
100
+ ruby
101
+
102
+ DEPENDENCIES
103
+ bundler
104
+ carwow_rubocop
105
+ pry
106
+ rake
107
+ restful_resource!
108
+ rspec
109
+ rspec-its
110
+ rspec_junit_formatter
111
+
112
+ BUNDLED WITH
113
+ 2.0.2
@@ -12,7 +12,7 @@ module RestfulResource
12
12
  timeout: nil,
13
13
  open_timeout: nil,
14
14
  faraday_config: nil,
15
- faraday_options: nil)
15
+ faraday_options: {})
16
16
 
17
17
  @base_url = URI.parse(base_url)
18
18
 
@@ -88,7 +88,7 @@ module RestfulResource
88
88
  timeout: nil,
89
89
  open_timeout: nil,
90
90
  faraday_config: nil,
91
- faraday_options: nil)
91
+ faraday_options: {})
92
92
  api_name = instrumentation[:api_name] ||= 'api'
93
93
  instrumentation[:request_instrument_name] ||= "http.#{api_name}"
94
94
  instrumentation[:cache_instrument_name] ||= "http_cache.#{api_name}"
@@ -202,7 +202,7 @@ module RestfulResource
202
202
  cache_instrument_name: nil,
203
203
  server_cache_instrument_name: nil,
204
204
  faraday_config: nil,
205
- faraday_options: nil)
205
+ faraday_options: {})
206
206
 
207
207
  @connection = Faraday.new(nil, faraday_options) do |b|
208
208
  b.request :json
@@ -253,6 +253,7 @@ module RestfulResource
253
253
  req.url request.url
254
254
 
255
255
  req.headers = req.headers.merge(request.headers)
256
+ req.headers = req.headers.merge(x_client_timeout: req.options[:timeout]) if req.options[:timeout]
256
257
  end
257
258
 
258
259
  Response.new(body: response.body, headers: response.headers, status: response.status)
@@ -264,6 +265,12 @@ module RestfulResource
264
265
  response = e.response
265
266
  raise ClientError, request unless response
266
267
 
268
+ handle_error(request, response)
269
+ rescue Faraday::ServerError => e
270
+ handle_error(request, e.response)
271
+ end
272
+
273
+ def handle_error(request, response)
267
274
  case response[:status]
268
275
  when 404 then raise HttpClient::ResourceNotFound.new(request, response)
269
276
  when 409 then raise HttpClient::Conflict.new(request, response)
@@ -1,3 +1,3 @@
1
1
  module RestfulResource
2
- VERSION = '2.5.3'.freeze
2
+ VERSION = '2.6.1'.freeze
3
3
  end
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'rspec-its'
27
27
 
28
28
  spec.add_dependency 'activesupport'
29
- spec.add_dependency 'faraday'
29
+ spec.add_dependency 'faraday', '~> 0.15.0'
30
30
  spec.add_dependency 'faraday-cdn-metrics'
31
31
  spec.add_dependency 'faraday-encoding'
32
32
  spec.add_dependency 'faraday-http-cache'
@@ -2,12 +2,8 @@ require_relative '../spec_helper'
2
2
 
3
3
  describe RestfulResource::Base, 'authorization' do
4
4
  before do
5
- class FirstClient < RestfulResource::Base
6
- end
7
-
8
- class SecondClient < RestfulResource::Base
9
- end
10
-
5
+ class FirstClient < RestfulResource::Base; end
6
+ class SecondClient < RestfulResource::Base; end
11
7
  class NotConfiguredClient < RestfulResource::Base; end
12
8
 
13
9
  class FirstTest < FirstClient
@@ -3,8 +3,10 @@ require_relative '../spec_helper'
3
3
  RSpec.describe RestfulResource::Base do
4
4
  before do
5
5
  @mock_http = double('mock_http')
6
- allow(described_class).to receive(:http).and_return(@mock_http)
7
- described_class.configure(base_url: 'http://api.carwow.co.uk/')
6
+ allow(Make).to receive(:http).and_return(@mock_http)
7
+ Make.configure(base_url: 'http://api.carwow.co.uk/')
8
+ allow(Model).to receive(:http).and_return(@mock_http)
9
+ Model.configure(base_url: 'http://api.carwow.co.uk/')
8
10
  end
9
11
 
10
12
  it 'acts as an openobject' do
@@ -143,9 +145,14 @@ RSpec.describe RestfulResource::Base do
143
145
  end
144
146
 
145
147
  describe '#base_url' do
148
+ before do
149
+ @mock_http = double('mock_http')
150
+ allow(TestA).to receive(:http).and_return(@mock_http)
151
+ allow(TestB).to receive(:http).and_return(@mock_http)
152
+ end
153
+
146
154
  it 'is different for each subclass of Base' do
147
155
  BaseA.configure(base_url: 'http://a.carwow.co.uk')
148
-
149
156
  BaseB.configure(base_url: 'http://b.carwow.co.uk')
150
157
 
151
158
  expect_get('http://a.carwow.co.uk/testa/1', RestfulResource::Response.new)
@@ -385,6 +392,7 @@ RSpec.describe RestfulResource::Base do
385
392
  let(:faraday_options) { double }
386
393
 
387
394
  it 'passes arguments to HttpClient' do
395
+ client = Class.new(described_class)
388
396
  expect(RestfulResource::HttpClient).to receive(:new).with(username: username,
389
397
  password: password,
390
398
  auth_token: auth_token,
@@ -397,7 +405,7 @@ RSpec.describe RestfulResource::Base do
397
405
  faraday_options: faraday_options
398
406
  )
399
407
 
400
- described_class.configure(base_url: 'http://foo.bar',
408
+ client.configure(base_url: 'http://foo.bar',
401
409
  username: username,
402
410
  password: password,
403
411
  auth_token: auth_token,
@@ -1,8 +1,8 @@
1
1
  require_relative '../spec_helper'
2
2
 
3
3
  RSpec.describe RestfulResource::HttpClient do
4
- def faraday_connection
5
- Faraday.new do |builder|
4
+ def faraday_connection(opts = {})
5
+ Faraday.new(opts) do |builder|
6
6
  builder.request :url_encoded
7
7
  builder.response :raise_error
8
8
  builder.adapter :test do |stubs|
@@ -292,4 +292,50 @@ RSpec.describe RestfulResource::HttpClient do
292
292
  expect(response.status).to eq 200
293
293
  end
294
294
  end
295
+
296
+ describe 'X-Client-Timeout' do
297
+ let(:http_client) { described_class.new(connection: connection, timeout: timeout) }
298
+ let(:connection) do
299
+ conn = faraday_connection do |stubs|
300
+ stubs.get('http://httpbin.org/get', required_headers) { |_env| [200, {}, nil] }
301
+ end
302
+
303
+ conn.options[:timeout] = timeout
304
+
305
+ conn
306
+ end
307
+
308
+
309
+ context 'when explicit timeout set on connection' do
310
+ let(:timeout) { 5 }
311
+ let(:required_headers) { { 'X-Client-Timeout' => 5 } }
312
+ it 'sets X-Client-Timeout correctly' do
313
+ response = http_client.get('http://httpbin.org/get')
314
+
315
+ expect(response.status).to eq 200
316
+ end
317
+ end
318
+
319
+ context 'when not explicit timeout set' do
320
+ let(:timeout) { nil }
321
+ let(:required_headers) { {} }
322
+
323
+ it 'sets X-Client-Timeout correctly' do
324
+ response = http_client.get('http://httpbin.org/get')
325
+
326
+ expect(response.status).to eq 200
327
+ end
328
+ end
329
+
330
+ context 'when set on request' do
331
+ let(:timeout) { nil }
332
+ let(:required_headers) { { 'X-Client-Timeout' => 1 } }
333
+
334
+ it 'sets X-Client-Timeout correctly' do
335
+ response = http_client.get('http://httpbin.org/get', timeout: 1)
336
+
337
+ expect(response.status).to eq 200
338
+ end
339
+ end
340
+ end
295
341
  end
@@ -3,8 +3,8 @@ require_relative '../spec_helper'
3
3
  RSpec.describe RestfulResource::RailsValidations do
4
4
  before do
5
5
  @mock_http = double('mock_http')
6
- RestfulResource::Base.configure(base_url: 'http://api.carwow.co.uk/')
7
- allow(RestfulResource::Base).to receive(:http).and_return(@mock_http)
6
+ Dealer.configure(base_url: 'http://api.carwow.co.uk/')
7
+ allow(Dealer).to receive(:http).and_return(@mock_http)
8
8
  end
9
9
 
10
10
  context '#patch without errors' do
@@ -3,8 +3,8 @@ require_relative '../spec_helper'
3
3
  RSpec.describe RestfulResource::Redirections do
4
4
  before do
5
5
  @mock_http = double('mock_http')
6
- allow(RestfulResource::Base).to receive(:http).and_return(@mock_http)
7
- RestfulResource::Base.configure(base_url: 'http://api.carwow.co.uk/')
6
+ allow(ModelWithRedirections).to receive(:http).and_return(@mock_http)
7
+ ModelWithRedirections.configure(base_url: 'http://api.carwow.co.uk/')
8
8
  end
9
9
 
10
10
  describe '#post' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: restful_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.3
4
+ version: 2.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Santoro
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-09-11 00:00:00.000000000 Z
12
+ date: 2019-10-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -113,16 +113,16 @@ dependencies:
113
113
  name: faraday
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - ">="
116
+ - - "~>"
117
117
  - !ruby/object:Gem::Version
118
- version: '0'
118
+ version: 0.15.0
119
119
  type: :runtime
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - ">="
123
+ - - "~>"
124
124
  - !ruby/object:Gem::Version
125
- version: '0'
125
+ version: 0.15.0
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: faraday-cdn-metrics
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -237,6 +237,7 @@ files:
237
237
  - ".rubocop_todo.yml"
238
238
  - CHANGELOG.md
239
239
  - Gemfile
240
+ - Gemfile.lock
240
241
  - LICENSE.txt
241
242
  - README.md
242
243
  - Rakefile