network-client 2.0.1 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +9 -0
- data/.ruby-version +1 -1
- data/.travis.yml +14 -5
- data/Gemfile.lock +42 -40
- data/README.md +16 -25
- data/lib/network/client.rb +12 -2
- data/lib/network/version.rb +1 -1
- data/network-client.gemspec +5 -5
- metadata +19 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bcefe9135ac3d265c22e2c9b2e241a3841f7bc75dc61c24b505e43b7d69e3171
|
4
|
+
data.tar.gz: 89b76915e7c3ef5d5d2274ef8fbb01a4bad64cb86c2c7f33f211dd66873b72ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f35222a252a1d94ca76fd0cb4c7e2368915f0ef053106bb005a23385d734d328ac1c8121bf99696a69d83ba497fdd29841de34115a6af969a29b8b2a4b84bc6
|
7
|
+
data.tar.gz: 9973132d65b81708625d1bec0b1e3dcb107e332829b302e0b0982c51e6e35f21cf29f784226e6a4f2024e59451ace08d970fb665807a4008f56c8c65f346f2fb
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.5.5
|
data/.travis.yml
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
sudo: false
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
|
-
- 2.
|
5
|
-
- 2.
|
6
|
-
- 2.
|
7
|
-
-
|
4
|
+
- 2.5.0
|
5
|
+
- 2.6.0
|
6
|
+
- 2.7.0
|
7
|
+
- 3.0.0
|
8
|
+
before_install: gem install bundler -v 2.2.24
|
9
|
+
install: bundle install --jobs=3 --retry=3
|
8
10
|
cache: bundler
|
9
|
-
|
11
|
+
before_script:
|
12
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
13
|
+
- chmod +x ./cc-test-reporter
|
14
|
+
- ./cc-test-reporter before-build
|
15
|
+
script:
|
16
|
+
- bundle exec rspec
|
17
|
+
after_script:
|
18
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/Gemfile.lock
CHANGED
@@ -1,62 +1,64 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
network-client (2.0.
|
4
|
+
network-client (2.0.4)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
activesupport (
|
9
|
+
activesupport (6.1.4)
|
10
10
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
11
|
-
i18n (
|
12
|
-
minitest (
|
13
|
-
tzinfo (~>
|
11
|
+
i18n (>= 1.6, < 2)
|
12
|
+
minitest (>= 5.1)
|
13
|
+
tzinfo (~> 2.0)
|
14
|
+
zeitwerk (~> 2.3)
|
14
15
|
codeclimate-test-reporter (1.0.7)
|
15
16
|
simplecov
|
16
|
-
concurrent-ruby (1.
|
17
|
-
diff-lcs (1.
|
18
|
-
docile (1.
|
19
|
-
dotenv (2.
|
20
|
-
|
21
|
-
activesupport (>=
|
22
|
-
i18n (
|
23
|
-
|
24
|
-
minitest (5.
|
25
|
-
rake (
|
26
|
-
rspec (3.
|
27
|
-
rspec-core (~> 3.
|
28
|
-
rspec-expectations (~> 3.
|
29
|
-
rspec-mocks (~> 3.
|
30
|
-
rspec-core (3.
|
31
|
-
rspec-support (~> 3.
|
32
|
-
rspec-expectations (3.
|
17
|
+
concurrent-ruby (1.1.9)
|
18
|
+
diff-lcs (1.4.4)
|
19
|
+
docile (1.4.0)
|
20
|
+
dotenv (2.7.6)
|
21
|
+
factory_bot (6.2.0)
|
22
|
+
activesupport (>= 5.0.0)
|
23
|
+
i18n (1.8.10)
|
24
|
+
concurrent-ruby (~> 1.0)
|
25
|
+
minitest (5.14.4)
|
26
|
+
rake (13.0.6)
|
27
|
+
rspec (3.10.0)
|
28
|
+
rspec-core (~> 3.10.0)
|
29
|
+
rspec-expectations (~> 3.10.0)
|
30
|
+
rspec-mocks (~> 3.10.0)
|
31
|
+
rspec-core (3.10.1)
|
32
|
+
rspec-support (~> 3.10.0)
|
33
|
+
rspec-expectations (3.10.1)
|
33
34
|
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
-
rspec-support (~> 3.
|
35
|
-
rspec-mocks (3.
|
35
|
+
rspec-support (~> 3.10.0)
|
36
|
+
rspec-mocks (3.10.2)
|
36
37
|
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
-
rspec-support (~> 3.
|
38
|
-
rspec-support (3.
|
39
|
-
simplecov (0.
|
40
|
-
docile (~> 1.1
|
41
|
-
|
42
|
-
|
43
|
-
simplecov-html (0.
|
44
|
-
|
45
|
-
tzinfo (
|
46
|
-
|
38
|
+
rspec-support (~> 3.10.0)
|
39
|
+
rspec-support (3.10.2)
|
40
|
+
simplecov (0.21.2)
|
41
|
+
docile (~> 1.1)
|
42
|
+
simplecov-html (~> 0.11)
|
43
|
+
simplecov_json_formatter (~> 0.1)
|
44
|
+
simplecov-html (0.12.3)
|
45
|
+
simplecov_json_formatter (0.1.3)
|
46
|
+
tzinfo (2.0.4)
|
47
|
+
concurrent-ruby (~> 1.0)
|
48
|
+
zeitwerk (2.4.2)
|
47
49
|
|
48
50
|
PLATFORMS
|
49
51
|
ruby
|
50
52
|
|
51
53
|
DEPENDENCIES
|
52
|
-
bundler (~>
|
54
|
+
bundler (~> 2.2.20)
|
53
55
|
codeclimate-test-reporter (~> 1.0)
|
54
|
-
dotenv (~> 2.
|
55
|
-
|
56
|
+
dotenv (~> 2.7)
|
57
|
+
factory_bot (~> 6.2)
|
56
58
|
network-client!
|
57
|
-
rake (~>
|
59
|
+
rake (~> 13.0)
|
58
60
|
rspec (~> 3.6)
|
59
|
-
simplecov (~> 0.
|
61
|
+
simplecov (~> 0.21)
|
60
62
|
|
61
63
|
BUNDLED WITH
|
62
|
-
|
64
|
+
2.2.24
|
data/README.md
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/network-client.svg)](https://rubygems.org/gems/network-client)
|
4
4
|
[![Gem](https://img.shields.io/gem/dt/network-client.svg?colorB=8b0000)](https://rubygems.org/gems/network-client)
|
5
|
-
[![Build Status](https://travis-ci.
|
6
|
-
[![Dependency Status](https://gemnasium.com/badges/github.com/abarrak/network-client.svg)](https://gemnasium.com/github.com/abarrak/network-client)
|
5
|
+
[![Build Status](https://www.travis-ci.com/abarrak/network-client.svg?branch=master)](https://www.travis-ci.com/abarrak/network-client)
|
7
6
|
[![Test Coverage](https://codeclimate.com/github/abarrak/network-client/badges/coverage.svg)](https://codeclimate.com/github/abarrak/network-client/coverage)
|
8
7
|
[![Code Climate](https://lima.codeclimate.com/github/abarrak/network-client/badges/gpa.svg)](https://lima.codeclimate.com/github/abarrak/network-client)
|
9
8
|
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
@@ -46,8 +45,7 @@ We can perform the following requests:
|
|
46
45
|
```ruby
|
47
46
|
client.get '/todos/10'
|
48
47
|
|
49
|
-
#=> #<struct Network::Client::Response code=200,
|
50
|
-
body={"userId"=>1, "id"=>10, "title"=>"illo est ...", "completed"=>true}>
|
48
|
+
#=> #<struct Network::Client::Response code=200, body={"userId"=>1, "id"=>10, "title"=>"illo est ...", "completed"=>true}>
|
51
49
|
```
|
52
50
|
|
53
51
|
* **POST**
|
@@ -55,8 +53,7 @@ We can perform the following requests:
|
|
55
53
|
```ruby
|
56
54
|
client.post '/todos', params: { title: 'foo bar', completed: 'false', userId: 1 }.to_json
|
57
55
|
|
58
|
-
#=> #<struct Network::Client::Response code=201,
|
59
|
-
body={"title"=>"foo bar", "completed"=>false, "userId"=>1, "id"=>201}>
|
56
|
+
#=> #<struct Network::Client::Response code=201, body={"title"=>"foo bar", "completed"=>false, "userId"=>1, "id"=>201}>
|
60
57
|
```
|
61
58
|
|
62
59
|
* **PATCH**
|
@@ -64,8 +61,7 @@ We can perform the following requests:
|
|
64
61
|
```ruby
|
65
62
|
client.patch '/todos/10', params: { title: 'new title' }.to_json
|
66
63
|
|
67
|
-
#=> #<struct Network::Client::Response code=200,
|
68
|
-
body={"userId"=>1, "id"=>10, "title"=>"new title", "completed"=>true}>
|
64
|
+
#=> #<struct Network::Client::Response code=200, body={"userId"=>1, "id"=>10, "title"=>"new title", "completed"=>true}>
|
69
65
|
```
|
70
66
|
|
71
67
|
* **PUT**
|
@@ -91,9 +87,8 @@ It holds the response's HTTP code and body parsed as JSON.
|
|
91
87
|
|
92
88
|
```ruby
|
93
89
|
response = client.get '/posts/30'
|
94
|
-
response.code
|
95
|
-
response.body
|
96
|
-
"body"=>"alias dolor cumque ..." }
|
90
|
+
response.code #=> 200
|
91
|
+
response.body #=> { "userId"=>3, "id"=>30, "title"=>"a quo magni similique perferendis", "body"=>"alias dolor cumque ..." }
|
97
92
|
```
|
98
93
|
|
99
94
|
#### Setting Request Headers
|
@@ -121,20 +116,20 @@ client.get 'posts/', headers: { 'X-SPECIAL-KEY' => '123456' }
|
|
121
116
|
client = Network::Client.new(endpoint: 'https://api.example.com',
|
122
117
|
username: 'ABC',
|
123
118
|
password: '999')
|
124
|
-
client.username
|
125
|
-
client.password
|
119
|
+
client.username #=> "ABC"
|
120
|
+
client.password #=> "999"
|
126
121
|
|
127
122
|
# or via `#set_basic_auth`:
|
128
123
|
|
129
124
|
client.set_basic_auth('John Doe', '112233')
|
130
|
-
client.username
|
131
|
-
client.password
|
125
|
+
client.username #=> "John Doe"
|
126
|
+
client.password #=> "112233"
|
132
127
|
```
|
133
128
|
|
134
129
|
2. **OAuth Bearer:**
|
135
130
|
```ruby
|
136
131
|
client.set_bearer_auth(token: 'e08f7739c3abb78c')
|
137
|
-
client.bearer_token
|
132
|
+
client.bearer_token
|
138
133
|
#=> "e08f7739c3abb78c"
|
139
134
|
```
|
140
135
|
|
@@ -150,14 +145,14 @@ You can set the user agent header during initialization:
|
|
150
145
|
|
151
146
|
```ruby
|
152
147
|
client = Network::Client.new(endpoint: 'https://maps.googleapis.com', user_agent: 'App Service')
|
153
|
-
client.user_agent
|
148
|
+
client.user_agent #=> "App Service"
|
154
149
|
```
|
155
150
|
|
156
151
|
Or later on via `#set_user_agent` method:
|
157
152
|
|
158
153
|
```ruby
|
159
154
|
client.set_user_agent('Gateway Server')
|
160
|
-
client.user_agent
|
155
|
+
client.user_agent #=> "Gateway Server"
|
161
156
|
```
|
162
157
|
|
163
158
|
The default user agent is `Network Client`.
|
@@ -167,7 +162,7 @@ Set the `tries:` named argument to define the number of tries when request fails
|
|
167
162
|
|
168
163
|
```ruby
|
169
164
|
client = Network::Client.new(endpoint: 'https://api.foursquare.com', tries: 3)
|
170
|
-
client.tries
|
165
|
+
client.tries #=> 3
|
171
166
|
```
|
172
167
|
|
173
168
|
The default `#tries` is 2.
|
@@ -177,15 +172,11 @@ To retrieve or extend the list of triable errors through `#errors_to_recover`:
|
|
177
172
|
```ruby
|
178
173
|
client.errors_to_recover
|
179
174
|
|
180
|
-
#=> [Net::HTTPTooManyRequests, Net::HTTPServerError, Net::ProtocolError,
|
181
|
-
Net::HTTPBadResponse,Net::ReadTimeout, Net::OpenTimeout, Errno::ECONNREFUSED,
|
182
|
-
Errno::ETIMEDOUT, OpenSSL::SSL::SSLError, SocketError]
|
175
|
+
#=> [Net::HTTPTooManyRequests, Net::HTTPServerError, Net::ProtocolError, Net::HTTPBadResponse,Net::ReadTimeout, Net::OpenTimeout, Errno::ECONNREFUSED, Errno::ETIMEDOUT, OpenSSL::SSL::SSLError, SocketError]
|
183
176
|
|
184
177
|
client.errors_to_recover << Net::HTTPRequestTimeOut
|
185
178
|
|
186
|
-
#=> [Net::HTTPTooManyRequests, Net::HTTPServerError, Net::ProtocolError,
|
187
|
-
Net::HTTPBadResponse,Net::ReadTimeout, Net::OpenTimeout, Errno::ECONNREFUSED,
|
188
|
-
Errno::ETIMEDOUT, OpenSSL::SSL::SSLError, SocketError, Net::HTTPRequestTimeOut]
|
179
|
+
#=> [Net::HTTPTooManyRequests, Net::HTTPServerError, Net::ProtocolError, Net::HTTPBadResponse,Net::ReadTimeout, Net::OpenTimeout, Errno::ECONNREFUSED, Errno::ETIMEDOUT, OpenSSL::SSL::SSLError, SocketError, Net::HTTPRequestTimeOut]
|
189
180
|
```
|
190
181
|
|
191
182
|
The list of `errors_to_propagate` takes precedence over `errors_to_recover`, and they are not retried.
|
data/lib/network/client.rb
CHANGED
@@ -32,6 +32,9 @@ module Network
|
|
32
32
|
# Do not assign ancestor error classes here that prevent retry for descendant ones.
|
33
33
|
attr_accessor :errors_to_propagate
|
34
34
|
|
35
|
+
# Gives access to underlying NET::HTTP client instance.
|
36
|
+
attr_accessor :http
|
37
|
+
|
35
38
|
##
|
36
39
|
# Construct and prepare client for requests targeting +endpoint+.
|
37
40
|
#
|
@@ -240,10 +243,17 @@ module Network
|
|
240
243
|
Net::OpenTimeout,
|
241
244
|
Errno::ECONNREFUSED,
|
242
245
|
Errno::ETIMEDOUT,
|
246
|
+
Errno::ECONNRESET,
|
247
|
+
Errno::EHOSTUNREACH,
|
248
|
+
Timeout::Error,
|
243
249
|
OpenSSL::SSL::SSLError,
|
244
|
-
|
250
|
+
EOFError,
|
251
|
+
SocketError,
|
252
|
+
IOError]
|
245
253
|
@errors_to_propagate = [Net::HTTPRequestURITooLarge,
|
246
|
-
Net::HTTPMethodNotAllowed
|
254
|
+
Net::HTTPMethodNotAllowed,
|
255
|
+
Zlib::BufError,
|
256
|
+
OpenSSL::X509::CertificateError]
|
247
257
|
end
|
248
258
|
|
249
259
|
def request_json(http_method, path, params, headers)
|
data/lib/network/version.rb
CHANGED
data/network-client.gemspec
CHANGED
@@ -24,11 +24,11 @@ Gem::Specification.new do |spec|
|
|
24
24
|
|
25
25
|
spec.require_paths = %w(lib)
|
26
26
|
|
27
|
-
spec.add_development_dependency "bundler", "~>
|
28
|
-
spec.add_development_dependency "rake", "~>
|
27
|
+
spec.add_development_dependency "bundler", "~> 2.2.20"
|
28
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
29
29
|
spec.add_development_dependency "rspec", "~> 3.6"
|
30
|
-
spec.add_development_dependency "
|
31
|
-
spec.add_development_dependency "simplecov", "~> 0.
|
30
|
+
spec.add_development_dependency "factory_bot", "~> 6.2"
|
31
|
+
spec.add_development_dependency "simplecov", "~> 0.21"
|
32
32
|
spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0"
|
33
|
-
spec.add_development_dependency "dotenv", "~> 2.
|
33
|
+
spec.add_development_dependency "dotenv", "~> 2.7"
|
34
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: network-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abdullah Barrak (abarrak)
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.2.20
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.2.20
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '13.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '13.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -53,33 +53,33 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.6'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: factory_bot
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '6.2'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '6.2'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: '0.21'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: '0.21'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: codeclimate-test-reporter
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '2.
|
103
|
+
version: '2.7'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '2.
|
110
|
+
version: '2.7'
|
111
111
|
description: network-client is a drop-in thin layer on top of Net::HTTP classes for JSON
|
112
112
|
web requests with retry functionality and simple error handling
|
113
113
|
email:
|
@@ -116,6 +116,7 @@ executables: []
|
|
116
116
|
extensions: []
|
117
117
|
extra_rdoc_files: []
|
118
118
|
files:
|
119
|
+
- ".github/dependabot.yml"
|
119
120
|
- ".gitignore"
|
120
121
|
- ".rspec"
|
121
122
|
- ".ruby-gemset"
|
@@ -134,7 +135,7 @@ homepage: https://github.com/abarrak/network-client
|
|
134
135
|
licenses:
|
135
136
|
- MIT
|
136
137
|
metadata: {}
|
137
|
-
post_install_message:
|
138
|
+
post_install_message:
|
138
139
|
rdoc_options: []
|
139
140
|
require_paths:
|
140
141
|
- lib
|
@@ -149,9 +150,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
150
|
- !ruby/object:Gem::Version
|
150
151
|
version: '0'
|
151
152
|
requirements: []
|
152
|
-
rubyforge_project:
|
153
|
-
rubygems_version: 2.6.
|
154
|
-
signing_key:
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.7.6.2
|
155
|
+
signing_key:
|
155
156
|
specification_version: 4
|
156
157
|
summary: A thin resilient JSON web client built around Net::HTTP
|
157
158
|
test_files: []
|