quiz_api_client 4.13.2 → 4.13.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5a3731bc74410110bbb5ebcd49a1810b4609e77a39d0f415a66b2add1c588c83
4
- data.tar.gz: c00017a51dd925c73ec1f6a957ba830b2762a1da20ba949ff42090d244188f86
3
+ metadata.gz: f9c4a3c5a1a9c2363d383f497b8aaccfc1ba1fbde99e6481e911b46f69ff6972
4
+ data.tar.gz: 4edb45c0ced2efcb9f32c3d7ec1b0376f891dc8d5b9ec336ef61b5a992e30cc5
5
5
  SHA512:
6
- metadata.gz: 7c0b3d1876135ab671d33a9156d6c56ad7f51103691de92f6a093d91e5f1a1d01c160f5017585572afd88b2bd245df34e043ff8f1e3516b75e87a3e96344bdca
7
- data.tar.gz: d41fde3e160e5b9d57b242810ae29657183516e88586f1afb4a0c86f7171ee447603282b43058f3feb7aff8897c06c74cdf2adec23b0dfcdbb54c423a09e12e4
6
+ metadata.gz: 637eb311b402f08c22e4109be5e092366b08ae0fb9d5db049b8e186ad92bb965bb0ef0bff73e97b88096976e2d28148eb94d107d9c8ca9e5cdf1aed17f9bb3c5
7
+ data.tar.gz: 4bc454f39df1137b2f289bfd7e99217c0c2eff58c43981b26be2bf3802f2d3a1e03ebd0da015ba48a4b8f6858e3a52f450c3b28d8ef255df1686c5965fc0fbae
@@ -31,7 +31,7 @@ module QuizApiClient
31
31
  def get(path, all: false, query: {})
32
32
  return make_request :get, url_for(path), query: query unless all
33
33
 
34
- make_paginated_request :get, url_for(path), query: query
34
+ make_paginated_request :get, url_for(path), query: sanitized_query(query, all)
35
35
  end
36
36
 
37
37
  def post(path, body = {})
@@ -52,6 +52,14 @@ module QuizApiClient
52
52
 
53
53
  private
54
54
 
55
+ def sanitized_query(query, all)
56
+ query.delete(:page) if query.key?(:page) && query[:page].nil? || all
57
+
58
+ query.delete(:per_page) if query.key?(:per_page) && query[:per_page].nil?
59
+
60
+ query
61
+ end
62
+
55
63
  def initialize_logger(log_level)
56
64
  HTTParty::Logger.add_formatter('quiz_api_client_json_formatter', QuizApiClient::JSONFormatter)
57
65
  @logger = ::Logger.new(
@@ -7,7 +7,10 @@ module QuizApiClient::Services
7
7
  def show(params:, token: nil)
8
8
  raise 'Quiz Session Id Required' unless params && params[:id]
9
9
 
10
- get_from_quiz_api(params: params, token: token)
10
+ access_code_params = {
11
+ disable_ac_invalidation: params.delete(:disable_ac_invalidation)
12
+ }.compact
13
+ get_from_quiz_api(params: params, token: token, access_code_params: access_code_params)
11
14
  end
12
15
 
13
16
  private
@@ -19,9 +22,10 @@ module QuizApiClient::Services
19
22
  )
20
23
  end
21
24
 
22
- def get_from_quiz_api(params:, token:)
25
+ def get_from_quiz_api(params:, token:, access_code_params:)
23
26
  client(token: token).get(
24
- "/api/quiz_sessions/#{params[:id]}"
27
+ "/api/quiz_sessions/#{params[:id]}",
28
+ query: access_code_params
25
29
  )
26
30
  end
27
31
  end
@@ -1,3 +1,3 @@
1
1
  module QuizApiClient
2
- VERSION = '4.13.2'.freeze
2
+ VERSION = '4.13.4'.freeze
3
3
  end
@@ -81,7 +81,17 @@ describe QuizApiClient::HttpClient do
81
81
  path = '/api/quizzes'
82
82
  stub_quiz_api path, headers: { link: link_header(path, 1, 2) }
83
83
  stub_quiz_api path, item: 2, query: { page: 2 }, headers: { link: link_header(path, 2, 2) }
84
- expect(client.get('/api/quizzes', all: true)).to eq [1, 2]
84
+ expect(client.get('/api/quizzes', query: { page: 2 }, all: true)).to eq [1, 2]
85
+ end
86
+
87
+ it 'sanitizies the query param if page is nil' do
88
+ stub_quiz_api '/api/quizzes'
89
+ expect(client.get('/api/quizzes', query: { page: nil }, all: true)).to eq [1]
90
+ end
91
+
92
+ it 'sanitizies the query param if per_page is nil' do
93
+ stub_quiz_api '/api/quizzes'
94
+ expect(client.get('/api/quizzes', query: { per_page: nil }, all: true)).to eq [1]
85
95
  end
86
96
  end
87
97
 
@@ -102,6 +112,20 @@ describe QuizApiClient::HttpClient do
102
112
  stub_quiz_api path, item: 2, query: { my_id: 12, **dynamo_params }
103
113
  expect(client.get('/api/quizzes', query: { my_id: 12 }, all: true)).to eq [1, 2]
104
114
  end
115
+
116
+ it 'retrieves subsequent pages when all is true and sanitizes query if page is nil' do
117
+ path = '/api/quizzes'
118
+ stub_quiz_api path, query: { my_id: 12 }, headers: dynamo_headers
119
+ stub_quiz_api path, item: 2, query: { my_id: 12, **dynamo_params }
120
+ expect(client.get('/api/quizzes', query: { my_id: 12, page: nil }, all: true)).to eq [1, 2]
121
+ end
122
+
123
+ it 'retrieves subsequent pages when all is true and sanitizes query if per_page is nil' do
124
+ path = '/api/quizzes'
125
+ stub_quiz_api path, query: { my_id: 12 }, headers: dynamo_headers
126
+ stub_quiz_api path, item: 2, query: { my_id: 12, **dynamo_params }
127
+ expect(client.get('/api/quizzes', query: { my_id: 12, per_page: nil }, all: true)).to eq [1, 2]
128
+ end
105
129
  end
106
130
  end
107
131
  end
@@ -45,5 +45,26 @@ describe QuizApiClient::Services::QuizSessionService do
45
45
  response = subject.show(params: params, token: 'token')
46
46
  expect(response.parsed_response).to eql(stubbed_response)
47
47
  end
48
+
49
+ context 'when the query param "disable_ac_invalidation" is given' do
50
+ let(:params) { { id: 1, disable_ac_invalidation: true } }
51
+ let(:stubbed_response) { { 'id' => 1, 'time_limit_seconds' => 10 } }
52
+ let(:expected_url) { "https://#{host}/api/quiz_sessions/#{params[:id]}?disable_ac_invalidation=true" }
53
+ let(:status_code) { 200 }
54
+
55
+ before do
56
+ stub_request(:get, expected_url)
57
+ .to_return(
58
+ status: status_code,
59
+ body: stubbed_response.to_json,
60
+ headers: { 'Content-Type' => 'application/json' }
61
+ )
62
+ end
63
+
64
+ it 'gets from quiz_api/api/quiz_sessions and returns the response' do
65
+ response = subject.show(params: params, token: 'token')
66
+ expect(response.parsed_response).to eql(stubbed_response)
67
+ end
68
+ end
48
69
  end
49
70
  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.13.2
4
+ version: 4.13.4
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-08-31 00:00:00.000000000 Z
18
+ date: 2023-09-29 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: httparty