taxjar-ruby 3.0.0 → 3.0.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: 47a7bd26490bf919e6339a26097c87d7d9dd0b09ea6214b87070243da422d03c
4
- data.tar.gz: ba4de289c2768c0e52effab858cd0569c3a43f524c34698bafc3cbea8e0eab4f
3
+ metadata.gz: 18688d5bc45966595ed15e6d20eef07bd736db1344a901f8314cc290ac120dcf
4
+ data.tar.gz: 2a3f17b97d09c5e4a5bc2f405884374e29bd0e8a326c29892d461bfe2b8db48e
5
5
  SHA512:
6
- metadata.gz: 7dbea4df68a8bd664c86507f8b266aa1a5901aad30f9b558d8d0e4fa999d36c887a0b6b5acebf511f0a67d8a812d98c60f0693fa4a54057e201765ea67db7ab3
7
- data.tar.gz: d152b6c9d34c19fbae78386346d63aa6bab0ac8d95197a7fa700bb7f2c4ea5da5fede05c6f7458f138febeb7a4065c542cf4c86c7bb320474856352858c67d56
6
+ metadata.gz: 5346c3672896ea11c88c741513003d4567ccc13cc33e7055abcae9529999a227bfc058c0d98a841881cc550c99b87ec0cacfe438f6e2f795c75c0a309e371992
7
+ data.tar.gz: afd508979ce8b8cce3a0700170b6fb13acfea108faae1caf5fdcdbce173f0f62c18bfb17646e54f68d2bdc86c4713ce5115a3a0f197fdcf82aa20981941b2f0a
data/.travis.yml CHANGED
@@ -6,5 +6,6 @@ rvm:
6
6
  - "2.5"
7
7
  - "2.6"
8
8
  - "2.7"
9
+ - "3.0"
9
10
 
10
11
  script: bundle exec rspec
data/CHANGELOG.md CHANGED
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [3.0.3] - 2022-02-07
11
+ - Throw a `Taxjar::Error::GatewayTimeout` exception when receiving a 504 HTTP status code
12
+
13
+ ## [3.0.2] - 2021-03-18
14
+ - Re-classify `HTTP::ConnectionError` and other `HTTP::Error` types as `Taxjar::Error`
15
+
16
+ ## [3.0.1] - 2021-03-16
17
+ - Throw a `Taxjar::Error` exception for any non-successful HTTP response
18
+
10
19
  ## [3.0.0] - 2020-04-03
11
20
  - Add information to custom user agent for debugging and informational purposes
12
21
  - Update required Ruby version from 2.0 to 2.3 or higher
@@ -43,7 +52,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
43
52
  - Update minimum required Ruby version to 2.0
44
53
  - Update HTTP (The Gem) to 2.2
45
54
 
46
- [Unreleased]: https://github.com/taxjar/taxjar-ruby/compare/v3.0.0...HEAD
55
+ [Unreleased]: https://github.com/taxjar/taxjar-ruby/compare/v3.0.3...HEAD
56
+ [3.0.3]: https://github.com/taxjar/taxjar-ruby/compare/v3.0.2...v3.0.3
57
+ [3.0.2]: https://github.com/taxjar/taxjar-ruby/compare/v3.0.1...v3.0.2
58
+ [3.0.1]: https://github.com/taxjar/taxjar-ruby/compare/v3.0.0...v3.0.1
47
59
  [3.0.0]: https://github.com/taxjar/taxjar-ruby/compare/v2.6.1...v3.0.0
48
60
  [2.6.1]: https://github.com/taxjar/taxjar-ruby/compare/v2.6.0...v2.6.1
49
61
  [2.6.0]: https://github.com/taxjar/taxjar-ruby/compare/v2.5.0...v2.6.0
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # TaxJar Sales Tax API for Ruby [![RubyGems](https://img.shields.io/gem/v/taxjar-ruby.svg?style=flat-square)](https://rubygems.org/gems/taxjar-ruby) [![Build Status](https://img.shields.io/travis/taxjar/taxjar-ruby.svg?style=flat-square)](https://travis-ci.org/taxjar/taxjar-ruby)
2
2
 
3
- <a href="https://developers.taxjar.com"><img src="https://www.taxjar.com/img/TJ_logo_color_office_png.png" alt="TaxJar" width="220"></a>
3
+ <a href="https://developers.taxjar.com"><img src="https://www.taxjar.com/wp-content/uploads/TaxJar__Wordmark_Black.svg" alt="TaxJar" width="220"></a>
4
4
 
