quiz_api_client 4.14.0 → 4.15.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/quiz_api_client/http_client.rb +3 -3
- data/lib/quiz_api_client/http_request/metrics.rb +3 -5
- data/lib/quiz_api_client/services/items_service.rb +15 -0
- data/lib/quiz_api_client/version.rb +1 -1
- data/spec/http_client_spec.rb +15 -15
- data/spec/quiz_api_client/http_request/metrics_spec.rb +3 -6
- data/spec/services/items_service_spec.rb +28 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cadaa3edf6975cbdb4b9281124426254a17d49125d7f3a9342e872b826a132c7
|
4
|
+
data.tar.gz: 73a3bf7743d64540340f09c638aa8cfa8b4125142da6205036b5c6b55b698c0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb0e0a4aad300a2073ab6d534ce201e944bfbfd24280f11509603ac8b81d7c747d175c0408a126c58dec1a326c2715c8cb1e33281d622eeef0a8b52b7e151f66
|
7
|
+
data.tar.gz: 19693517278da57fd622f017e590f8d5081aa4f51c8864545230377bfa53ff44d8cbd1ce85d821b0b3ef8477f1e3e948b844e8db3548ec577840c00c9475541d
|
@@ -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
|
@@ -25,6 +25,12 @@ module QuizApiClient::Services
|
|
25
25
|
get_media_upload_url_from_quiz_api(params: params, token: token)
|
26
26
|
end
|
27
27
|
|
28
|
+
def bulk_update_item_alignments(params:, token:)
|
29
|
+
raise 'Quiz Id Required' unless params && params[:quiz_id]
|
30
|
+
|
31
|
+
put_bulk_item_outcome_alignments_update(params: params, token: token)
|
32
|
+
end
|
33
|
+
|
28
34
|
private
|
29
35
|
|
30
36
|
def list_from_quiz_api(params:, token:)
|
@@ -55,5 +61,14 @@ module QuizApiClient::Services
|
|
55
61
|
quiz_id = params.delete(:quiz_id)
|
56
62
|
client(token: token).get("/api/quizzes/#{quiz_id}/items/media_upload_url")
|
57
63
|
end
|
64
|
+
|
65
|
+
def put_bulk_item_outcome_alignments_update(params:, token:)
|
66
|
+
quiz_id = params.delete(:quiz_id)
|
67
|
+
client(token: token).put(
|
68
|
+
"/api/quizzes/#{quiz_id}/items/update_outcome_alignments",
|
69
|
+
quiz_id: quiz_id,
|
70
|
+
items: params
|
71
|
+
)
|
72
|
+
end
|
58
73
|
end
|
59
74
|
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
|
|
@@ -100,4 +100,32 @@ describe QuizApiClient::Services::ItemsService do
|
|
100
100
|
expect(result.parsed_response).to eql(stubbed_response)
|
101
101
|
end
|
102
102
|
end
|
103
|
+
|
104
|
+
describe '#update_outcome_alignments' do
|
105
|
+
let(:put_url) { "https://#{host}/api/quizzes/1/items/update_outcome_alignments" }
|
106
|
+
let(:params) do
|
107
|
+
{
|
108
|
+
items: [
|
109
|
+
{ item_id: 1, outcome_alignment_set_guid: '29d04bab-e499-498b-ae47-bcc6a80ed924' },
|
110
|
+
{ item_id: 2, outcome_alignment_set_guid: 'f9d5002d-7ef5-4341-bf16-471a83a32add' }
|
111
|
+
],
|
112
|
+
quiz_id: 1
|
113
|
+
}
|
114
|
+
end
|
115
|
+
it 'returns status ok' do
|
116
|
+
stub_request(:put, put_url)
|
117
|
+
.to_return(
|
118
|
+
status: 200,
|
119
|
+
headers: { 'Content-Type' => 'application/json' }
|
120
|
+
)
|
121
|
+
result = subject.bulk_update_item_alignments(params: params, token: 'token')
|
122
|
+
|
123
|
+
expect(result.code).to eql(200)
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'raise error for missing quiz_id parameter' do
|
127
|
+
params.delete(:quiz_id)
|
128
|
+
expect { subject.bulk_update_item_alignments(params: p, token: 'token') }.to raise_error('Quiz Id Required')
|
129
|
+
end
|
130
|
+
end
|
103
131
|
end
|
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.
|
4
|
+
version: 4.15.0
|
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-03-28 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: httparty
|