chimera_http_client 1.1.2 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +40 -34
- data/.ruby-version +1 -1
- data/.travis.yml +4 -3
- data/README.markdown +41 -8
- data/Rakefile +10 -12
- data/TODO.markdown +13 -9
- data/chimera_http_client.gemspec +7 -5
- data/lib/chimera_http_client.rb +1 -1
- data/lib/chimera_http_client/base.rb +2 -1
- data/lib/chimera_http_client/connection.rb +5 -4
- data/lib/chimera_http_client/error.rb +2 -0
- data/lib/chimera_http_client/queue.rb +5 -4
- data/lib/chimera_http_client/request.rb +30 -5
- data/lib/chimera_http_client/version.rb +1 -1
- metadata +47 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d44d96daf4357f5f997f4874569c0f92bddeab9f945d5c950f8066d937c8d92b
|
|
4
|
+
data.tar.gz: 71eadaa902be940979f3fff031bddb78469beefafed2f605a19199ca54ce14f7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7efe9e56feff54e326a568817cd2edde14ca7988188f67a150d6a4c507d0c87e6d4e08ab159102fdf91f6a86684acb18386cd9b433a63bc5b98e22a92b4e18d9
|
|
7
|
+
data.tar.gz: 97fa3cbea4100201f44264efccd9d5e574abbac20dcc36ef3cfdfd5b9aac16d993ba065b39fa56d2c6b31f9c1cbc2476ab58621bb0815aaa6343419e48c0dcff
|
data/.rubocop.yml
CHANGED
|
@@ -1,50 +1,48 @@
|
|
|
1
|
+
require:
|
|
2
|
+
- rubocop-rake
|
|
3
|
+
- rubocop-rspec
|
|
4
|
+
|
|
1
5
|
AllCops:
|
|
2
|
-
DisplayCopNames: true
|
|
3
6
|
TargetRubyVersion: 2.5
|
|
7
|
+
DisplayCopNames: true
|
|
8
|
+
NewCops: enable # but feel free to disable them below
|
|
4
9
|
Exclude:
|
|
5
10
|
- vendor/**/*
|
|
6
11
|
- config.ru
|
|
7
12
|
|
|
8
|
-
Layout/
|
|
9
|
-
|
|
13
|
+
Layout/EmptyLineBetweenDefs:
|
|
14
|
+
AllowAdjacentOneLineDefs: true
|
|
10
15
|
|
|
11
|
-
# Cop supports --auto-correct.
|
|
12
16
|
# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth.
|
|
13
17
|
# SupportedStyles: special_inside_parentheses, consistent, align_braces
|
|
14
|
-
Layout/
|
|
18
|
+
Layout/FirstHashElementIndentation:
|
|
15
19
|
EnforcedStyle: consistent
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
Layout/HashAlignment:
|
|
22
|
+
Enabled: false
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
- chimera_http_client.gemspec
|
|
23
|
-
- spec/**/*
|
|
24
|
+
Layout/LineLength:
|
|
25
|
+
Max: 125
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Max: 150
|
|
27
|
+
Metrics:
|
|
28
|
+
Enabled: false
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
RSpec/ContextWording:
|
|
31
|
+
Enabled: false
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
Metrics/LineLength:
|
|
35
|
-
Max: 125
|
|
33
|
+
RSpec/ExampleLength:
|
|
34
|
+
Max: 25
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
Metrics/MethodLength:
|
|
40
|
-
Max: 32
|
|
36
|
+
RSpec/MultipleExpectations:
|
|
37
|
+
Enabled: false
|
|
41
38
|
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
RSpec/MultipleMemoizedHelpers:
|
|
40
|
+
Enabled: false
|
|
44
41
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
RSpec/NestedGroups:
|
|
43
|
+
Max: 4
|
|
44
|
+
|
|
45
|
+
Style/CaseLikeIf:
|
|
48
46
|
Enabled: false
|
|
49
47
|
|
|
50
48
|
Style/CommentedKeyword:
|
|
@@ -55,7 +53,6 @@ Style/Documentation:
|
|
|
55
53
|
|
|
56
54
|
Style/DoubleNegation:
|
|
57
55
|
Enabled: true
|
|
58
|
-
|
|
59
56
|
Style/FrozenStringLiteralComment:
|
|
60
57
|
Enabled: false
|
|
61
58
|
|
|
@@ -71,11 +68,22 @@ Style/StringLiterals:
|
|
|
71
68
|
- single_quotes
|
|
72
69
|
- double_quotes
|
|
73
70
|
|
|
74
|
-
# Cop supports --auto-correct.
|
|
75
71
|
Style/NumericLiterals:
|
|
76
72
|
MinDigits: 15
|
|
77
73
|
|
|
78
|
-
|
|
74
|
+
Style/PercentLiteralDelimiters:
|
|
75
|
+
PreferredDelimiters:
|
|
76
|
+
default: ()
|
|
77
|
+
"%": ()
|
|
78
|
+
"%i": ()
|
|
79
|
+
"%q": ()
|
|
80
|
+
"%Q": ()
|
|
81
|
+
"%r": "{}"
|
|
82
|
+
"%s": ()
|
|
83
|
+
"%w": ()
|
|
84
|
+
"%W": ()
|
|
85
|
+
"%x": ()
|
|
86
|
+
|
|
79
87
|
# Configuration parameters: AllowAsExpressionSeparator.
|
|
80
88
|
Style/Semicolon:
|
|
81
89
|
AllowAsExpressionSeparator: true
|
|
@@ -83,7 +91,6 @@ Style/Semicolon:
|
|
|
83
91
|
Style/SymbolProc:
|
|
84
92
|
Enabled: false
|
|
85
93
|
|
|
86
|
-
# Cop supports --auto-correct.
|
|
87
94
|
# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles.
|
|
88
95
|
# SupportedStyles: comma, consistent_comma, no_comma
|
|
89
96
|
Style/TrailingCommaInArrayLiteral:
|
|
@@ -92,7 +99,6 @@ Style/TrailingCommaInArrayLiteral:
|
|
|
92
99
|
Style/TrailingCommaInHashLiteral:
|
|
93
100
|
EnforcedStyleForMultiline: comma
|
|
94
101
|
|
|
95
|
-
# Cop supports --auto-correct.
|
|
96
102
|
# Configuration parameters: SupportedStyles, MinSize, WordRegex.
|
|
97
103
|
# SupportedStyles: percent, brackets
|
|
98
104
|
Style/WordArray:
|
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
3.0.1
|
data/.travis.yml
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
language: ruby
|
|
2
2
|
|
|
3
3
|
rvm:
|
|
4
|
-
-
|
|
4
|
+
- 3.0
|
|
5
|
+
- 2.7
|
|
5
6
|
- 2.6
|
|
6
7
|
- 2.5
|
|
7
8
|
- jruby
|
|
@@ -16,10 +17,10 @@ matrix:
|
|
|
16
17
|
before_install:
|
|
17
18
|
- 'echo ''gem: --no-ri --no-rdoc'' > ~/.gemrc'
|
|
18
19
|
|
|
19
|
-
bundler_args: --jobs
|
|
20
|
+
bundler_args: --jobs 4 --retry 4
|
|
20
21
|
|
|
21
22
|
before_script:
|
|
22
23
|
|
|
23
24
|
# execute rspec tests, rubocop and bundle:audit
|
|
24
25
|
script:
|
|
25
|
-
bundle exec rake
|
|
26
|
+
bundle exec rake ci
|
data/README.markdown
CHANGED
|
@@ -17,11 +17,14 @@ The only other runtime dependency is Ruby's latest code loader [**zeitwerk**](ht
|
|
|
17
17
|
|
|
18
18
|
### Ruby version
|
|
19
19
|
|
|
20
|
-
| Chimera version | Ruby version
|
|
21
|
-
|
|
22
|
-
| >= 1.
|
|
23
|
-
|
|
|
24
|
-
|
|
|
20
|
+
| Chimera version | Ruby version |
|
|
21
|
+
|:----------------|:-----------------------------------|
|
|
22
|
+
| >= 1.4 | >= 2.5 (3.0 compatibility ensured) |
|
|
23
|
+
| >= 1.1 | >= 2.5 |
|
|
24
|
+
| = 1.0 | >= 2.4, <= 3.0 |
|
|
25
|
+
| <= 0.5 | >= 2.1, <= 3.0 |
|
|
26
|
+
|
|
27
|
+
The test suite of v1.4 passes on **MRI Ruby** (2.5, 2.6, 2.7, 3.0) and on **JRuby**, but not on **TruffleRuby**.
|
|
25
28
|
|
|
26
29
|
### ENV variables
|
|
27
30
|
|
|
@@ -83,12 +86,13 @@ Setting the `base_url` is meant to be a comfort feature, as you can then pass sh
|
|
|
83
86
|
|
|
84
87
|
The optional parameters are:
|
|
85
88
|
|
|
86
|
-
* `
|
|
89
|
+
* `cache` - an instance of your cache solution, can be overwritten in any request
|
|
90
|
+
* `deserializers` - custom methods to deserialize the response body, below more details
|
|
91
|
+
* `logger` - an instance of a logger class that implements `#info`, `#warn` and `#error` methods
|
|
92
|
+
* `monitor` - to collect metrics about requests, the basis for your instrumentation needs
|
|
87
93
|
* `timeout` - the timeout for all requests, can be overwritten in any request, the default are 3 seconds
|
|
88
94
|
* `user_agent` - if you would like your calls to identify with a specific user agent
|
|
89
95
|
* `verbose` - the default is `false`, set it to true while debugging issues
|
|
90
|
-
* `cache` - an instance of your cache solution, can be overwritten in any request
|
|
91
|
-
* `deserializers` - custom methods to deserialize the response body, below more details
|
|
92
96
|
|
|
93
97
|
##### Custom deserializers
|
|
94
98
|
|
|
@@ -102,6 +106,23 @@ A Deserializer has to be an object on which the method `call` with the parameter
|
|
|
102
106
|
|
|
103
107
|
where `body` is the response body (in the default case a JSON object). The class `Deserializer` contains the default objects that are used. They might help you creating your own. Don't forget to make requests with another header than the default `"Content-Type" => "application/json"`, when the API you connect to does not support JSON.
|
|
104
108
|
|
|
109
|
+
##### Monitoring, metrics, instrumentation
|
|
110
|
+
|
|
111
|
+
Pass an object as `:monitor` to a connection that defines the method `call` and accepts a hash as parameter.
|
|
112
|
+
|
|
113
|
+
monitor.call({...})
|
|
114
|
+
|
|
115
|
+
It will receive information about every request as soon as it finished. What you do with this information is up for you to implement.
|
|
116
|
+
|
|
117
|
+
| Field | Description |
|
|
118
|
+
|:---------------|:----------------------------------------------------------------------|
|
|
119
|
+
| `url` | URL of the endpoint that was called |
|
|
120
|
+
| `method` | HTTP method: get, post, ... |
|
|
121
|
+
| `status` | HTTP status code: 200, ... |
|
|
122
|
+
| `runtime` | the time in seconds it took the request to finish |
|
|
123
|
+
| `completed_at` | Time.now.utc.iso8601(3) |
|
|
124
|
+
| `context` | Whatever you pass as `monitoring_context` to the options of a request |
|
|
125
|
+
|
|
105
126
|
### Request methods
|
|
106
127
|
|
|
107
128
|
The available methods are:
|
|
@@ -142,6 +163,7 @@ All request methods expect a mandatory `endpoint` and an optional hash as parame
|
|
|
142
163
|
* `password` - used for a BasicAuth login
|
|
143
164
|
* `timeout` - set a custom timeout per request (the default is 3 seconds)
|
|
144
165
|
* `cache` - optionally overwrite the cache store set in `Connection` in any request
|
|
166
|
+
* `monitoring_context` - pass additional information you want to collect with your instrumentation `monitor`
|
|
145
167
|
|
|
146
168
|
Example:
|
|
147
169
|
|
|
@@ -171,6 +193,17 @@ If you want to use a different timeout, you can pass the key `timeout` when init
|
|
|
171
193
|
|
|
172
194
|
By default no logging is happening. If you need request logging, you can pass your custom Logger to the key `logger` when initializing the `Connection`. It will write to `logger.info` when starting and when completing a request.
|
|
173
195
|
|
|
196
|
+
The message passed to the logger is a hash with the following fields:
|
|
197
|
+
|
|
198
|
+
| Key | Description |
|
|
199
|
+
|:-------------|:--------------------------------------------|
|
|
200
|
+
| `message` | indicator if a call was started or finished |
|
|
201
|
+
| `method` | the HTTP method used |
|
|
202
|
+
| `url` | the requested URL |
|
|
203
|
+
| `code` | HTTP status code |
|
|
204
|
+
| `runtime` | time the request took in ms |
|
|
205
|
+
| `user_agent` | the user_agent used to open the connection |
|
|
206
|
+
|
|
174
207
|
#### Caching responses
|
|
175
208
|
|
|
176
209
|
To cache all the reponses of a connection, just pass the optional parameter `cache` to its initializer. You can also overwrite the connection's cache configuration by passing the parameter `cache` to any `get` call.
|
data/Rakefile
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
require "bundler/audit/task"
|
|
2
2
|
require "bundler/gem_tasks"
|
|
3
3
|
require "rspec/core/rake_task"
|
|
4
|
+
require "rubocop/rake_task"
|
|
4
5
|
|
|
6
|
+
# setup task bundle:audit
|
|
5
7
|
Bundler::Audit::Task.new
|
|
6
8
|
|
|
9
|
+
# setup taks rspec
|
|
7
10
|
RSpec::Core::RakeTask.new(:rspec) do |t|
|
|
8
11
|
# t.exclude_pattern = "**/server/*_spec.rb" # skip real http server specs
|
|
9
12
|
# t.exclude_pattern = "**/stubbed/*_spec.rb" # skip the stubbed Typhoeus specs
|
|
10
13
|
end
|
|
11
14
|
|
|
15
|
+
# setup taks rubocop and rubocop:auto_correct
|
|
16
|
+
RuboCop::RakeTask.new
|
|
17
|
+
|
|
12
18
|
desc "Open a console with the ChimeraHttpClient loaded"
|
|
13
19
|
task :console do
|
|
14
|
-
puts "Console with the gem and
|
|
20
|
+
puts "Console with the gem and amazing_print loaded:"
|
|
15
21
|
ARGV.clear
|
|
16
22
|
require "irb"
|
|
17
23
|
require "ap"
|
|
@@ -19,15 +25,7 @@ task :console do
|
|
|
19
25
|
IRB.start
|
|
20
26
|
end
|
|
21
27
|
|
|
22
|
-
desc "Run
|
|
23
|
-
task :rubocop
|
|
24
|
-
system "bundle exec rubocop -c .rubocop.yml"
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
desc "Run Rubocop and auto-correct issues"
|
|
28
|
-
task :rubocopa do
|
|
29
|
-
system "bundle exec rubocop -c .rubocop.yml -a"
|
|
30
|
-
end
|
|
28
|
+
desc "Run rubocop and the specs and check for known CVEs"
|
|
29
|
+
task ci: %i(rubocop rspec bundle:audit)
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
task default: %i[rspec rubocop bundle:audit]
|
|
31
|
+
task default: :ci
|
data/TODO.markdown
CHANGED
|
@@ -14,8 +14,9 @@ _none known_
|
|
|
14
14
|
* [x] ~~include the total_time of the requests in the log~~
|
|
15
15
|
* [x] ~~add (example) to README~~
|
|
16
16
|
* [ ] add logger.warn / .error for error cases (?)
|
|
17
|
+
* [ ] streamline log message
|
|
17
18
|
|
|
18
|
-
### Custom De-serializer
|
|
19
|
+
### ~~Custom De-serializer~~
|
|
19
20
|
|
|
20
21
|
* [x] ~~allow to pass custom deserializer~~
|
|
21
22
|
* [x] ~~use custom deserializer in #parsed_body instead of default JSON parsing~~
|
|
@@ -40,15 +41,18 @@ _none known_
|
|
|
40
41
|
|
|
41
42
|
- [ ] Determine by parameter if 3xx Redirects should be handled as an Error or not
|
|
42
43
|
- [x] ~~Add a longer description to the gemspec file~~
|
|
44
|
+
- [ ] Refactor README to explain simple use case vs. all the powerful options?
|
|
43
45
|
|
|
44
|
-
### Instrumentation
|
|
46
|
+
### ~~Instrumentation~~
|
|
45
47
|
|
|
46
|
-
- [
|
|
47
|
-
- [
|
|
48
|
-
- [
|
|
49
|
-
- [
|
|
50
|
-
- [
|
|
51
|
-
- [
|
|
48
|
+
- [x] ~~allow to pass object to collect metrics for monitoring~~
|
|
49
|
+
- [x] ~~request URL~~
|
|
50
|
+
- [x] ~~request HTTP method~~
|
|
51
|
+
- [x] ~~request response code~~
|
|
52
|
+
- [x] ~~request datetime~~
|
|
53
|
+
- [x] ~~request runtime~~
|
|
54
|
+
- [x] ~~custom context information per request~~
|
|
55
|
+
- [x] ~~add example to README~~
|
|
52
56
|
|
|
53
57
|
### Enable more Typhoeus functionality
|
|
54
58
|
|
|
@@ -93,7 +97,7 @@ _none known_
|
|
|
93
97
|
* [x] ~~allow to set custom timeout per call~~
|
|
94
98
|
* [x] ~~add (example) to README~~
|
|
95
99
|
|
|
96
|
-
### Release
|
|
100
|
+
### ~~Release~~
|
|
97
101
|
|
|
98
102
|
* [x] ~~rename module to have unique namespace~~
|
|
99
103
|
* [x] ~~release to rubygems to add to the plethora of similar gems~~
|
data/chimera_http_client.gemspec
CHANGED
|
@@ -32,14 +32,15 @@ Gem::Specification.new do |spec|
|
|
|
32
32
|
spec.add_runtime_dependency "zeitwerk", ">= 2.0"
|
|
33
33
|
|
|
34
34
|
# general development and test dependencies
|
|
35
|
-
spec.add_development_dependency "
|
|
35
|
+
spec.add_development_dependency "amazing_print", ">= 1.2"
|
|
36
36
|
spec.add_development_dependency "bundler", ">= 1.0"
|
|
37
|
-
spec.add_development_dependency "bundler-audit", "
|
|
38
|
-
spec.add_development_dependency "irb", "
|
|
37
|
+
spec.add_development_dependency "bundler-audit", ">= 0.6"
|
|
38
|
+
spec.add_development_dependency "irb", ">= 1.0"
|
|
39
39
|
spec.add_development_dependency "rake", ">= 10.0"
|
|
40
40
|
spec.add_development_dependency "rspec", "~> 3.0"
|
|
41
|
-
spec.add_development_dependency "rubocop", "~>
|
|
42
|
-
spec.add_development_dependency "rubocop-
|
|
41
|
+
spec.add_development_dependency "rubocop", "~> 1.12"
|
|
42
|
+
spec.add_development_dependency "rubocop-rake", "~> 0.5"
|
|
43
|
+
spec.add_development_dependency "rubocop-rspec", "~> 2.2"
|
|
43
44
|
|
|
44
45
|
# only for server specs with real HTTP requests
|
|
45
46
|
spec.add_development_dependency "capybara", "~> 3.0"
|
|
@@ -47,4 +48,5 @@ Gem::Specification.new do |spec|
|
|
|
47
48
|
spec.add_development_dependency "sinatra", "~> 2.0"
|
|
48
49
|
spec.add_development_dependency "sinatra-contrib", "~> 2.0"
|
|
49
50
|
spec.add_development_dependency "webmock", "~> 3.0"
|
|
51
|
+
spec.add_development_dependency "webrick"
|
|
50
52
|
end
|
data/lib/chimera_http_client.rb
CHANGED
|
@@ -8,6 +8,7 @@ module ChimeraHttpClient
|
|
|
8
8
|
@base_url = options.fetch(:base_url)
|
|
9
9
|
@deserializer = default_deserializer.merge(options.fetch(:deserializer, {}))
|
|
10
10
|
@logger = options[:logger]
|
|
11
|
+
@monitor = options[:monitor]
|
|
11
12
|
@timeout = options[:timeout]
|
|
12
13
|
|
|
13
14
|
Typhoeus::Config.cache = options[:cache]
|
|
@@ -55,7 +56,7 @@ module ChimeraHttpClient
|
|
|
55
56
|
|
|
56
57
|
# Remove leading and trailing "/" from a give part of a String (usually URL or endpoint)
|
|
57
58
|
def trim(element)
|
|
58
|
-
element.to_s.sub(%r{
|
|
59
|
+
element.to_s.sub(%r{^/}, "").chomp("/")
|
|
59
60
|
end
|
|
60
61
|
end
|
|
61
62
|
end
|
|
@@ -12,17 +12,18 @@ module ChimeraHttpClient
|
|
|
12
12
|
|
|
13
13
|
def request
|
|
14
14
|
options = {
|
|
15
|
-
logger: @logger,
|
|
16
15
|
deserializer: @deserializer,
|
|
16
|
+
logger: @logger,
|
|
17
|
+
monitor: @monitor,
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
Request.new(options)
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
private
|
|
23
24
|
|
|
24
25
|
def run(method, endpoint, options = {})
|
|
25
|
-
options[:body_optional] = true if %i
|
|
26
|
+
options[:body_optional] = true if %i(get delete head options trace).include?(method)
|
|
26
27
|
body = extract_body(options)
|
|
27
28
|
headers = extract_headers(options, default_headers)
|
|
28
29
|
|
|
@@ -36,7 +37,7 @@ module ChimeraHttpClient
|
|
|
36
37
|
# end
|
|
37
38
|
#
|
|
38
39
|
def define_http_methods
|
|
39
|
-
%i
|
|
40
|
+
%i(get post put patch delete head options trace).each do |method_name|
|
|
40
41
|
self.class.send(:define_method, method_name) do |endpoint, options = {}|
|
|
41
42
|
send(:run, method_name, endpoint, options)
|
|
42
43
|
end
|
|
@@ -2,7 +2,7 @@ module ChimeraHttpClient
|
|
|
2
2
|
class Queue < Base
|
|
3
3
|
def add(method, endpoint, options = {})
|
|
4
4
|
http_method = method.downcase.to_sym
|
|
5
|
-
options[:body_optional] = true if %i
|
|
5
|
+
options[:body_optional] = true if %i(get delete head options trace).include?(http_method)
|
|
6
6
|
|
|
7
7
|
queued_requests << create_request(
|
|
8
8
|
method: http_method,
|
|
@@ -38,12 +38,13 @@ module ChimeraHttpClient
|
|
|
38
38
|
private
|
|
39
39
|
|
|
40
40
|
def create_request(method:, url:, body:, headers:, options:)
|
|
41
|
-
|
|
42
|
-
logger: @logger,
|
|
41
|
+
instance_options = {
|
|
43
42
|
deserializer: @deserializer,
|
|
43
|
+
logger: @logger,
|
|
44
|
+
monitor: @monitor,
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
Request.new(
|
|
47
|
+
Request.new(instance_options).create(
|
|
47
48
|
method: method,
|
|
48
49
|
url: url,
|
|
49
50
|
body: body,
|
|
@@ -5,7 +5,6 @@ module ChimeraHttpClient
|
|
|
5
5
|
attr_reader :request, :result
|
|
6
6
|
|
|
7
7
|
def initialize(options = {})
|
|
8
|
-
@logger = options[:logger]
|
|
9
8
|
@options = options
|
|
10
9
|
end
|
|
11
10
|
|
|
@@ -37,13 +36,39 @@ module ChimeraHttpClient
|
|
|
37
36
|
|
|
38
37
|
@result = nil
|
|
39
38
|
@request.on_complete do |response|
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
runtime = response.total_time&.round(3)
|
|
40
|
+
|
|
41
|
+
@options[:monitor]&.call(
|
|
42
|
+
{
|
|
43
|
+
url: url, method: method, status: response.code, runtime: runtime,
|
|
44
|
+
completed_at: Time.now.utc.iso8601(3), context: options[:monitoring_context]
|
|
45
|
+
}
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
@options[:logger]&.info(
|
|
49
|
+
{
|
|
50
|
+
message: "Completed Chimera HTTP Request",
|
|
51
|
+
method: method.upcase,
|
|
52
|
+
url: url,
|
|
53
|
+
code: response.code,
|
|
54
|
+
runtime: runtime,
|
|
55
|
+
user_agent: Typhoeus::Config.user_agent,
|
|
56
|
+
}
|
|
57
|
+
)
|
|
42
58
|
|
|
43
59
|
@result = on_complete_handler(response)
|
|
44
60
|
end
|
|
45
61
|
|
|
46
|
-
@logger&.info(
|
|
62
|
+
@options[:logger]&.info(
|
|
63
|
+
{
|
|
64
|
+
message: "Starting Chimera HTTP Request",
|
|
65
|
+
method: method.upcase,
|
|
66
|
+
url: url,
|
|
67
|
+
code: nil,
|
|
68
|
+
runtime: 0,
|
|
69
|
+
user_agent: Typhoeus::Config.user_agent,
|
|
70
|
+
}
|
|
71
|
+
)
|
|
47
72
|
|
|
48
73
|
self
|
|
49
74
|
end
|
|
@@ -63,7 +88,7 @@ module ChimeraHttpClient
|
|
|
63
88
|
when 301, 302, 303, 307
|
|
64
89
|
RedirectionError.new(response, @options) # TODO: throw error conditionally
|
|
65
90
|
when 200..399
|
|
66
|
-
nil
|
|
91
|
+
nil # TODO: decide to either raise error or return a Response
|
|
67
92
|
when 400
|
|
68
93
|
BadRequestError.new(response, @options)
|
|
69
94
|
when 401
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: chimera_http_client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1
|
|
4
|
+
version: 1.4.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Andreas Finger
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-04-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: typhoeus
|
|
@@ -39,19 +39,19 @@ dependencies:
|
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '2.0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
|
-
name:
|
|
42
|
+
name: amazing_print
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- - "
|
|
45
|
+
- - ">="
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '1.
|
|
47
|
+
version: '1.2'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- - "
|
|
52
|
+
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '1.
|
|
54
|
+
version: '1.2'
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: bundler
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -70,28 +70,28 @@ dependencies:
|
|
|
70
70
|
name: bundler-audit
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
|
73
|
-
- - "
|
|
73
|
+
- - ">="
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
75
|
version: '0.6'
|
|
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
82
|
version: '0.6'
|
|
83
83
|
- !ruby/object:Gem::Dependency
|
|
84
84
|
name: irb
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements:
|
|
87
|
-
- - "
|
|
87
|
+
- - ">="
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
89
|
version: '1.0'
|
|
90
90
|
type: :development
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
|
-
- - "
|
|
94
|
+
- - ">="
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: '1.0'
|
|
97
97
|
- !ruby/object:Gem::Dependency
|
|
@@ -128,28 +128,42 @@ dependencies:
|
|
|
128
128
|
requirements:
|
|
129
129
|
- - "~>"
|
|
130
130
|
- !ruby/object:Gem::Version
|
|
131
|
-
version: '
|
|
131
|
+
version: '1.12'
|
|
132
|
+
type: :development
|
|
133
|
+
prerelease: false
|
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
135
|
+
requirements:
|
|
136
|
+
- - "~>"
|
|
137
|
+
- !ruby/object:Gem::Version
|
|
138
|
+
version: '1.12'
|
|
139
|
+
- !ruby/object:Gem::Dependency
|
|
140
|
+
name: rubocop-rake
|
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
|
142
|
+
requirements:
|
|
143
|
+
- - "~>"
|
|
144
|
+
- !ruby/object:Gem::Version
|
|
145
|
+
version: '0.5'
|
|
132
146
|
type: :development
|
|
133
147
|
prerelease: false
|
|
134
148
|
version_requirements: !ruby/object:Gem::Requirement
|
|
135
149
|
requirements:
|
|
136
150
|
- - "~>"
|
|
137
151
|
- !ruby/object:Gem::Version
|
|
138
|
-
version: '0.
|
|
152
|
+
version: '0.5'
|
|
139
153
|
- !ruby/object:Gem::Dependency
|
|
140
154
|
name: rubocop-rspec
|
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
|
142
156
|
requirements:
|
|
143
157
|
- - "~>"
|
|
144
158
|
- !ruby/object:Gem::Version
|
|
145
|
-
version: '
|
|
159
|
+
version: '2.2'
|
|
146
160
|
type: :development
|
|
147
161
|
prerelease: false
|
|
148
162
|
version_requirements: !ruby/object:Gem::Requirement
|
|
149
163
|
requirements:
|
|
150
164
|
- - "~>"
|
|
151
165
|
- !ruby/object:Gem::Version
|
|
152
|
-
version: '
|
|
166
|
+
version: '2.2'
|
|
153
167
|
- !ruby/object:Gem::Dependency
|
|
154
168
|
name: capybara
|
|
155
169
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -220,6 +234,20 @@ dependencies:
|
|
|
220
234
|
- - "~>"
|
|
221
235
|
- !ruby/object:Gem::Version
|
|
222
236
|
version: '3.0'
|
|
237
|
+
- !ruby/object:Gem::Dependency
|
|
238
|
+
name: webrick
|
|
239
|
+
requirement: !ruby/object:Gem::Requirement
|
|
240
|
+
requirements:
|
|
241
|
+
- - ">="
|
|
242
|
+
- !ruby/object:Gem::Version
|
|
243
|
+
version: '0'
|
|
244
|
+
type: :development
|
|
245
|
+
prerelease: false
|
|
246
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
247
|
+
requirements:
|
|
248
|
+
- - ">="
|
|
249
|
+
- !ruby/object:Gem::Version
|
|
250
|
+
version: '0'
|
|
223
251
|
description: |
|
|
224
252
|
The Chimera http client offers an easy to learn interface and consistent error handling.
|
|
225
253
|
It is lightweight, fast and enables you to queue HTTP requests to run them in parallel
|
|
@@ -256,7 +284,7 @@ homepage: https://github.com/mediafinger/chimera_http_client
|
|
|
256
284
|
licenses:
|
|
257
285
|
- MIT
|
|
258
286
|
metadata: {}
|
|
259
|
-
post_install_message:
|
|
287
|
+
post_install_message:
|
|
260
288
|
rdoc_options: []
|
|
261
289
|
require_paths:
|
|
262
290
|
- lib
|
|
@@ -271,8 +299,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
271
299
|
- !ruby/object:Gem::Version
|
|
272
300
|
version: '0'
|
|
273
301
|
requirements: []
|
|
274
|
-
rubygems_version: 3.
|
|
275
|
-
signing_key:
|
|
302
|
+
rubygems_version: 3.2.15
|
|
303
|
+
signing_key:
|
|
276
304
|
specification_version: 4
|
|
277
305
|
summary: General http client functionality to quickly connect to JSON REST API endpoints
|
|
278
306
|
and any others
|