taxjar-ruby 2.6.0 → 2.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -2
- data/README.md +523 -331
- data/lib/taxjar/api/request.rb +7 -1
- data/lib/taxjar/error.rb +4 -0
- data/lib/taxjar/version.rb +1 -1
- data/spec/taxjar/api/request_spec.rb +11 -0
- metadata +2 -2
data/lib/taxjar/api/request.rb
CHANGED
@@ -28,7 +28,12 @@ module Taxjar
|
|
28
28
|
def perform
|
29
29
|
options_key = [:get, :delete].include?(@request_method) ? :params : :json
|
30
30
|
response = build_http_client.request(request_method, uri.to_s, options_key => @options)
|
31
|
-
response_body =
|
31
|
+
response_body =
|
32
|
+
begin
|
33
|
+
symbolize_keys!(response.parse(:json))
|
34
|
+
rescue JSON::ParserError
|
35
|
+
nil
|
36
|
+
end
|
32
37
|
fail_or_return_response_body(response.code, response_body)
|
33
38
|
end
|
34
39
|
|
@@ -74,6 +79,7 @@ module Taxjar
|
|
74
79
|
end
|
75
80
|
|
76
81
|
def extract_error(code, body)
|
82
|
+
return Taxjar::Error.for_json_parse_error(code) if body.nil?
|
77
83
|
klass = Taxjar::Error::ERRORS[code]
|
78
84
|
if !klass.nil?
|
79
85
|
klass.from_response(body)
|
data/lib/taxjar/error.rb
CHANGED
data/lib/taxjar/version.rb
CHANGED
@@ -168,6 +168,17 @@ describe Taxjar::API::Request do
|
|
168
168
|
end
|
169
169
|
end
|
170
170
|
|
171
|
+
it 'handles unexpected Content-Type responses' do
|
172
|
+
stub_request(:get, "https://api.taxjar.com/api_path").
|
173
|
+
with(:headers => {'Authorization'=>'Bearer AK', 'Connection'=>'close',
|
174
|
+
'Host'=>'api.taxjar.com',
|
175
|
+
'User-Agent'=>"TaxjarRubyGem/#{Taxjar::Version.to_s}"}).
|
176
|
+
to_return(:status => 200, :body => 'Something unexpected',
|
177
|
+
:headers => {content_type: 'text/html; charset=UTF-8'})
|
178
|
+
|
179
|
+
expect{subject.perform}.to raise_error(Taxjar::Error::ServerError)
|
180
|
+
end
|
181
|
+
|
171
182
|
Taxjar::Error::ERRORS.each do |status, exception|
|
172
183
|
context "when HTTP status is #{status}" do
|
173
184
|
it "raises #{exception}" do
|
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: 2.6.
|
4
|
+
version: 2.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TaxJar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|