quiz_api_client 4.19.0 → 4.21.0
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/lib/quiz_api_client/services/analyses_service.rb +7 -3
- data/lib/quiz_api_client/services/quizzes_service.rb +12 -0
- data/lib/quiz_api_client/version.rb +1 -1
- data/spec/services/analyses_service_spec.rb +121 -50
- data/spec/services/quizzes_service_spec.rb +38 -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: 1163e85cb5fd4c258330d4d8a6fdd298e6a252bc453b28ca7f3a02cbfb06b968
|
4
|
+
data.tar.gz: 230852d9477251d2b97a49a3ab5b7f84bdc96505e9636d01f1257859c3641d80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d550ce6a725dc72a605a4ef037662143d553cc6ac2ea47411e1739abdf32f3e3e1a61f24e80c00755aafaad0c410df753f26cd83e90b4efca241ed5a9a91812
|
7
|
+
data.tar.gz: ca76400aee18a66010e821cb3b4a3e8b720f69106031445da5dbdb1851f9bf7d2976683c4a711d3ae762e288576d5ae06fbfd643393f41afc8070b330dd0bbf4
|
@@ -15,26 +15,30 @@ module QuizApiClient::Services
|
|
15
15
|
def show(params:, token: nil)
|
16
16
|
client(token: token).get(
|
17
17
|
"/api/quizzes/#{params[:quiz_id]}/reports/#{params[:id]}",
|
18
|
-
query: { filter:
|
18
|
+
query: { filter: filter_value(params) }
|
19
19
|
)
|
20
20
|
end
|
21
21
|
|
22
22
|
def export(params:, token: nil)
|
23
23
|
client(token: token).get(
|
24
24
|
"/api/quizzes/#{params[:quiz_id]}/analyses/export",
|
25
|
-
query: { filter:
|
25
|
+
query: { filter: filter_value(params), format: :csv, analysis_type: params[:analysis_type] }
|
26
26
|
)
|
27
27
|
end
|
28
28
|
|
29
29
|
def status(params:, token: nil)
|
30
30
|
client(token: token).get(
|
31
31
|
"/api/quizzes/#{params[:quiz_id]}/analyses/status",
|
32
|
-
query: { filter:
|
32
|
+
query: { filter: filter_value(params), analysis_type: params[:analysis_type] }
|
33
33
|
)
|
34
34
|
end
|
35
35
|
|
36
36
|
private
|
37
37
|
|
38
|
+
def filter_value(params)
|
39
|
+
params[:filter] || :last_attempt
|
40
|
+
end
|
41
|
+
|
38
42
|
def post_to_create_report(params:, token:)
|
39
43
|
path = "/api/quizzes/#{params[:quiz_id]}/analyses/create_report"
|
40
44
|
post_to_quiz_api(path: path, params: params, token: token)
|
@@ -8,6 +8,10 @@ module QuizApiClient::Services
|
|
8
8
|
get_from_quiz_api(params: params, token: token, all: all)
|
9
9
|
end
|
10
10
|
|
11
|
+
def quiz_question_counts(params:, token: nil, all: false)
|
12
|
+
get_quiz_question_counts(params: params, token: token, all: all)
|
13
|
+
end
|
14
|
+
|
11
15
|
private
|
12
16
|
|
13
17
|
def post_to_quiz_api(params:, token:)
|
@@ -24,5 +28,13 @@ module QuizApiClient::Services
|
|
24
28
|
query: params
|
25
29
|
)
|
26
30
|
end
|
31
|
+
|
32
|
+
def get_quiz_question_counts(params:, token:, all:)
|
33
|
+
client(token: token).get(
|
34
|
+
'/api/quizzes/question_count',
|
35
|
+
all: all,
|
36
|
+
query: params
|
37
|
+
)
|
38
|
+
end
|
27
39
|
end
|
28
40
|
end
|
@@ -58,81 +58,152 @@ describe QuizApiClient::Services::AnalysesService do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
describe '#show' do
|
61
|
-
let(:params)
|
62
|
-
{ quiz_id: 1, id: 2 }
|
63
|
-
end
|
61
|
+
let(:params) { { quiz_id: 1, id: 2 } }
|
64
62
|
let(:stubbed_response) { { 'id' => 1 } }
|
65
|
-
let(:expected_url) { "https://#{host}/api/quizzes/#{params[:quiz_id]}/reports/#{params[:id]}?filter=last_attempt" }
|
66
63
|
let(:status_code) { 200 }
|
67
64
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
)
|
65
|
+
context 'when filter is last_attempt' do
|
66
|
+
let(:expected_url) do
|
67
|
+
"https://#{host}/api/quizzes/#{params[:quiz_id]}/reports/#{params[:id]}?filter=last_attempt"
|
68
|
+
end
|
69
|
+
|
70
|
+
before do
|
71
|
+
stub_request(:get, expected_url)
|
72
|
+
.to_return(
|
73
|
+
status: status_code,
|
74
|
+
body: stubbed_response.to_json,
|
75
|
+
headers: { 'Content-Type' => 'application/json' }
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'returns the last_attempt report' do
|
80
|
+
result = subject.show(params: params.merge(filter: 'last_attempt'), token: 'token')
|
81
|
+
expect(result.parsed_response).to eql(stubbed_response)
|
82
|
+
end
|
75
83
|
end
|
76
84
|
|
77
|
-
|
78
|
-
|
79
|
-
|
85
|
+
context 'when filter is all_attempts' do
|
86
|
+
let(:expected_url) do
|
87
|
+
"https://#{host}/api/quizzes/#{params[:quiz_id]}/reports/#{params[:id]}?filter=all_attempts"
|
88
|
+
end
|
89
|
+
|
90
|
+
before do
|
91
|
+
stub_request(:get, expected_url)
|
92
|
+
.to_return(
|
93
|
+
status: status_code,
|
94
|
+
body: stubbed_response.to_json,
|
95
|
+
headers: { 'Content-Type' => 'application/json' }
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'returns the all_attempts report' do
|
100
|
+
result = subject.show(params: params.merge(filter: 'all_attempts'), token: 'token')
|
101
|
+
expect(result.parsed_response).to eql(stubbed_response)
|
102
|
+
end
|
80
103
|
end
|
81
104
|
end
|
82
105
|
|
83
|
-
describe 'status' do
|
84
|
-
let(:
|
85
|
-
{ quiz_id: 1, analysis_type: 'item_analysis' }
|
86
|
-
end
|
106
|
+
describe '#status' do
|
107
|
+
let(:base_params) { { quiz_id: 1, analysis_type: 'item_analysis' } }
|
87
108
|
let(:stubbed_response) { { 'id' => 1 } }
|
88
|
-
let(:expected_url) do
|
89
|
-
"https://#{host}/api/quizzes/#{params[:quiz_id]}/analyses/status?filter=last_attempt" +
|
90
|
-
+ "&analysis_type=#{params[:analysis_type]}"
|
91
|
-
end
|
92
109
|
let(:status_code) { 200 }
|
93
110
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
111
|
+
context 'when filter is last_attempt' do
|
112
|
+
let(:params) { base_params.merge(filter: 'last_attempt') }
|
113
|
+
let(:expected_url) do
|
114
|
+
"https://#{host}/api/quizzes/#{params[:quiz_id]}/analyses/status" \
|
115
|
+
"?filter=#{params[:filter]}&analysis_type=#{params[:analysis_type]}"
|
116
|
+
end
|
117
|
+
|
118
|
+
before do
|
119
|
+
stub_request(:get, expected_url)
|
120
|
+
.to_return(
|
121
|
+
status: status_code,
|
122
|
+
body: stubbed_response.to_json,
|
123
|
+
headers: { 'Content-Type' => 'application/json' }
|
124
|
+
)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'returns the last_attempt analysis status' do
|
128
|
+
result = subject.status(params: params, token: 'token')
|
129
|
+
expect(result.parsed_response).to eql(stubbed_response)
|
130
|
+
end
|
101
131
|
end
|
102
132
|
|
103
|
-
|
104
|
-
|
105
|
-
|
133
|
+
context 'when filter is all_attempts' do
|
134
|
+
let(:params) { base_params.merge(filter: 'all_attempts') }
|
135
|
+
let(:expected_url) do
|
136
|
+
"https://#{host}/api/quizzes/#{params[:quiz_id]}/analyses/status" \
|
137
|
+
"?filter=#{params[:filter]}&analysis_type=#{params[:analysis_type]}"
|
138
|
+
end
|
139
|
+
|
140
|
+
before do
|
141
|
+
stub_request(:get, expected_url)
|
142
|
+
.to_return(
|
143
|
+
status: status_code,
|
144
|
+
body: stubbed_response.to_json,
|
145
|
+
headers: { 'Content-Type' => 'application/json' }
|
146
|
+
)
|
147
|
+
end
|
148
|
+
|
149
|
+
it 'returns the all_attempts analysis status' do
|
150
|
+
result = subject.status(params: params, token: 'token')
|
151
|
+
expect(result.parsed_response).to eql(stubbed_response)
|
152
|
+
end
|
106
153
|
end
|
107
154
|
end
|
108
155
|
|
109
|
-
describe 'export' do
|
110
|
-
let(:
|
111
|
-
{ quiz_id: 1, analysis_type: 'item_analysis' }
|
112
|
-
end
|
156
|
+
describe '#export' do
|
157
|
+
let(:base_params) { { quiz_id: 1, analysis_type: 'item_analysis' } }
|
113
158
|
let(:stubbed_response) do
|
114
159
|
CSV.generate(headers: true) do |csv|
|
115
160
|
csv << %w[column1 column2 column3]
|
116
161
|
end
|
117
162
|
end
|
118
|
-
let(:expected_url) do
|
119
|
-
"https://#{host}/api/quizzes/#{params[:quiz_id]}/analyses/export" \
|
120
|
-
"?analysis_type=#{params[:analysis_type]}&filter=last_attempt&format=csv"
|
121
|
-
end
|
122
163
|
let(:status_code) { 200 }
|
123
164
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
165
|
+
context 'when filter is last_attempt' do
|
166
|
+
let(:params) { base_params.merge(filter: 'last_attempt') }
|
167
|
+
let(:expected_url) do
|
168
|
+
"https://#{host}/api/quizzes/#{params[:quiz_id]}/analyses/export" \
|
169
|
+
"?analysis_type=#{params[:analysis_type]}&filter=#{params[:filter]}&format=csv"
|
170
|
+
end
|
171
|
+
|
172
|
+
before do
|
173
|
+
stub_request(:get, expected_url)
|
174
|
+
.to_return(
|
175
|
+
status: status_code,
|
176
|
+
body: stubbed_response,
|
177
|
+
headers: { 'Content-Type' => 'text/csv' }
|
178
|
+
)
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'returns the last_attempt CSV export' do
|
182
|
+
result = subject.export(params: params, token: 'token')
|
183
|
+
expect(result.parsed_response).to eql([%w[column1 column2 column3]])
|
184
|
+
end
|
131
185
|
end
|
132
186
|
|
133
|
-
|
134
|
-
|
135
|
-
|
187
|
+
context 'when filter is all_attempts' do
|
188
|
+
let(:params) { base_params.merge(filter: 'all_attempts') }
|
189
|
+
let(:expected_url) do
|
190
|
+
"https://#{host}/api/quizzes/#{params[:quiz_id]}/analyses/export" \
|
191
|
+
"?analysis_type=#{params[:analysis_type]}&filter=#{params[:filter]}&format=csv"
|
192
|
+
end
|
193
|
+
|
194
|
+
before do
|
195
|
+
stub_request(:get, expected_url)
|
196
|
+
.to_return(
|
197
|
+
status: status_code,
|
198
|
+
body: stubbed_response,
|
199
|
+
headers: { 'Content-Type' => 'text/csv' }
|
200
|
+
)
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'returns the all_attempts CSV export' do
|
204
|
+
result = subject.export(params: params, token: 'token')
|
205
|
+
expect(result.parsed_response).to eql([%w[column1 column2 column3]])
|
206
|
+
end
|
136
207
|
end
|
137
208
|
end
|
138
209
|
|
@@ -68,4 +68,42 @@ describe QuizApiClient::Services::QuizzesService do
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
71
|
+
|
72
|
+
describe '#quiz_question_counts' do
|
73
|
+
let(:quiz_ids) { [1, 2, 3] }
|
74
|
+
let(:params) { { quiz_ids: quiz_ids } }
|
75
|
+
let(:stubbed_response) { { 'quiz_id' => '1', 'question_count' => 10 } }
|
76
|
+
|
77
|
+
context 'on success' do
|
78
|
+
before do
|
79
|
+
query_params = URI.encode_www_form(quiz_ids.map { |id| ['quiz_ids[]', id] })
|
80
|
+
expected_url = "https://#{host}/api/quizzes/question_count?#{query_params}"
|
81
|
+
stub_request(:get, expected_url)
|
82
|
+
.to_return(
|
83
|
+
status: 200,
|
84
|
+
body: [stubbed_response].to_json,
|
85
|
+
headers: { 'Content-Type' => 'application/json' }
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'gets quiz_api/api/quizzes/question_count and returns the response' do
|
90
|
+
result = subject.quiz_question_counts(params: params, token: 'token')
|
91
|
+
expect(result.parsed_response[0]).to eql(stubbed_response)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'on failure' do
|
96
|
+
let(:status_code) { 401 }
|
97
|
+
before do
|
98
|
+
expected_url = "https://#{host}/api/quizzes/question_count"
|
99
|
+
stub_request(:get, expected_url)
|
100
|
+
.to_return(status: status_code)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'returns the response with the correct code' do
|
104
|
+
response = subject.quiz_question_counts(params: nil, token: 'token')
|
105
|
+
expect(response.code).to eq(status_code)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
71
109
|
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.21.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: 2025-
|
18
|
+
date: 2025-05-06 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: httparty
|