quiz_api_client 4.6.0 → 4.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbda532d39d3bc76cb64465b5e393d150a469448b9747f5556a0e09f0ccb70cd
4
- data.tar.gz: dc2b0545c2b6b7b031fdec7e9fcf084cb69ab897444521fabd62944cfd38e70a
3
+ metadata.gz: 75b8beea94a5e16f60fd8f37f34e952b6fe7964178561e1d6e93a0c0a8fa7f93
4
+ data.tar.gz: 43eaa7a546489ceaa98c9765357f70bdadb64da7348dfc6bdc7599da42b7ab43
5
5
  SHA512:
6
- metadata.gz: b12c35f7e25194b3e9aa20ecbdd4f9bdc835ba4f948f6659cc62dd360b0288629d4ccda99c65c8b0ba155573c26f0516f1395c5b5151dbc1da4cd30504136695
7
- data.tar.gz: 5547cc8b2d32ec019868f88e346285b6fb03b5ebe68bd1c1018aa278a658c38a4f7f76dd1f26aaa8cbb10767731210d94984850dd80077c48cfc6af08a4f41f6
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",
@@ -1,3 +1,3 @@
1
1
  module QuizApiClient
2
- VERSION = '4.6.0'.freeze
2
+ VERSION = '4.7.0'.freeze
3
3
  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.6.0
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-08 00:00:00.000000000 Z
18
+ date: 2023-02-14 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: httparty