quiz_api_client 4.13.2 → 4.13.3

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: ba3c7ef7577c2eb514a0ba86c804c2b3f98ffcbad90bae29e6a0e505ab987bb4
4
+ data.tar.gz: 96a6091a6c5b5811bd7776871b9b0af664f3a330306a614f6b0d17662a54c6f9
5
5
  SHA512:
6
- metadata.gz: 7c0b3d1876135ab671d33a9156d6c56ad7f51103691de92f6a093d91e5f1a1d01c160f5017585572afd88b2bd245df34e043ff8f1e3516b75e87a3e96344bdca
7
- data.tar.gz: d41fde3e160e5b9d57b242810ae29657183516e88586f1afb4a0c86f7171ee447603282b43058f3feb7aff8897c06c74cdf2adec23b0dfcdbb54c423a09e12e4
6
+ metadata.gz: 679f371890c6fa8bbcde89b60f7eaa8bee1e379c666a7fd7e53b6869f69f9e337b45b715a2d469f2fd9f8b2e31aac6b6d7575fddee1e419c1a0b37c87bbb3922
7
+ data.tar.gz: ebb6c033080207b63e7d3da0d0668057e9b845c95cf43b1ffd70ec8c3da2639c2ae237ef6a1cc36db0a08244d1b92e5c1e69097aecd1c53805e4b7ed7b40009e
@@ -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(
@@ -1,3 +1,3 @@
1
1
  module QuizApiClient
2
- VERSION = '4.13.2'.freeze
2
+ VERSION = '4.13.3'.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
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.3
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-26 00:00:00.000000000 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: httparty