taxjar-ruby 3.0.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +5 -1
- data/README.md +2 -2
- data/lib/taxjar/api/request.rb +10 -12
- data/lib/taxjar/error.rb +5 -0
- data/lib/taxjar/version.rb +1 -1
- data/spec/taxjar/api/request_spec.rb +36 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bd370b061b002cddb9e65f2a879beed9e11c82678eccaa4b6e3b4b6ceb4c053
|
4
|
+
data.tar.gz: b45f569333906938d5f656442549124f06b12c9dc51c47db9af3a0a29e312730
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6960458fd1bb6c89eaeb5f817b15c70a5e68b5b23f6232c05be63273fe02be92102797b989eaaacd76ee77ffa97cef67cdf413293d2a351300633a7d1d51f51a
|
7
|
+
data.tar.gz: fe9903162754fa2c551d1dd4a88fc1bdd270bc92ac5fedeb1489ecc38a817cee5d93bfbf386442f3b3006df082ff8b31e692a24e6a1a95c716cee8d2b5917077
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [3.0.1] - 2021-03-16
|
11
|
+
- Throw a `Taxjar::Error` exception for any non-successful HTTP response
|
12
|
+
|
10
13
|
## [3.0.0] - 2020-04-03
|
11
14
|
- Add information to custom user agent for debugging and informational purposes
|
12
15
|
- Update required Ruby version from 2.0 to 2.3 or higher
|
@@ -43,7 +46,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
43
46
|
- Update minimum required Ruby version to 2.0
|
44
47
|
- Update HTTP (The Gem) to 2.2
|
45
48
|
|
46
|
-
[Unreleased]: https://github.com/taxjar/taxjar-ruby/compare/v3.0.
|
49
|
+
[Unreleased]: https://github.com/taxjar/taxjar-ruby/compare/v3.0.1...HEAD
|
50
|
+
[3.0.1]: https://github.com/taxjar/taxjar-ruby/compare/v3.0.0...v3.0.1
|
47
51
|
[3.0.0]: https://github.com/taxjar/taxjar-ruby/compare/v2.6.1...v3.0.0
|
48
52
|
[2.6.1]: https://github.com/taxjar/taxjar-ruby/compare/v2.6.0...v2.6.1
|
49
53
|
[2.6.0]: https://github.com/taxjar/taxjar-ruby/compare/v2.5.0...v2.6.0
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
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 [
|
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>
|
@@ -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
|
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
|
|
data/lib/taxjar/api/request.rb
CHANGED
@@ -34,7 +34,7 @@ module Taxjar
|
|
34
34
|
rescue JSON::ParserError
|
35
35
|
nil
|
36
36
|
end
|
37
|
-
fail_or_return_response_body(response
|
37
|
+
fail_or_return_response_body(response, response_body)
|
38
38
|
end
|
39
39
|
|
40
40
|
private
|
@@ -72,17 +72,15 @@ module Taxjar
|
|
72
72
|
object
|
73
73
|
end
|
74
74
|
|
75
|
-
def fail_or_return_response_body(
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
if !klass.nil?
|
85
|
-
klass.from_response(body)
|
75
|
+
def fail_or_return_response_body(response, body)
|
76
|
+
if body.nil?
|
77
|
+
fail(Taxjar::Error.for_json_parse_error(response.code))
|
78
|
+
elsif response.status.success?
|
79
|
+
body[object_key.to_sym]
|
80
|
+
elsif !(klass = Taxjar::Error::ERRORS[response.code]).nil?
|
81
|
+
fail(klass.from_response(body))
|
82
|
+
else
|
83
|
+
fail(Taxjar::Error.from_response_code(response.code))
|
86
84
|
end
|
87
85
|
end
|
88
86
|
end
|
data/lib/taxjar/error.rb
CHANGED
@@ -61,6 +61,11 @@ module Taxjar
|
|
61
61
|
new(message, code)
|
62
62
|
end
|
63
63
|
|
64
|
+
def from_response_code(code)
|
65
|
+
message = HTTP::Response::Status::REASONS[code] || "Unknown Error"
|
66
|
+
new(message, code)
|
67
|
+
end
|
68
|
+
|
64
69
|
def for_json_parse_error(code)
|
65
70
|
ServerError.new("Couldn't parse response as JSON.", code)
|
66
71
|
end
|
data/lib/taxjar/version.rb
CHANGED
@@ -191,5 +191,41 @@ describe Taxjar::API::Request do
|
|
191
191
|
end
|
192
192
|
end
|
193
193
|
end
|
194
|
+
|
195
|
+
context "when HTTP status is 502" do
|
196
|
+
it "raises Taxjar::Error" do
|
197
|
+
stub_request(:get, "https://api.taxjar.com/api_path").
|
198
|
+
with(:headers => {'Authorization'=>'Bearer AK', 'Connection'=>'close',
|
199
|
+
'Host'=>'api.taxjar.com'}).
|
200
|
+
to_return(:status => 502,
|
201
|
+
:body => '{}',
|
202
|
+
:headers => {content_type: 'application/json; charset=UTF-8'})
|
203
|
+
|
204
|
+
expect{subject.perform}.to raise_error(
|
205
|
+
an_instance_of(Taxjar::Error).and having_attributes({
|
206
|
+
"message" => "Bad Gateway",
|
207
|
+
"code" => 502
|
208
|
+
})
|
209
|
+
)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
context "when HTTP status is 5xx" 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 => 509,
|
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" => "Unknown Error",
|
225
|
+
"code" => 509
|
226
|
+
})
|
227
|
+
)
|
228
|
+
end
|
229
|
+
end
|
194
230
|
end
|
195
231
|
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.
|
4
|
+
version: 3.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TaxJar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -202,7 +202,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
202
|
- !ruby/object:Gem::Version
|
203
203
|
version: '0'
|
204
204
|
requirements: []
|
205
|
-
|
205
|
+
rubyforge_project:
|
206
|
+
rubygems_version: 2.7.6.2
|
206
207
|
signing_key:
|
207
208
|
specification_version: 4
|
208
209
|
summary: Ruby wrapper for Taxjar API
|