quiz_api_client 4.6.0 → 4.7.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/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/spec/services/items_service_spec.rb +26 -0
- data/spec/services/quiz_entries_service_spec.rb +51 -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: 75b8beea94a5e16f60fd8f37f34e952b6fe7964178561e1d6e93a0c0a8fa7f93
|
4
|
+
data.tar.gz: 43eaa7a546489ceaa98c9765357f70bdadb64da7348dfc6bdc7599da42b7ab43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffd1d5bb30fb3136429a3031aa847aa0fe9dd58c38a071f00c88e90ee37c8f56a0870cfc9cfb209fc8b1c24b6525cd38f57a891c922473b816305d62a64e3185
|
7
|
+
data.tar.gz: 369fb4ddd2ebf9151d86637d6b2991e82e926fb0b9952854f86be2623c362361154e80e355c615717ab25e3b360a25442e3ada1253074f1e57f9eba8867567c7
|
@@ -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",
|
@@ -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.7.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-14 00:00:00.000000000 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: httparty
|