quiz_api_client 4.6.0 → 4.8.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/content_exports_service.rb +16 -0
- data/lib/quiz_api_client/services/items_service.rb +17 -0
- data/lib/quiz_api_client/services/quiz_entries_service.rb +27 -0
- data/lib/quiz_api_client/version.rb +1 -1
- data/lib/quiz_api_client.rb +5 -0
- data/spec/quiz_api_client_spec.rb +7 -0
- data/spec/services/content_exports_service_spec.rb +50 -0
- data/spec/services/items_service_spec.rb +26 -0
- data/spec/services/quiz_entries_service_spec.rb +51 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 057d0dea94cbf0a0781d3c8144906a8ea7b29790f278f4d4a55891aaf6c3a12b
|
4
|
+
data.tar.gz: c5241135784c367e250fe0fb0a1e6012fc391c2a9d09c1225173f1acfbb3a595
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89212f479d1081e38ad2005e5f7b84a4c3c5088b1620c6673cc2538fa719ed73f9eba1df31c5bca786c0efa4c3755d9e5bcd37e2508e7aaec73ee8ad41b1bdc4
|
7
|
+
data.tar.gz: b2be42851612a9fae066ff5dcfdd322e6d66d821ddd03fa53083e8713e90c8d4ad780de177c4f13752919897ffc0e720e8b8aa2db98f27e159c73e3f64e9cd2f
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module QuizApiClient::Services
|
2
|
+
class ContentExportsService < BaseApiService
|
3
|
+
def create(params:, token: nil)
|
4
|
+
post_to_quiz_api(params: params, token: token)
|
5
|
+
end
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def post_to_quiz_api(params:, token:)
|
10
|
+
client(token: token).post(
|
11
|
+
'/api/content_exports',
|
12
|
+
content_export: params
|
13
|
+
)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -12,6 +12,13 @@ module QuizApiClient::Services
|
|
12
12
|
post_to_quiz_api(params: params, token: token)
|
13
13
|
end
|
14
14
|
|
15
|
+
def update(params:, token: nil)
|
16
|
+
raise 'Quiz Id Required' unless params && params[:quiz_id]
|
17
|
+
raise 'Item Id Required' unless params && params[:item_id]
|
18
|
+
|
19
|
+
put_to_quiz_api(params: params, token: token)
|
20
|
+
end
|
21
|
+
|
15
22
|
private
|
16
23
|
|
17
24
|
def list_from_quiz_api(params:, token:)
|
@@ -27,5 +34,15 @@ module QuizApiClient::Services
|
|
27
34
|
item: params
|
28
35
|
)
|
29
36
|
end
|
37
|
+
|
38
|
+
def put_to_quiz_api(params:, token:)
|
39
|
+
quiz_id = params.delete(:quiz_id)
|
40
|
+
item_id = params.delete(:item_id)
|
41
|
+
client(token: token).put(
|
42
|
+
"/api/quizzes/#{quiz_id}/items/#{item_id}",
|
43
|
+
quiz_id: quiz_id,
|
44
|
+
item: params
|
45
|
+
)
|
46
|
+
end
|
30
47
|
end
|
31
48
|
end
|
@@ -1,11 +1,25 @@
|
|
1
1
|
module QuizApiClient::Services
|
2
2
|
class QuizEntriesService < BaseApiService
|
3
|
+
def show(params:, token: nil)
|
4
|
+
raise 'Quiz Id Required' unless params && params[:quiz_id]
|
5
|
+
raise 'Entry Id Required' unless params[:entry_id]
|
6
|
+
|
7
|
+
get_single_entry_from_quiz_api(params: params, token: token)
|
8
|
+
end
|
9
|
+
|
3
10
|
def create(params:, token: nil)
|
4
11
|
raise 'Quiz Id Required' unless params && params[:id]
|
5
12
|
|
6
13
|
post_to_quiz_api(params: params, token: token)
|
7
14
|
end
|
8
15
|
|
16
|
+
def update(params:, token: nil)
|
17
|
+
raise 'Quiz Id Required' unless params && params[:quiz_id]
|
18
|
+
raise 'Entry Id Required' unless params[:entry_id]
|
19
|
+
|
20
|
+
put_to_quiz_api(params: params, token: token)
|
21
|
+
end
|
22
|
+
|
9
23
|
def list(params:, token: nil, all: false)
|
10
24
|
raise 'Quiz Id Required' unless params && params[:id]
|
11
25
|
|
@@ -21,6 +35,12 @@ module QuizApiClient::Services
|
|
21
35
|
|
22
36
|
private
|
23
37
|
|
38
|
+
def get_single_entry_from_quiz_api(params:, token:)
|
39
|
+
client(token: token).get(
|
40
|
+
"/api/quizzes/#{params[:quiz_id]}/quiz_entries/#{params[:entry_id]}"
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
24
44
|
def post_to_quiz_api(params:, token:)
|
25
45
|
client(token: token).post(
|
26
46
|
"/api/quizzes/#{params[:id]}/quiz_entries",
|
@@ -28,6 +48,13 @@ module QuizApiClient::Services
|
|
28
48
|
)
|
29
49
|
end
|
30
50
|
|
51
|
+
def put_to_quiz_api(params:, token:)
|
52
|
+
client(token: token).put(
|
53
|
+
"/api/quizzes/#{params[:quiz_id]}/quiz_entries/#{params[:entry_id]}",
|
54
|
+
quiz_entry: params
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
31
58
|
def get_from_quiz_api(params:, token:, all:)
|
32
59
|
client(token: token).get(
|
33
60
|
"/api/quizzes/#{params[:id]}/quiz_entries",
|
data/lib/quiz_api_client.rb
CHANGED
@@ -22,6 +22,10 @@ module QuizApiClient
|
|
22
22
|
@_config ||= QuizApiClient::Config.new
|
23
23
|
end
|
24
24
|
|
25
|
+
def content_exports_service
|
26
|
+
@_content_exports_service ||= Services::ContentExportsService.new(config)
|
27
|
+
end
|
28
|
+
|
25
29
|
def courses_service
|
26
30
|
@_courses_service ||= Services::CoursesService.new(config)
|
27
31
|
end
|
@@ -118,6 +122,7 @@ require 'quiz_api_client/http_request/metrics'
|
|
118
122
|
require 'quiz_api_client/services/jwt_service'
|
119
123
|
require 'quiz_api_client/services/base_api_service'
|
120
124
|
|
125
|
+
require 'quiz_api_client/services/content_exports_service'
|
121
126
|
require 'quiz_api_client/services/courses_service'
|
122
127
|
require 'quiz_api_client/services/interaction_types_service'
|
123
128
|
require 'quiz_api_client/services/item_analyses_service'
|
@@ -51,6 +51,13 @@ describe QuizApiClient do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
describe '#content_exports_service' do
|
55
|
+
it 'creates the service' do
|
56
|
+
expect(QuizApiClient::Services::ContentExportsService).to receive(:new).with(subject.config)
|
57
|
+
subject.content_exports_service
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
54
61
|
describe '#courses_service' do
|
55
62
|
it 'creates the service' do
|
56
63
|
expect(QuizApiClient::Services::CoursesService).to receive(:new).with(subject.config)
|
@@ -0,0 +1,50 @@
|
|
1
|
+
describe QuizApiClient::Services::ContentExportsService do
|
2
|
+
let(:host) { 'api.host' }
|
3
|
+
let(:config) { QuizApiClient::Config.new { |c| c.host = host } }
|
4
|
+
let(:subject) { described_class.new(config) }
|
5
|
+
|
6
|
+
describe '#create' do
|
7
|
+
let(:params) do
|
8
|
+
{
|
9
|
+
canvas_content_export_id: 1234,
|
10
|
+
export_settings: {
|
11
|
+
quizzes: [10, 11],
|
12
|
+
everything: false,
|
13
|
+
content_export_type: 'qti'
|
14
|
+
}
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:response) do
|
19
|
+
{
|
20
|
+
'id' => '1',
|
21
|
+
'canvas_content_export_id' => '1234',
|
22
|
+
'export_settings' => {
|
23
|
+
'quizzes' => [10, 11],
|
24
|
+
'everything' => false,
|
25
|
+
'content_export_type' => 'qti'
|
26
|
+
},
|
27
|
+
'created_at' => '2023-02-17T01:00:00.000Z',
|
28
|
+
'updated_at' => '2023-02-17T01:00:00.000Z'
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:expected_url) { "https://#{host}/api/content_exports" }
|
33
|
+
|
34
|
+
before do
|
35
|
+
stub_request(:post, expected_url)
|
36
|
+
.with(body: { content_export: params }.to_json)
|
37
|
+
.to_return(
|
38
|
+
status: 201,
|
39
|
+
body: response.to_json,
|
40
|
+
headers: { 'Content-Type' => 'application/json' }
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'posts to the correct endpoint and returns the response' do
|
45
|
+
expect(
|
46
|
+
subject.create(params: params, token: 'token').parsed_response
|
47
|
+
).to eq(response)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -53,4 +53,30 @@ describe QuizApiClient::Services::ItemsService do
|
|
53
53
|
expect(result.parsed_response).to eql(stubbed_response)
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
describe '#update' do
|
58
|
+
let(:params) { { quiz_id: 1, item_id: 1, item: { item_body: 'item body' } } }
|
59
|
+
let(:stubbed_response) { { 'item' => { 'id' => 1 } } }
|
60
|
+
let(:expected_url) { "https://#{host}/api/quizzes/#{params[:quiz_id]}/items/#{params[:item_id]}" }
|
61
|
+
let(:status_code) { 200 }
|
62
|
+
|
63
|
+
before do
|
64
|
+
stub_request(:put, expected_url)
|
65
|
+
.to_return(
|
66
|
+
status: status_code,
|
67
|
+
body: stubbed_response.to_json,
|
68
|
+
headers: { 'Content-Type' => 'application/json' }
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'puts to quiz_api/api/quizzes/{quiz_id}/items/{item_id} and returns the response' do
|
73
|
+
result = subject.update(params: params, token: 'token')
|
74
|
+
expect(result.parsed_response).to eql(stubbed_response)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'raises errors on missing ids' do
|
78
|
+
expect { subject.update(params: {}, token: 'token') }.to raise_error('Quiz Id Required')
|
79
|
+
expect { subject.update(params: { quiz_id: 1 }, token: 'token') }.to raise_error('Item Id Required')
|
80
|
+
end
|
81
|
+
end
|
56
82
|
end
|
@@ -24,6 +24,32 @@ describe QuizApiClient::Services::QuizEntriesService do
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
describe '#show' do
|
28
|
+
let(:params) { { quiz_id: 1, entry_id: 1 } }
|
29
|
+
let(:stubbed_response) { { 'id' => 1, 'entry' => { 'id' => 1 } } }
|
30
|
+
let(:expected_url) { "https://#{host}/api/quizzes/#{params[:quiz_id]}/quiz_entries/#{params[:entry_id]}" }
|
31
|
+
let(:status_code) { 200 }
|
32
|
+
|
33
|
+
before do
|
34
|
+
stub_request(:get, expected_url)
|
35
|
+
.to_return(
|
36
|
+
status: status_code,
|
37
|
+
body: stubbed_response.to_json,
|
38
|
+
headers: { 'Content-Type' => 'application/json' }
|
39
|
+
)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'gets from quiz_api/api/quizzes/{quiz_id}/quiz_entries/{entry_id} and returns the response' do
|
43
|
+
result = subject.show(params: params, token: 'token')
|
44
|
+
expect(result.parsed_response).to eql(stubbed_response)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'raises errors on missing ids' do
|
48
|
+
expect { subject.update(params: {}, token: 'token') }.to raise_error('Quiz Id Required')
|
49
|
+
expect { subject.update(params: { quiz_id: 1 }, token: 'token') }.to raise_error('Entry Id Required')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
27
53
|
describe '#create' do
|
28
54
|
let(:params) do
|
29
55
|
{ id: 1, entry_id: 1, entry_type: 'Item', points_possible: 1 }
|
@@ -47,6 +73,31 @@ describe QuizApiClient::Services::QuizEntriesService do
|
|
47
73
|
end
|
48
74
|
end
|
49
75
|
|
76
|
+
describe '#update' do
|
77
|
+
let(:params) { { quiz_id: 1, entry_id: 1, points_possible: 1 } }
|
78
|
+
let(:stubbed_response) { { 'id' => 1, 'entry' => { 'id' => 1 } } }
|
79
|
+
let(:expected_url) { "https://#{host}/api/quizzes/#{params[:quiz_id]}/quiz_entries/#{params[:entry_id]}" }
|
80
|
+
let(:status_code) { 200 }
|
81
|
+
before do
|
82
|
+
stub_request(:put, expected_url)
|
83
|
+
.to_return(
|
84
|
+
status: status_code,
|
85
|
+
body: stubbed_response.to_json,
|
86
|
+
headers: { 'Content-Type' => 'application/json' }
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'puts to quiz_api/api/quizzes/{quiz_id}/quiz_entries/{entry_id} and returns the response' do
|
91
|
+
result = subject.update(params: params, token: 'token')
|
92
|
+
expect(result.parsed_response).to eql(stubbed_response)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'raises errors on missing ids' do
|
96
|
+
expect { subject.update(params: {}, token: 'token') }.to raise_error('Quiz Id Required')
|
97
|
+
expect { subject.update(params: { quiz_id: 1 }, token: 'token') }.to raise_error('Entry Id Required')
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
50
101
|
describe '#destroy' do
|
51
102
|
let(:params) do
|
52
103
|
{ id: 6, quiz_id: 1 }
|
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.8.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: 2023-02-
|
18
|
+
date: 2023-02-24 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: httparty
|
@@ -180,6 +180,7 @@ files:
|
|
180
180
|
- lib/quiz_api_client/http_request/metrics.rb
|
181
181
|
- lib/quiz_api_client/json_formatter.rb
|
182
182
|
- lib/quiz_api_client/services/base_api_service.rb
|
183
|
+
- lib/quiz_api_client/services/content_exports_service.rb
|
183
184
|
- lib/quiz_api_client/services/courses_service.rb
|
184
185
|
- lib/quiz_api_client/services/interaction_types_service.rb
|
185
186
|
- lib/quiz_api_client/services/item_analyses_service.rb
|
@@ -209,6 +210,7 @@ files:
|
|
209
210
|
- spec/quiz_api_client/http_request/metrics_spec.rb
|
210
211
|
- spec/quiz_api_client_spec.rb
|
211
212
|
- spec/services/base_api_service_spec.rb
|
213
|
+
- spec/services/content_exports_service_spec.rb
|
212
214
|
- spec/services/courses_service_spec.rb
|
213
215
|
- spec/services/interaction_types_service_spec.rb
|
214
216
|
- spec/services/item_analyses_service_spec.rb
|
@@ -260,6 +262,7 @@ test_files:
|
|
260
262
|
- spec/quiz_api_client/http_request/metrics_spec.rb
|
261
263
|
- spec/quiz_api_client_spec.rb
|
262
264
|
- spec/services/base_api_service_spec.rb
|
265
|
+
- spec/services/content_exports_service_spec.rb
|
263
266
|
- spec/services/courses_service_spec.rb
|
264
267
|
- spec/services/interaction_types_service_spec.rb
|
265
268
|
- spec/services/item_analyses_service_spec.rb
|