nxt_http_client 1.0.1 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +2 -2
- data/.ruby-version +1 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +40 -39
- data/README.md +32 -29
- data/lib/nxt_http_client/error.rb +1 -2
- data/lib/nxt_http_client/fire_callbacks.rb +5 -0
- data/lib/nxt_http_client/version.rb +1 -1
- data/nxt_http_client.gemspec +4 -5
- metadata +23 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f15083d70472500d85d5b14313db955407d41c0381253824df06d7b62408be81
|
4
|
+
data.tar.gz: c8eac41c1f068d3cfb2892eadda053deb928e8bb1595cade76549d53e72db677
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: edaeb82434e63eaebe71ddfc93d029d91e468d800dc21b42825136e483ef4353f229df48737eb59f373bea51f5365c8d3ba6faea553b93ac4b4fa4f2eed5c376
|
7
|
+
data.tar.gz: 141abc01af4c33257773c42e4d8f6ca82e59034e9ecdbd49adf837b395d0c345bbc493e0e718f2c779d1befeea4057c0ef9a1b5913315a25419349aeec1a8319
|
data/.circleci/config.yml
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.4
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
# v1.0.4 2022-06-08
|
2
|
+
- Fix bug where callbacks were shared between unrelated child client class ([#130](https://github.com/nxt-insurance/nxt_http_client/pull/130))
|
3
|
+
|
4
|
+
# v1.0.3 2022-02-08
|
5
|
+
|
6
|
+
- Relax dependency version constraints, allow activesupport < 8
|
7
|
+
|
8
|
+
# v1.0.2 2021-02-17
|
9
|
+
|
10
|
+
### Update NxtHttpClient::Error
|
11
|
+
- delegate timed_out? and status_message to response
|
12
|
+
|
1
13
|
# v1.0.1 2021-02-04
|
2
14
|
|
3
15
|
### Update NxtRegistry
|
data/Gemfile.lock
CHANGED
@@ -1,89 +1,90 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nxt_http_client (1.0.
|
5
|
-
activesupport (
|
4
|
+
nxt_http_client (1.0.4)
|
5
|
+
activesupport (< 8.0)
|
6
6
|
nxt_registry
|
7
7
|
typhoeus
|
8
8
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (
|
12
|
+
activesupport (7.0.3)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
14
|
i18n (>= 1.6, < 2)
|
15
15
|
minitest (>= 5.1)
|
16
16
|
tzinfo (~> 2.0)
|
17
|
-
|
18
|
-
addressable (2.7.0)
|
17
|
+
addressable (2.8.0)
|
19
18
|
public_suffix (>= 2.0.2, < 5.0)
|
20
19
|
coderay (1.1.3)
|
21
|
-
concurrent-ruby (1.1.
|
20
|
+
concurrent-ruby (1.1.10)
|
22
21
|
crack (0.4.5)
|
23
22
|
rexml
|
24
|
-
diff-lcs (1.
|
25
|
-
ethon (0.
|
26
|
-
ffi (>= 1.
|
27
|
-
ffi (1.
|
23
|
+
diff-lcs (1.5.0)
|
24
|
+
ethon (0.15.0)
|
25
|
+
ffi (>= 1.15.0)
|
26
|
+
ffi (1.15.5)
|
28
27
|
hashdiff (1.0.1)
|
29
|
-
i18n (1.
|
28
|
+
i18n (1.10.0)
|
30
29
|
concurrent-ruby (~> 1.0)
|
31
30
|
method_source (1.0.0)
|
32
|
-
minitest (5.
|
33
|
-
nxt_registry (0.3.
|
31
|
+
minitest (5.15.0)
|
32
|
+
nxt_registry (0.3.10)
|
34
33
|
activesupport
|
35
34
|
nxt_vcr_harness (0.1.4)
|
36
35
|
rspec (~> 3.0)
|
37
36
|
vcr (~> 6.0)
|
38
|
-
pry (0.
|
37
|
+
pry (0.14.1)
|
39
38
|
coderay (~> 1.1)
|
40
39
|
method_source (~> 1.0)
|
41
|
-
public_suffix (4.0.
|
42
|
-
rake (13.0.
|
43
|
-
redis (4.
|
44
|
-
rexml (3.2.
|
45
|
-
rspec (3.
|
46
|
-
rspec-core (~> 3.
|
47
|
-
rspec-expectations (~> 3.
|
48
|
-
rspec-mocks (~> 3.
|
49
|
-
rspec-core (3.
|
50
|
-
rspec-support (~> 3.
|
51
|
-
rspec-expectations (3.
|
40
|
+
public_suffix (4.0.7)
|
41
|
+
rake (13.0.6)
|
42
|
+
redis (4.6.0)
|
43
|
+
rexml (3.2.5)
|
44
|
+
rspec (3.11.0)
|
45
|
+
rspec-core (~> 3.11.0)
|
46
|
+
rspec-expectations (~> 3.11.0)
|
47
|
+
rspec-mocks (~> 3.11.0)
|
48
|
+
rspec-core (3.11.0)
|
49
|
+
rspec-support (~> 3.11.0)
|
50
|
+
rspec-expectations (3.11.0)
|
52
51
|
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
-
rspec-support (~> 3.
|
54
|
-
rspec-mocks (3.
|
52
|
+
rspec-support (~> 3.11.0)
|
53
|
+
rspec-mocks (3.11.1)
|
55
54
|
diff-lcs (>= 1.2.0, < 2.0)
|
56
|
-
rspec-support (~> 3.
|
57
|
-
rspec-support (3.
|
58
|
-
rspec_junit_formatter (0.
|
55
|
+
rspec-support (~> 3.11.0)
|
56
|
+
rspec-support (3.11.0)
|
57
|
+
rspec_junit_formatter (0.5.1)
|
59
58
|
rspec-core (>= 2, < 4, != 2.12.0)
|
60
|
-
timecop (0.9.
|
59
|
+
timecop (0.9.5)
|
61
60
|
typhoeus (1.4.0)
|
62
61
|
ethon (>= 0.9.0)
|
63
62
|
tzinfo (2.0.4)
|
64
63
|
concurrent-ruby (~> 1.0)
|
65
|
-
vcr (6.
|
66
|
-
webmock (3.
|
67
|
-
addressable (>= 2.
|
64
|
+
vcr (6.1.0)
|
65
|
+
webmock (3.14.0)
|
66
|
+
addressable (>= 2.8.0)
|
68
67
|
crack (>= 0.3.2)
|
69
68
|
hashdiff (>= 0.4.0, < 2.0.0)
|
70
|
-
zeitwerk (2.4.2)
|
71
69
|
|
72
70
|
PLATFORMS
|
71
|
+
ruby
|
73
72
|
x86_64-darwin-19
|
73
|
+
x86_64-darwin-20
|
74
|
+
x86_64-linux
|
74
75
|
|
75
76
|
DEPENDENCIES
|
76
|
-
bundler
|
77
|
+
bundler
|
77
78
|
nxt_http_client!
|
78
79
|
nxt_vcr_harness
|
79
80
|
pry
|
80
|
-
rake
|
81
|
+
rake
|
81
82
|
redis
|
82
|
-
rspec
|
83
|
+
rspec
|
83
84
|
rspec_junit_formatter
|
84
85
|
timecop
|
85
86
|
vcr
|
86
87
|
webmock
|
87
88
|
|
88
89
|
BUNDLED WITH
|
89
|
-
2.
|
90
|
+
2.3.6
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# NxtHttpClient
|
2
2
|
|
3
3
|
Build http clients with ease. NxtHttpClient is a simple DSL on top of the [typhoeus](https://github.com/typhoeus/typhoeus)
|
4
|
-
gem. NxtHttpClient mostly provides you a simple configuration functionality to setup http connections on the class level.
|
4
|
+
gem. NxtHttpClient mostly provides you a simple configuration functionality to setup http connections on the class level.
|
5
5
|
Furthermore it's mostly a callback framework that allows you to seamlessly handle your responses. Since it's is just a simple
|
6
|
-
layer on top of [typhoeus](https://github.com/typhoeus/typhoeus) it also allows to access and configure the original
|
6
|
+
layer on top of [typhoeus](https://github.com/typhoeus/typhoeus) it also allows to access and configure the original
|
7
7
|
`Typhoeus::Request` before making a request.
|
8
8
|
|
9
9
|
|
@@ -40,14 +40,14 @@ class UserFetcher < Client
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
private
|
45
45
|
|
46
46
|
attr_reader :url
|
47
47
|
end
|
48
48
|
```
|
49
49
|
|
50
|
-
In order to setup a shared configuration you would therefore setup a client base class. The configuration and any
|
50
|
+
In order to setup a shared configuration you would therefore setup a client base class. The configuration and any
|
51
51
|
response handler or callbacks you setup in your base class are then inherited to your concrete client implementations.
|
52
52
|
|
53
53
|
```ruby
|
@@ -59,13 +59,13 @@ class Client < NxtHttpClient
|
|
59
59
|
method: :get,
|
60
60
|
followlocation: true
|
61
61
|
)
|
62
|
-
config.x_request_id_proc = -> { ('a'..'z').to_a.shuffle.take(10).join }
|
62
|
+
config.x_request_id_proc = -> { ('a'..'z').to_a.shuffle.take(10).join }
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
log do |info|
|
66
66
|
Rails.logger.info(info)
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
response_handler do |handler|
|
70
70
|
handler.on(:error) do |response|
|
71
71
|
Raven.extra_context(error_details: error.to_h)
|
@@ -77,7 +77,7 @@ end
|
|
77
77
|
|
78
78
|
### HTTP Methods
|
79
79
|
|
80
|
-
In order to build a request and execute it NxtHttpClient implements all http standard methods.
|
80
|
+
In order to build a request and execute it NxtHttpClient implements all http standard methods.
|
81
81
|
|
82
82
|
```ruby
|
83
83
|
class Client < NxtHttpClient
|
@@ -111,20 +111,20 @@ end
|
|
111
111
|
|
112
112
|
### configure
|
113
113
|
|
114
|
-
Register your default request options on the class level. Available options are `request_options` that are passed
|
114
|
+
Register your default request options on the class level. Available options are `request_options` that are passed
|
115
115
|
directly to the underlying Typhoeus Request. Then there is `base_url` and `x_request_id_proc`.
|
116
116
|
|
117
117
|
### response_handler
|
118
118
|
|
119
|
-
Register a default response handler for your client class. You can reconfigure or overwrite this in subclasses and
|
120
|
-
on the instance level.
|
119
|
+
Register a default response handler for your client class. You can reconfigure or overwrite this in subclasses and
|
120
|
+
on the instance level.
|
121
121
|
|
122
122
|
### fire
|
123
123
|
|
124
|
-
All http methods internally are delegate to `fire('uri', **request_options)`. Since `fire` is a public method you can
|
124
|
+
All http methods internally are delegate to `fire('uri', **request_options)`. Since `fire` is a public method you can
|
125
125
|
also use it to fire your requests and use the response handler to register callbacks for specific responses.
|
126
126
|
|
127
|
-
Registered callbacks have a hierarchy by which they are executed. Specific callbacks will come first
|
127
|
+
Registered callbacks have a hierarchy by which they are executed. Specific callbacks will come first
|
128
128
|
and more common callbacks will come later in case none of the specific callbacks matched. It this is not what you want you
|
129
129
|
can simply put the logic you need into one common callback that is called in any case. You can also use strings with wildcards
|
130
130
|
to match a group of response by status code. `handler.on('4**') { ... }` basically would match all client errors.
|
@@ -138,33 +138,33 @@ fire('uri', **request_options) do |handler|
|
|
138
138
|
handler.on(:success) do |response|
|
139
139
|
response.body
|
140
140
|
end
|
141
|
-
|
141
|
+
|
142
142
|
handler.on(:timed_out) do |response|
|
143
143
|
raise StandardError, 'Timeout'
|
144
144
|
end
|
145
|
-
|
145
|
+
|
146
146
|
handler.on(:error) do |response|
|
147
147
|
raise StandardError, 'This is bad'
|
148
148
|
end
|
149
|
-
|
149
|
+
|
150
150
|
handler.on(:others) do |response|
|
151
151
|
raise StandardError, 'Other problem'
|
152
152
|
end
|
153
|
-
|
153
|
+
|
154
154
|
handler.on(:headers) do |response|
|
155
155
|
# This is already executed when the headers are received
|
156
156
|
end
|
157
|
-
|
157
|
+
|
158
158
|
handler.on(:body) do |chunk|
|
159
|
-
# Use this to stream the body in chunks
|
159
|
+
# Use this to stream the body in chunks
|
160
160
|
end
|
161
161
|
end
|
162
|
-
```
|
162
|
+
```
|
163
163
|
|
164
164
|
### Callbacks around fire
|
165
165
|
|
166
|
-
Next to implementing callbacks for handling responses there are also callbacks around making requests. Note tht you can
|
167
|
-
have as many callbacks as you want. In case you need to reset them because you do not want to inherit them from your
|
166
|
+
Next to implementing callbacks for handling responses there are also callbacks around making requests. Note tht you can
|
167
|
+
have as many callbacks as you want. In case you need to reset them because you do not want to inherit them from your
|
168
168
|
parent class (might be a smell when you need to...) you can reset callbacks via `clear_fire_callbacks` on the class level.
|
169
169
|
|
170
170
|
```ruby
|
@@ -190,9 +190,12 @@ end
|
|
190
190
|
|
191
191
|
NxtHttpClient also provides an error base class that you might want to use as the base for your client errors.
|
192
192
|
It comes with a nice set of useful methods. You can ask the error for the request and response options since it
|
193
|
-
requires the response for initialization. Furthermore it has a handy `to_h` method that provides you all info about
|
193
|
+
requires the response for initialization. Furthermore it has a handy `to_h` method that provides you all info about
|
194
194
|
the request and response.
|
195
195
|
|
196
|
+
#### Timeouts
|
197
|
+
NxtHttpClient::Error exposes the `timed_out?` method from `Typhoeus::Response`, so you can check if an error is raised due to a timeout. This is useful when setting a custom timeout value in your configuration.
|
198
|
+
|
196
199
|
### Logging
|
197
200
|
|
198
201
|
NxtHttpClient also comes with a log method on the class level that you can pass a proc if you want to log your request.
|
@@ -218,23 +221,23 @@ end
|
|
218
221
|
|
219
222
|
### Caching
|
220
223
|
|
221
|
-
Typhoeus ships with caching built in. Checkout the [typhoeus](https://github.com/typhoeus/typhoeus) docu to figure out
|
222
|
-
how to set it up. NxtHttpClient builds some functionality on top of this and offer to cache requests within the current
|
223
|
-
thread or globally. You can simply make use of it by providing one of the caching options `:thread` or`:global` as config
|
224
|
-
request option or the actual request options when building the request.
|
224
|
+
Typhoeus ships with caching built in. Checkout the [typhoeus](https://github.com/typhoeus/typhoeus) docu to figure out
|
225
|
+
how to set it up. NxtHttpClient builds some functionality on top of this and offer to cache requests within the current
|
226
|
+
thread or globally. You can simply make use of it by providing one of the caching options `:thread` or`:global` as config
|
227
|
+
request option or the actual request options when building the request.
|
225
228
|
|
226
229
|
```ruby
|
227
230
|
class Client < NxtHttpClient::Client
|
228
231
|
configure do |config|
|
229
232
|
config.request_options = { cache: :thread }
|
230
233
|
end
|
231
|
-
|
234
|
+
|
232
235
|
response_handler do |handler|
|
233
236
|
handler.on(200) do |response|
|
234
237
|
# ...
|
235
238
|
end
|
236
239
|
end
|
237
|
-
|
240
|
+
|
238
241
|
def call
|
239
242
|
get('.../url.com', cache: :thread) # configure caching per request level
|
240
243
|
end
|
data/nxt_http_client.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
lib = File.expand_path("../lib", __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require "nxt_http_client/version"
|
@@ -36,12 +35,12 @@ Gem::Specification.new do |spec|
|
|
36
35
|
spec.require_paths = ['lib']
|
37
36
|
|
38
37
|
spec.add_dependency 'typhoeus'
|
39
|
-
spec.add_dependency 'activesupport', '
|
38
|
+
spec.add_dependency 'activesupport', '< 8.0'
|
40
39
|
spec.add_dependency 'nxt_registry'
|
41
40
|
|
42
|
-
spec.add_development_dependency 'bundler'
|
43
|
-
spec.add_development_dependency 'rake'
|
44
|
-
spec.add_development_dependency 'rspec'
|
41
|
+
spec.add_development_dependency 'bundler'
|
42
|
+
spec.add_development_dependency 'rake'
|
43
|
+
spec.add_development_dependency 'rspec'
|
45
44
|
spec.add_development_dependency 'pry'
|
46
45
|
spec.add_development_dependency 'vcr'
|
47
46
|
spec.add_development_dependency 'webmock'
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nxt_http_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andreas Robecke
|
8
8
|
- Nils Sommer
|
9
9
|
- Raphael Kallensee
|
10
10
|
- Luetfi Demirci
|
11
|
-
autorequire:
|
11
|
+
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2022-06-08 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: typhoeus
|
@@ -31,16 +31,16 @@ dependencies:
|
|
31
31
|
name: activesupport
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
requirements:
|
34
|
-
- - "
|
34
|
+
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: '
|
36
|
+
version: '8.0'
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
40
40
|
requirements:
|
41
|
-
- - "
|
41
|
+
- - "<"
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
43
|
+
version: '8.0'
|
44
44
|
- !ruby/object:Gem::Dependency
|
45
45
|
name: nxt_registry
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,44 +59,44 @@ dependencies:
|
|
59
59
|
name: bundler
|
60
60
|
requirement: !ruby/object:Gem::Requirement
|
61
61
|
requirements:
|
62
|
-
- - "
|
62
|
+
- - ">="
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version: '
|
64
|
+
version: '0'
|
65
65
|
type: :development
|
66
66
|
prerelease: false
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
|
-
- - "
|
69
|
+
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
|
-
version: '
|
71
|
+
version: '0'
|
72
72
|
- !ruby/object:Gem::Dependency
|
73
73
|
name: rake
|
74
74
|
requirement: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
|
-
- - "
|
76
|
+
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version: '
|
78
|
+
version: '0'
|
79
79
|
type: :development
|
80
80
|
prerelease: false
|
81
81
|
version_requirements: !ruby/object:Gem::Requirement
|
82
82
|
requirements:
|
83
|
-
- - "
|
83
|
+
- - ">="
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
version: '
|
85
|
+
version: '0'
|
86
86
|
- !ruby/object:Gem::Dependency
|
87
87
|
name: rspec
|
88
88
|
requirement: !ruby/object:Gem::Requirement
|
89
89
|
requirements:
|
90
|
-
- - "
|
90
|
+
- - ">="
|
91
91
|
- !ruby/object:Gem::Version
|
92
|
-
version: '
|
92
|
+
version: '0'
|
93
93
|
type: :development
|
94
94
|
prerelease: false
|
95
95
|
version_requirements: !ruby/object:Gem::Requirement
|
96
96
|
requirements:
|
97
|
-
- - "
|
97
|
+
- - ">="
|
98
98
|
- !ruby/object:Gem::Version
|
99
|
-
version: '
|
99
|
+
version: '0'
|
100
100
|
- !ruby/object:Gem::Dependency
|
101
101
|
name: pry
|
102
102
|
requirement: !ruby/object:Gem::Requirement
|
@@ -205,6 +205,7 @@ files:
|
|
205
205
|
- ".circleci/config.yml"
|
206
206
|
- ".gitignore"
|
207
207
|
- ".rspec"
|
208
|
+
- ".ruby-version"
|
208
209
|
- ".travis.yml"
|
209
210
|
- CHANGELOG.md
|
210
211
|
- Gemfile
|
@@ -233,7 +234,7 @@ metadata:
|
|
233
234
|
allowed_push_host: https://rubygems.org
|
234
235
|
homepage_uri: https://github.com/nxt-insurance
|
235
236
|
source_code_uri: https://github.com/nxt-insurance/nxt_http_client
|
236
|
-
post_install_message:
|
237
|
+
post_install_message:
|
237
238
|
rdoc_options: []
|
238
239
|
require_paths:
|
239
240
|
- lib
|
@@ -248,8 +249,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
248
249
|
- !ruby/object:Gem::Version
|
249
250
|
version: '0'
|
250
251
|
requirements: []
|
251
|
-
rubygems_version: 3.
|
252
|
-
signing_key:
|
252
|
+
rubygems_version: 3.1.6
|
253
|
+
signing_key:
|
253
254
|
specification_version: 4
|
254
255
|
summary: NxtHttpClinet is a simple DSL on top the typhoeus http gem
|
255
256
|
test_files: []
|