quiz_api_client 4.0.0 → 4.1.0

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: 48279a4ca7eeb3d7fc50e493733f5718c2960b2267d70db68b2956b0b11c99c1
4
- data.tar.gz: cbd66f799b72273b23b2e7a208fc10336bee5cf2cb93656987d0fdc5d1c173a7
3
+ metadata.gz: f901bb687e405ab11127e8cbbe476f38c3578d122d838b25438cc106287b4d83
4
+ data.tar.gz: 6bae389bad7c912f709747a00a562e42cd10e4b85d1d72f5a7c5ffff6564ae61
5
5
  SHA512:
6
- metadata.gz: d448acbf4ac471f2c8f55cda52191d35ade2d0e107546946e9cee8f6712556ac402160150555d8e3f978034843240deeeb4cec0a658a5fdf8ce2b2b8d3e1a452
7
- data.tar.gz: c73951b3bc89f5ff17b08ac1199aff03f3fd2a7e9cf701d5b2d9fffcc31d4bc76ddd2cc4384622584479ab32f2abf85abc3993554fb8a872a4b961eb8b23b4a3
6
+ metadata.gz: 519030cead9c1d820cf40bb489029433f751ce41e6488dcddfd7a8520ea2c47c5fa7a8a96e0aaea59640793f0efcc7fcd825c3d5e2fbe026533cb9d18208fd18
7
+ data.tar.gz: b906985f27f6e78e734f248685ae071efde9414cc3198d5a214caf9d54d8c1d2f29e6cc7d9e53677eac2c1c1d4d9bbd3016f3cea210173c1cf00628784d18507
data/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ CHANGELOG
2
+ =========
3
+
4
+ All notable changes to this project will be documented in this file. This
5
+ project adheres to [Semantic Versioning](http://semver.org/).
6
+
7
+ [TOC]
8
+
9
+ ## 4.1.0 (2021-10-27)
10
+
11
+ ### Breaking changes (potentially)
12
+
13
+ * All non-successful (2xx) responses will raise `QuizApiClient::HttpClient::RequestFailed` error except for 401 and 422
14
+ * Can be overridden in `allowable_response_codes` config
15
+
16
+ ## 4.0.0 (2021-10-18)
17
+
18
+ ### Breaking changes
19
+
20
+ * Ruby 2.4.x is no longer supported
21
+ * Ruby 2.5.x is no longer supported
22
+
23
+ ### Changed
24
+ * Minimum Ruby version to 2.6.x
25
+ * Internal classes use a configuration object instead parameters on instantiation
26
+ * Instantiating `QuizApiClient::Client` remains the same
27
+ * Added `error_handler` configuration to work with Sentry Raven gem
28
+
@@ -1,12 +1,13 @@
1
1
  module QuizApiClient
2
2
  class Config
3
+ DEFAULT_ALLOWABLE_RESPONSE_CODES = [401, 422].freeze
3
4
  DEFAULT_PROTOCOL = 'https'.freeze
4
5
  ERROR_HANDLERS = %i[sentry_raven].freeze
5
6
 
6
7
  class InvalidErrorHandler < StandardError; end
7
8
 
8
9
  attr_reader :error_handler
9
- attr_writer :protocol
10
+ attr_writer :protocol, :allowable_response_codes
10
11
  attr_accessor :consumer_key, :consumer_request_id, :host, :shared_secret
11
12
 
12
13
  def initialize
@@ -23,6 +24,10 @@ module QuizApiClient
23
24
  @error_handler = handler
24
25
  end
25
26
 
27
+ def allowable_response_codes
28
+ @allowable_response_codes || DEFAULT_ALLOWABLE_RESPONSE_CODES
29
+ end
30
+
26
31
  private
27
32
 
28
33
  def validate_error_hander!(handler)
@@ -4,7 +4,14 @@ module QuizApiClient
4
4
  class HttpClient
5
5
  include HTTParty
6
6
 
7
- class RequestFailed < StandardError; end
7
+ class RequestFailed < StandardError
8
+ attr_reader :context
9
+
10
+ def initialize(context)
11
+ @context = context
12
+ super(context)
13
+ end
14
+ end
8
15
 
9
16
  attr_reader :jwt, :uri, :config
10
17
 
@@ -75,11 +82,13 @@ module QuizApiClient
75
82
  end
76
83
 
77
84
  def make_request(method, url, request_options = {})
78
- self.class.send(
85
+ resp = self.class.send(
79
86
  method,
80
87
  url,
81
88
  default_request_data.merge(request_options)
82
89
  )
90
+ raise_error(method, url, response: resp) unless successful_response?(resp)
91
+ resp
83
92
  rescue HTTParty::Error, Errno::ECONNREFUSED, Net::ReadTimeout => e
84
93
  raise_error(method, url, current_error: e)
85
94
  end
@@ -91,8 +100,6 @@ module QuizApiClient
91
100
 
92
101
  until request_url.nil?
93
102
  resp = make_request(method, request_url, request_options)
94
- raise_error(method, url, response: resp) unless resp.code == 200
95
-
96
103
  entities.concat(resp.parsed_response)
97
104
  request_url, request_options = next_page(resp, url, options)
98
105
  end
@@ -182,7 +189,11 @@ module QuizApiClient
182
189
 
183
190
  record_error_context(context)
184
191
 
185
- raise error_class, error_message(current_error, url, response)
192
+ raise error_class.new(context), error_message(current_error, url, response)
193
+ end
194
+
195
+ def successful_response?(resp)
196
+ resp.success? || config.allowable_response_codes.include?(resp.code)
186
197
  end
187
198
  end
188
199
  end
@@ -1,3 +1,3 @@
1
1
  module QuizApiClient
2
- VERSION = '4.0.0'.freeze
2
+ VERSION = '4.1.0'.freeze
3
3
  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.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Wang
@@ -20,7 +20,7 @@ authors:
20
20
  autorequire:
21
21
  bindir: exe
22
22
  cert_chain: []
23
- date: 2021-10-18 00:00:00.000000000 Z
23
+ date: 2021-10-27 00:00:00.000000000 Z
24
24
  dependencies:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httparty
@@ -200,6 +200,7 @@ files:
200
200
  - ".gitignore"
201
201
  - ".rspec"
202
202
  - ".rubocop.yml"
203
+ - CHANGELOG.md
203
204
  - Dockerfile
204
205
  - Gemfile
205
206
  - Jenkinsfile