quiz_api_client 4.14.0 → 4.14.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7df5e01555ce19ad84445f0287c640e0c2eb9873af3c88a6ad1432162ce228a
|
4
|
+
data.tar.gz: 04d758bf5007880147d0e4316b6d151821b904b0a84db0401b7b53b426d6791f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4e95a71d9e8853ae5a3ef251b6df743ee36ce1838be1bcdf7ab6675c6e85a800a5cb4a48a7f394b6094d6b9747ea90c5a1ff2942059991bd6a5f69306185043
|
7
|
+
data.tar.gz: 72c177b35fc78f784c0b26fa49d90c92bfc305539528b357e104864cf339cd870202c97710df4ca672e8d9505b96217be73039b313a4bec7bd244bffbd6c3c15
|
@@ -101,7 +101,7 @@ module QuizApiClient
|
|
101
101
|
rescue HTTParty::Error, Errno::ECONNREFUSED, Net::ReadTimeout => e
|
102
102
|
raise_error(method, url, current_error: e)
|
103
103
|
ensure
|
104
|
-
record_metrics(method,
|
104
|
+
record_metrics(method, resp, start_time, Time.now)
|
105
105
|
end
|
106
106
|
|
107
107
|
def make_paginated_request(method, url, options)
|
@@ -166,9 +166,9 @@ module QuizApiClient
|
|
166
166
|
failure.raise_error(method, url, response: response, current_error: current_error)
|
167
167
|
end
|
168
168
|
|
169
|
-
def record_metrics(method,
|
169
|
+
def record_metrics(method, resp, start_time, end_time)
|
170
170
|
code = resp&.code || 0
|
171
|
-
metrics = QuizApiClient::HttpRequest::Metrics.new(config, method,
|
171
|
+
metrics = QuizApiClient::HttpRequest::Metrics.new(config, method, code)
|
172
172
|
|
173
173
|
metrics.increment
|
174
174
|
metrics.duration(start_time, end_time)
|
@@ -3,13 +3,12 @@ module QuizApiClient
|
|
3
3
|
class Metrics
|
4
4
|
extend Forwardable
|
5
5
|
|
6
|
-
attr_reader :config, :method, :
|
6
|
+
attr_reader :config, :method, :code
|
7
7
|
def_delegators :config, :metrics_handler, :metrics_namespace
|
8
8
|
|
9
|
-
def initialize(config, method,
|
9
|
+
def initialize(config, method, code)
|
10
10
|
@config = config
|
11
11
|
@method = method
|
12
|
-
@url = url
|
13
12
|
@code = code
|
14
13
|
end
|
15
14
|
|
@@ -58,8 +57,7 @@ module QuizApiClient
|
|
58
57
|
def tags
|
59
58
|
{
|
60
59
|
method: method,
|
61
|
-
status: code
|
62
|
-
url: url
|
60
|
+
status: code
|
63
61
|
}
|
64
62
|
end
|
65
63
|
end
|
data/spec/http_client_spec.rb
CHANGED
@@ -41,9 +41,9 @@ describe QuizApiClient::HttpClient do
|
|
41
41
|
mock
|
42
42
|
end
|
43
43
|
|
44
|
-
def expect_metrics_calls(config, method,
|
44
|
+
def expect_metrics_calls(config, method, code)
|
45
45
|
expect(QuizApiClient::HttpRequest::Metrics).to receive(:new)
|
46
|
-
.with(config, method,
|
46
|
+
.with(config, method, code)
|
47
47
|
.and_return(mock_metrics(mock_time(10)))
|
48
48
|
end
|
49
49
|
|
@@ -65,7 +65,7 @@ describe QuizApiClient::HttpClient do
|
|
65
65
|
it 'makes a get request' do
|
66
66
|
path = '/api/quizzes'
|
67
67
|
stub_quiz_api path, query: { sort: 'alpha' }
|
68
|
-
expect_metrics_calls(client.config, :get,
|
68
|
+
expect_metrics_calls(client.config, :get, 200)
|
69
69
|
response = client.get(path, all: false, query: { sort: 'alpha' })
|
70
70
|
expect(response.parsed_response).to eq [1]
|
71
71
|
end
|
@@ -138,7 +138,7 @@ describe QuizApiClient::HttpClient do
|
|
138
138
|
body: { title: 'ohai' }.to_json,
|
139
139
|
**default_request_data
|
140
140
|
).and_return(instance_double('HTTParty::Response', success?: true, code: 200))
|
141
|
-
expect_metrics_calls(client.config, :post,
|
141
|
+
expect_metrics_calls(client.config, :post, 200)
|
142
142
|
client.post('/api/quizzes', title: 'ohai')
|
143
143
|
end
|
144
144
|
end
|
@@ -151,7 +151,7 @@ describe QuizApiClient::HttpClient do
|
|
151
151
|
body: { title: 'new title' }.to_json,
|
152
152
|
**default_request_data
|
153
153
|
).and_return(instance_double('HTTParty::Response', success?: true, code: 200))
|
154
|
-
expect_metrics_calls(client.config, :patch,
|
154
|
+
expect_metrics_calls(client.config, :patch, 200)
|
155
155
|
client.patch('/api/quizzes/1', title: 'new title')
|
156
156
|
end
|
157
157
|
end
|
@@ -164,7 +164,7 @@ describe QuizApiClient::HttpClient do
|
|
164
164
|
body: { title: 'new title' }.to_json,
|
165
165
|
**default_request_data
|
166
166
|
).and_return(instance_double('HTTParty::Response', success?: true, code: 200))
|
167
|
-
expect_metrics_calls(client.config, :put,
|
167
|
+
expect_metrics_calls(client.config, :put, 200)
|
168
168
|
client.put('/api/quizzes/1', title: 'new title')
|
169
169
|
end
|
170
170
|
end
|
@@ -176,7 +176,7 @@ describe QuizApiClient::HttpClient do
|
|
176
176
|
url,
|
177
177
|
**default_request_data
|
178
178
|
).and_return(instance_double('HTTParty::Response', success?: true, code: 200))
|
179
|
-
expect_metrics_calls(client.config, :delete,
|
179
|
+
expect_metrics_calls(client.config, :delete, 200)
|
180
180
|
client.delete('/api/quizzes/1')
|
181
181
|
end
|
182
182
|
end
|
@@ -277,7 +277,7 @@ describe QuizApiClient::HttpClient do
|
|
277
277
|
it 'raises error' do
|
278
278
|
expect(client).to receive(:successful_response?).with(mock_response).and_return(false)
|
279
279
|
expect(client.class).to receive(:get).and_return(mock_response)
|
280
|
-
expect_metrics_calls(client.config, method,
|
280
|
+
expect_metrics_calls(client.config, method, code)
|
281
281
|
expect_raise_error_call(client.config, method, url_for_path(path), mock_response, nil)
|
282
282
|
expect { client.get(path, all: false, query: { sort: 'alpha' }) }
|
283
283
|
.to raise_error(QuizApiClient::HttpClient::RequestFailed)
|
@@ -290,7 +290,7 @@ describe QuizApiClient::HttpClient do
|
|
290
290
|
it 'raises error' do
|
291
291
|
expect(client).to receive(:successful_response?).with(mock_response).and_return(false)
|
292
292
|
expect(client.class).to receive(:post).and_return(mock_response)
|
293
|
-
expect_metrics_calls(client.config, method,
|
293
|
+
expect_metrics_calls(client.config, method, code)
|
294
294
|
expect_raise_error_call(client.config, method, url_for_path(path), mock_response, nil)
|
295
295
|
expect { client.post(path) }.to raise_error(QuizApiClient::HttpClient::RequestFailed)
|
296
296
|
end
|
@@ -302,7 +302,7 @@ describe QuizApiClient::HttpClient do
|
|
302
302
|
it 'raises error' do
|
303
303
|
expect(client).to receive(:successful_response?).with(mock_response).and_return(false)
|
304
304
|
expect(client.class).to receive(:put).and_return(mock_response)
|
305
|
-
expect_metrics_calls(client.config, method,
|
305
|
+
expect_metrics_calls(client.config, method, code)
|
306
306
|
expect_raise_error_call(client.config, method, url_for_path(path), mock_response, nil)
|
307
307
|
expect { client.put(path) }.to raise_error(QuizApiClient::HttpClient::RequestFailed)
|
308
308
|
end
|
@@ -314,7 +314,7 @@ describe QuizApiClient::HttpClient do
|
|
314
314
|
it 'raises error' do
|
315
315
|
expect(client).to receive(:successful_response?).with(mock_response).and_return(false)
|
316
316
|
expect(client.class).to receive(:patch).and_return(mock_response)
|
317
|
-
expect_metrics_calls(client.config, method,
|
317
|
+
expect_metrics_calls(client.config, method, code)
|
318
318
|
expect_raise_error_call(client.config, method, url_for_path(path), mock_response, nil)
|
319
319
|
expect { client.patch(path) }.to raise_error(QuizApiClient::HttpClient::RequestFailed)
|
320
320
|
end
|
@@ -326,7 +326,7 @@ describe QuizApiClient::HttpClient do
|
|
326
326
|
it 'raises error' do
|
327
327
|
expect(client).to receive(:successful_response?).with(mock_response).and_return(false)
|
328
328
|
expect(client.class).to receive(:delete).and_return(mock_response)
|
329
|
-
expect_metrics_calls(client.config, method,
|
329
|
+
expect_metrics_calls(client.config, method, code)
|
330
330
|
expect_raise_error_call(client.config, method, url_for_path(path), mock_response, nil)
|
331
331
|
expect { client.delete(path) }.to raise_error(QuizApiClient::HttpClient::RequestFailed)
|
332
332
|
end
|
@@ -348,21 +348,21 @@ describe QuizApiClient::HttpClient do
|
|
348
348
|
|
349
349
|
it 'handles an HTTParty::Error error' do
|
350
350
|
stub_request(:get, url).to_raise(HTTParty::Error)
|
351
|
-
expect_metrics_calls(client.config, :get,
|
351
|
+
expect_metrics_calls(client.config, :get, 0)
|
352
352
|
expect_raise_error_call(client.config, :get, url_for_path(path), nil, kind_of(HTTParty::Error))
|
353
353
|
expect { client.get('/') }.to raise_error(QuizApiClient::HttpClient::RequestFailed)
|
354
354
|
end
|
355
355
|
|
356
356
|
it 'handles an Errno::ECONNREFUSED error' do
|
357
357
|
stub_request(:get, url).to_raise(Errno::ECONNREFUSED)
|
358
|
-
expect_metrics_calls(client.config, :get,
|
358
|
+
expect_metrics_calls(client.config, :get, 0)
|
359
359
|
expect_raise_error_call(client.config, :get, url_for_path(path), nil, kind_of(Errno::ECONNREFUSED))
|
360
360
|
expect { client.get('/') }.to raise_error(QuizApiClient::HttpClient::RequestFailed)
|
361
361
|
end
|
362
362
|
|
363
363
|
it 'handles an Net::ReadTimeout error' do
|
364
364
|
stub_request(:get, url).to_raise(Net::ReadTimeout)
|
365
|
-
expect_metrics_calls(client.config, :get,
|
365
|
+
expect_metrics_calls(client.config, :get, 0)
|
366
366
|
expect_raise_error_call(client.config, :get, url_for_path(path), nil, kind_of(Net::ReadTimeout))
|
367
367
|
expect { client.get('/') }.to raise_error(QuizApiClient::HttpClient::RequestFailed)
|
368
368
|
end
|
@@ -3,10 +3,9 @@ require 'inst_statsd'
|
|
3
3
|
describe QuizApiClient::HttpRequest::Metrics do
|
4
4
|
let(:config) { QuizApiClient::Config.new }
|
5
5
|
let(:method) { 'GET' }
|
6
|
-
let(:url) { 'https://something.com' }
|
7
6
|
let(:code) { 200 }
|
8
7
|
|
9
|
-
subject { described_class.new(config, method,
|
8
|
+
subject { described_class.new(config, method, code) }
|
10
9
|
|
11
10
|
describe '#increment' do
|
12
11
|
it 'does nothing when the metrics handler is nil' do
|
@@ -29,8 +28,7 @@ describe QuizApiClient::HttpRequest::Metrics do
|
|
29
28
|
'fake-namespace.quiz_api_client.request.count',
|
30
29
|
tags: {
|
31
30
|
method: method,
|
32
|
-
status: code
|
33
|
-
url: url
|
31
|
+
status: code
|
34
32
|
}
|
35
33
|
)
|
36
34
|
|
@@ -64,8 +62,7 @@ describe QuizApiClient::HttpRequest::Metrics do
|
|
64
62
|
duration_in_secs * 1_000,
|
65
63
|
tags: {
|
66
64
|
method: method,
|
67
|
-
status: code
|
68
|
-
url: url
|
65
|
+
status: code
|
69
66
|
}
|
70
67
|
)
|
71
68
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quiz_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.14.
|
4
|
+
version: 4.14.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Slaughter
|
@@ -15,7 +15,7 @@ authors:
|
|
15
15
|
autorequire:
|
16
16
|
bindir: exe
|
17
17
|
cert_chain: []
|
18
|
-
date:
|
18
|
+
date: 2024-02-22 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: httparty
|