5
5
  A Ruby interface to the TaxJar [Sales Tax API](https://developers.taxjar.com/api/reference/?ruby). TaxJar makes sales tax filing easier for online sellers and merchants. See local jurisdictional tax reports, get payment reminders, and more. You can use our API to access TaxJar API endpoints, which can get information on sales tax rates, categories or upload transactions.
6
6
 
7
- * This wrapper supports 100% of [SmartCalcs v2](https://developers.taxjar.com/api/#introduction)
7
+ * This wrapper supports 100% of the [TaxJar API](https://developers.taxjar.com/api/#introduction)
8
8
  * Data returned from API calls are mapped to Ruby objects
9
9
 
10
10
  <hr>
@@ -1188,7 +1188,7 @@ nexus_regions = client.nexus_regions
1188
1188
 
1189
1189
  ### Validate an address <small>_([API docs](https://developers.taxjar.com/api/reference/?ruby#post-validate-an-address))_</small>
1190
1190
 
1191
- > Validates a customer address and returns back a collection of address matches. **Address validation requires a [TaxJar Plus](https://www.taxjar.com/plus/) subscription.**
1191
+ > Validates a customer address and returns back a collection of address matches. **Address validation requires a [TaxJar Professional](https://www.taxjar.com/pricing) subscription.**
1192
1192
 
1193
1193
  #### Definition
1194
1194
 
@@ -1268,7 +1268,7 @@ validation = client.validate({
1268
1268
 
1269
1269
  > Retrieve minimum and average sales tax rates by region as a backup.
1270
1270
  >
1271
- > This method is useful for periodically pulling down rates to use if the SmartCalcs API is unavailable. However, it does not support nexus determination, sourcing based on a ship from and ship to address, shipping taxability, product exemptions, customer exemptions, or sales tax holidays. We recommend using [`tax_for_order` to accurately calculate sales tax for an order](#calculate-sales-tax-for-an-order-api-docs).
1271
+ > This method is useful for periodically pulling down rates to use if the TaxJar API is unavailable. However, it does not support nexus determination, sourcing based on a ship from and ship to address, shipping taxability, product exemptions, customer exemptions, or sales tax holidays. We recommend using [`tax_for_order` to accurately calculate sales tax for an order](#calculate-sales-tax-for-an-order-api-docs).
1272
1272
 
1273
1273
  #### Definition
1274
1274
 
@@ -34,7 +34,9 @@ module Taxjar
34
34
  rescue JSON::ParserError
35
35
  nil
36
36
  end
37
- fail_or_return_response_body(response.code, response_body)
37
+ fail_or_return_response_body(response, response_body)
38
+ rescue HTTP::Error => e
39
+ raise Taxjar::Error, e
38
40
  end
39
41
 
40
42
  private
@@ -72,17 +74,15 @@ module Taxjar
72
74
  object
73
75
  end
74
76
 
75
- def fail_or_return_response_body(code, body)
76
- e = extract_error(code, body)
77
- fail(e) if e
78
- body[object_key.to_sym]
79
- end
80
-
81
- def extract_error(code, body)
82
- return Taxjar::Error.for_json_parse_error(code) if body.nil?
83
- klass = Taxjar::Error::ERRORS[code]
84
- if !klass.nil?
85
- klass.from_response(body)
77
+ def fail_or_return_response_body(response, body)
78
+ if body.nil?
79
+ fail(Taxjar::Error.for_json_parse_error(response.code))
80
+ elsif response.status.success?
81
+ body[object_key.to_sym]
82
+ elsif !(klass = Taxjar::Error::ERRORS[response.code]).nil?
83
+ fail(klass.from_response(body))
84
+ else
85
+ fail(Taxjar::Error.from_response_code(response.code))
86
86
  end
87
87
  end
88
88
  end
data/lib/taxjar/error.rb CHANGED
@@ -39,6 +39,9 @@ module Taxjar
39
39
  # Raised when Taxjar endpoint returns the HTTP status code 503
40
40
  ServiceUnavailable = Class.new(ServerError)
41
41
 
42
+ # Raised when Taxjar endpoint returns the HTTP status code 504
43
+ GatewayTimeout = Class.new(ServerError)
44
+
42
45
  ERRORS = {
43
46
  400 => Taxjar::Error::BadRequest,
44
47
  401 => Taxjar::Error::Unauthorized,
@@ -50,7 +53,8 @@ module Taxjar
50
53
  422 => Taxjar::Error::UnprocessableEntity,
51
54
  429 => Taxjar::Error::TooManyRequests,
52
55
  500 => Taxjar::Error::InternalServerError,
53
- 503 => Taxjar::Error::ServiceUnavailable
56
+ 503 => Taxjar::Error::ServiceUnavailable,
57
+ 504 => Taxjar::Error::GatewayTimeout
54
58
  }
55
59
 
56
60
  class << self
@@ -61,6 +65,11 @@ module Taxjar
61
65
  new(message, code)
62
66
  end
63
67
 
68
+ def from_response_code(code)
69
+ message = HTTP::Response::Status::REASONS[code] || "Unknown Error"
70
+ new(message, code)
71
+ end
72
+
64
73
  def for_json_parse_error(code)
65
74
  ServerError.new("Couldn't parse response as JSON.", code)
66
75
  end
@@ -10,7 +10,7 @@ module Taxjar
10
10
  end
11
11
 
12
12
  def patch
13
- 0
13
+ 3
14
14
  end
15
15
 
16
16
  def pre
@@ -175,6 +175,24 @@ describe Taxjar::API::Request do
175
175
  expect{subject.perform}.to raise_error(Taxjar::Error::ServerError)
176
176
  end
177
177
 
178
+ [
179
+ HTTP::Error,
180
+ HTTP::ConnectionError,
181
+ HTTP::RequestError,
182
+ HTTP::ResponseError,
183
+ HTTP::StateError,
184
+ HTTP::TimeoutError,
185
+ HTTP::HeaderError
186
+ ].each do |http_error_class|
187
+ context "#{http_error_class}" do
188
+ it "is classified as a Taxjar::Error" do
189
+ stub_request(:get, "https://api.taxjar.com/api_path").to_raise(http_error_class)
190
+
191
+ expect{subject.perform}.to raise_error(Taxjar::Error)
192
+ end
193
+ end
194
+ end
195
+
178
196
  Taxjar::Error::ERRORS.each do |status, exception|
179
197
  context "when HTTP status is #{status}" do
180
198
  it "raises #{exception}" do
@@ -191,5 +209,41 @@ describe Taxjar::API::Request do
191
209
  end
192
210
  end
193
211
  end
212
+
213
+ context "when HTTP status is 502" do
214
+ it "raises Taxjar::Error" do
215
+ stub_request(:get, "https://api.taxjar.com/api_path").
216
+ with(:headers => {'Authorization'=>'Bearer AK', 'Connection'=>'close',
217
+ 'Host'=>'api.taxjar.com'}).
218
+ to_return(:status => 502,
219
+ :body => '{}',
220
+ :headers => {content_type: 'application/json; charset=UTF-8'})
221
+
222
+ expect{subject.perform}.to raise_error(
223
+ an_instance_of(Taxjar::Error).and having_attributes({
224
+ "message" => "Bad Gateway",
225
+ "code" => 502
226
+ })
227
+ )
228
+ end
229
+ end
230
+
231
+ context "when HTTP status is 5xx" do
232
+ it "raises Taxjar::Error" do
233
+ stub_request(:get, "https://api.taxjar.com/api_path").
234
+ with(:headers => {'Authorization'=>'Bearer AK', 'Connection'=>'close',
235
+ 'Host'=>'api.taxjar.com'}).
236
+ to_return(:status => 509,
237
+ :body => '{}',
238
+ :headers => {content_type: 'application/json; charset=UTF-8'})
239
+
240
+ expect{subject.perform}.to raise_error(
241
+ an_instance_of(Taxjar::Error).and having_attributes({
242
+ "message" => "Unknown Error",
243
+ "code" => 509
244
+ })
245
+ )
246
+ end
247
+ end
194
248
  end
195
249
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taxjar-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - TaxJar
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-06 00:00:00.000000000 Z
11
+ date: 2022-06-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -116,7 +116,6 @@ files:
116
116
  - ".editorconfig"
117
117
  - ".gitignore"
118
118
  - ".rspec"
119
- - ".ruby-version"
120
119
  - ".travis.yml"
121
120
  - CHANGELOG.md
122
121
  - Gemfile
@@ -187,7 +186,7 @@ metadata:
187
186
  changelog_uri: https://github.com/taxjar/taxjar-ruby/blob/master/CHANGELOG.md
188
187
  source_code_uri: https://github.com/taxjar/taxjar-ruby
189
188
  bug_tracker_uri: https://github.com/taxjar/taxjar-ruby/issues
190
- post_install_message:
189
+ post_install_message:
191
190
  rdoc_options: []
192
191
  require_paths:
193
192
  - lib
@@ -202,8 +201,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
202
201
  - !ruby/object:Gem::Version
203
202
  version: '0'
204
203
  requirements: []
205
- rubygems_version: 3.1.2
206
- signing_key:
204
+ rubygems_version: 3.3.3
205
+ signing_key:
207
206
  specification_version: 4
208
207
  summary: Ruby wrapper for Taxjar API
209
208
  test_files:
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 1.9.3-p0