nxt_http_client 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +6 -6
- data/README.md +32 -29
- data/lib/nxt_http_client/error.rb +1 -2
- data/lib/nxt_http_client/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aebfa8039d0d512c58392115ba1e7362a47acd59311e032e30b518db87b7a3ea
|
4
|
+
data.tar.gz: 29f82bfb73f10f8006351a7a9f0c61d58ca734f1b118df0fe4f6d7bee1c97caa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66d043d9c7dfde0e562d38fb42be8d338facb674feae608b85aa69b03320c19426351b8c636e2bba2c0107dfe217a2a04ca5f9205d701c0e9ebfb5d82b74c858
|
7
|
+
data.tar.gz: 31321953bc43d2d9f19bf46a0ae5e3e2bbd223c4d13eb29c28024a07882588f31530839c378915531d1fa54f56668490bb8abe55528b7782ca364cfecf375130
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nxt_http_client (1.0.
|
4
|
+
nxt_http_client (1.0.2)
|
5
5
|
activesupport (~> 6.0)
|
6
6
|
nxt_registry
|
7
7
|
typhoeus
|
@@ -9,7 +9,7 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (6.1.1)
|
12
|
+
activesupport (6.1.2.1)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
14
|
i18n (>= 1.6, < 2)
|
15
15
|
minitest (>= 5.1)
|
@@ -26,7 +26,7 @@ GEM
|
|
26
26
|
ffi (>= 1.3.0)
|
27
27
|
ffi (1.14.2)
|
28
28
|
hashdiff (1.0.1)
|
29
|
-
i18n (1.8.
|
29
|
+
i18n (1.8.9)
|
30
30
|
concurrent-ruby (~> 1.0)
|
31
31
|
method_source (1.0.0)
|
32
32
|
minitest (5.14.3)
|
@@ -35,7 +35,7 @@ GEM
|
|
35
35
|
nxt_vcr_harness (0.1.4)
|
36
36
|
rspec (~> 3.0)
|
37
37
|
vcr (~> 6.0)
|
38
|
-
pry (0.
|
38
|
+
pry (0.14.0)
|
39
39
|
coderay (~> 1.1)
|
40
40
|
method_source (~> 1.0)
|
41
41
|
public_suffix (4.0.6)
|
@@ -57,7 +57,7 @@ GEM
|
|
57
57
|
rspec-support (3.10.2)
|
58
58
|
rspec_junit_formatter (0.4.1)
|
59
59
|
rspec-core (>= 2, < 4, != 2.12.0)
|
60
|
-
timecop (0.9.
|
60
|
+
timecop (0.9.4)
|
61
61
|
typhoeus (1.4.0)
|
62
62
|
ethon (>= 0.9.0)
|
63
63
|
tzinfo (2.0.4)
|
@@ -86,4 +86,4 @@ DEPENDENCIES
|
|
86
86
|
webmock
|
87
87
|
|
88
88
|
BUNDLED WITH
|
89
|
-
2.2.
|
89
|
+
2.2.7
|
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
|
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.2
|
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: 2021-02-
|
14
|
+
date: 2021-02-22 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: typhoeus
|
@@ -233,7 +233,7 @@ metadata:
|
|
233
233
|
allowed_push_host: https://rubygems.org
|
234
234
|
homepage_uri: https://github.com/nxt-insurance
|
235
235
|
source_code_uri: https://github.com/nxt-insurance/nxt_http_client
|
236
|
-
post_install_message:
|
236
|
+
post_install_message:
|
237
237
|
rdoc_options: []
|
238
238
|
require_paths:
|
239
239
|
- lib
|
@@ -248,8 +248,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
248
248
|
- !ruby/object:Gem::Version
|
249
249
|
version: '0'
|
250
250
|
requirements: []
|
251
|
-
rubygems_version: 3.
|
252
|
-
signing_key:
|
251
|
+
rubygems_version: 3.1.4
|
252
|
+
signing_key:
|
253
253
|
specification_version: 4
|
254
254
|
summary: NxtHttpClinet is a simple DSL on top the typhoeus http gem
|
255
255
|
test_files: []
|