taxjar-ruby 2.4.1 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +2 -7
- data/CHANGELOG.md +26 -2
- data/README.md +525 -333
- data/lib/taxjar/api/request.rb +24 -15
- data/lib/taxjar/client.rb +9 -1
- data/lib/taxjar/error.rb +9 -0
- data/lib/taxjar/order.rb +3 -1
- data/lib/taxjar/refund.rb +3 -1
- data/lib/taxjar/tax.rb +1 -0
- data/lib/taxjar/version.rb +2 -2
- data/spec/fixtures/order.json +2 -0
- data/spec/fixtures/refund.json +2 -0
- data/spec/fixtures/taxes.json +1 -0
- data/spec/fixtures/taxes_canada.json +1 -0
- data/spec/fixtures/taxes_international.json +1 -0
- data/spec/taxjar/api/api_spec.rb +4 -0
- data/spec/taxjar/api/order_spec.rb +30 -17
- data/spec/taxjar/api/refund_spec.rb +32 -19
- data/spec/taxjar/api/request_spec.rb +65 -8
- data/spec/taxjar/client_spec.rb +4 -4
- data/taxjar-ruby.gemspec +3 -3
- metadata +14 -8
@@ -41,7 +41,7 @@ describe Taxjar::API::Request do
|
|
41
41
|
it 'should return headers' do
|
42
42
|
expect(subject).to respond_to(:headers)
|
43
43
|
expect(subject.headers).to be_instance_of(Hash)
|
44
|
-
expect(subject.headers[:user_agent]).to match(
|
44
|
+
expect(subject.headers[:user_agent]).to match(/^TaxJar\/Ruby \(.+\) taxjar-ruby\/\d+\.\d+\.\d+$/)
|
45
45
|
expect(subject.headers[:authorization]).to eq('Bearer AK')
|
46
46
|
end
|
47
47
|
|
@@ -52,7 +52,7 @@ describe Taxjar::API::Request do
|
|
52
52
|
subject = Taxjar::API::Request.new(client, :get, '/api_path', 'object')
|
53
53
|
expect(subject).to respond_to(:headers)
|
54
54
|
expect(subject.headers).to be_instance_of(Hash)
|
55
|
-
expect(subject.headers[:user_agent]).to match(
|
55
|
+
expect(subject.headers[:user_agent]).to match(/^TaxJar\/Ruby \(.+\) taxjar-ruby\/\d+\.\d+\.\d+$/)
|
56
56
|
expect(subject.headers[:authorization]).to eq('Bearer AK')
|
57
57
|
expect(subject.headers['X-TJ-Expected-Response']).to eq(422)
|
58
58
|
end
|
@@ -119,12 +119,25 @@ describe Taxjar::API::Request do
|
|
119
119
|
Taxjar::API::Request.new(client, :get, '/api_path', 'object')
|
120
120
|
end
|
121
121
|
|
122
|
+
context 'with a proxy' do
|
123
|
+
let(:client){ Taxjar::Client.new(api_key: 'AK', http_proxy: ["127.0.0.1", 8080])}
|
124
|
+
it "runs through the proxy" do
|
125
|
+
stub_request(:get, "https://api.taxjar.com/api_path").
|
126
|
+
with(:headers => {'Authorization'=>'Bearer AK', 'Connection'=>'close',
|
127
|
+
'Host'=>'api.taxjar.com'}).
|
128
|
+
to_return(:status => 200, :body => '{"object": {"id": "3"}}',
|
129
|
+
:headers => {content_type: 'application/json; charset=UTF-8'})
|
130
|
+
|
131
|
+
expect(subject.perform).to eq({id: '3'})
|
132
|
+
expect(subject.send(:build_http_client).default_options.proxy).to eq({proxy_address: "127.0.0.1", proxy_port: 8080})
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
122
136
|
context 'with get' do
|
123
137
|
it 'should return a body if no errors' do
|
124
138
|
stub_request(:get, "https://api.taxjar.com/api_path").
|
125
139
|
with(:headers => {'Authorization'=>'Bearer AK', 'Connection'=>'close',
|
126
|
-
'Host'=>'api.taxjar.com'
|
127
|
-
'User-Agent'=>"TaxjarRubyGem/#{Taxjar::Version.to_s}"}).
|
140
|
+
'Host'=>'api.taxjar.com'}).
|
128
141
|
to_return(:status => 200, :body => '{"object": {"id": "3"}}',
|
129
142
|
:headers => {content_type: 'application/json; charset=UTF-8'})
|
130
143
|
|
@@ -144,8 +157,7 @@ describe Taxjar::API::Request do
|
|
144
157
|
with(:body => "{\"city\":\"New York\"}",
|
145
158
|
:headers => {'Authorization'=>'Bearer AK', 'Connection'=>'close',
|
146
159
|
'Content-Type'=>'application/json; charset=UTF-8',
|
147
|
-
'Host'=>'api.taxjar.com'
|
148
|
-
'User-Agent'=>"TaxjarRubyGem/#{Taxjar::Version.to_s}"}).
|
160
|
+
'Host'=>'api.taxjar.com'}).
|
149
161
|
to_return(:status => 200, :body => '{"object": {"id": "3"}}',
|
150
162
|
:headers => {content_type: 'application/json; charset=UTF-8'})
|
151
163
|
|
@@ -153,13 +165,22 @@ describe Taxjar::API::Request do
|
|
153
165
|
end
|
154
166
|
end
|
155
167
|
|
168
|
+
it 'handles unexpected Content-Type responses' do
|
169
|
+
stub_request(:get, "https://api.taxjar.com/api_path").
|
170
|
+
with(:headers => {'Authorization'=>'Bearer AK', 'Connection'=>'close',
|
171
|
+
'Host'=>'api.taxjar.com'}).
|
172
|
+
to_return(:status => 200, :body => 'Something unexpected',
|
173
|
+
:headers => {content_type: 'text/html; charset=UTF-8'})
|
174
|
+
|
175
|
+
expect{subject.perform}.to raise_error(Taxjar::Error::ServerError)
|
176
|
+
end
|
177
|
+
|
156
178
|
Taxjar::Error::ERRORS.each do |status, exception|
|
157
179
|
context "when HTTP status is #{status}" do
|
158
180
|
it "raises #{exception}" do
|
159
181
|
stub_request(:get, "https://api.taxjar.com/api_path").
|
160
182
|
with(:headers => {'Authorization'=>'Bearer AK', 'Connection'=>'close',
|
161
|
-
'Host'=>'api.taxjar.com'
|
162
|
-
'User-Agent'=>"TaxjarRubyGem/#{Taxjar::Version.to_s}"}).
|
183
|
+
'Host'=>'api.taxjar.com'}).
|
163
184
|
to_return(:status => status,
|
164
185
|
:body => '{"error": "Not Acceptable",
|
165
186
|
"detail": "error explanation",
|
@@ -170,5 +191,41 @@ describe Taxjar::API::Request do
|
|
170
191
|
end
|
171
192
|
end
|
172
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
|
173
230
|
end
|
174
231
|
end
|
data/spec/taxjar/client_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
describe Taxjar::Client do
|
4
|
-
describe '#api_key?' do
|
4
|
+
describe '#api_key?' do
|
5
5
|
it 'returns true if api_key is present' do
|
6
6
|
client = Taxjar::Client.new(api_key: 'AK')
|
7
7
|
expect(client.api_key?).to be true
|
@@ -25,14 +25,14 @@ describe Taxjar::Client do
|
|
25
25
|
client.set_api_config('api_url', 'https://api.sandbox.taxjar.com')
|
26
26
|
expect(client.api_url).to eq('https://api.sandbox.taxjar.com')
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it 'sets new custom headers' do
|
30
30
|
client = Taxjar::Client.new(api_key: 'AK')
|
31
31
|
client.set_api_config('headers', { 'X-TJ-Expected-Response' => 422 })
|
32
32
|
expect(client.headers).to eq({ 'X-TJ-Expected-Response' => 422 })
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
describe "#get_api_config" do
|
37
37
|
it 'gets a config value' do
|
38
38
|
client = Taxjar::Client.new(api_key: 'AK')
|
@@ -44,7 +44,7 @@ describe Taxjar::Client do
|
|
44
44
|
describe '#user_agent' do
|
45
45
|
it 'returns string with version' do
|
46
46
|
client = Taxjar::Client.new(api_key: 'AK')
|
47
|
-
expect(client.user_agent).to
|
47
|
+
expect(client.user_agent).to match(/^TaxJar\/Ruby \(.+\) taxjar-ruby\/\d+\.\d+\.\d+$/)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
data/taxjar-ruby.gemspec
CHANGED
@@ -18,13 +18,13 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.required_ruby_version = '>= 2.
|
21
|
+
spec.required_ruby_version = '>= 2.3'
|
22
22
|
|
23
23
|
spec.add_dependency 'addressable', '~> 2.3'
|
24
|
-
spec.add_dependency 'http', '>=
|
24
|
+
spec.add_dependency 'http', '>= 4.3', '< 5.0'
|
25
25
|
spec.add_dependency 'memoizable', '~> 0.4.0'
|
26
26
|
spec.add_dependency 'model_attribute', '~> 3.2'
|
27
|
-
spec.add_development_dependency "bundler", "
|
27
|
+
spec.add_development_dependency "bundler", ">= 1.7", "< 3.0"
|
28
28
|
spec.add_development_dependency "rake", "~> 12.0"
|
29
29
|
|
30
30
|
if spec.respond_to?(:metadata)
|
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:
|
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
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '4.3'
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
36
|
version: '5.0'
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version: '
|
43
|
+
version: '4.3'
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '5.0'
|
@@ -76,16 +76,22 @@ dependencies:
|
|
76
76
|
name: bundler
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
|
-
- - "
|
79
|
+
- - ">="
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '1.7'
|
82
|
+
- - "<"
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '3.0'
|
82
85
|
type: :development
|
83
86
|
prerelease: false
|
84
87
|
version_requirements: !ruby/object:Gem::Requirement
|
85
88
|
requirements:
|
86
|
-
- - "
|
89
|
+
- - ">="
|
87
90
|
- !ruby/object:Gem::Version
|
88
91
|
version: '1.7'
|
92
|
+
- - "<"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '3.0'
|
89
95
|
- !ruby/object:Gem::Dependency
|
90
96
|
name: rake
|
91
97
|
requirement: !ruby/object:Gem::Requirement
|
@@ -189,7 +195,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
189
195
|
requirements:
|
190
196
|
- - ">="
|
191
197
|
- !ruby/object:Gem::Version
|
192
|
-
version: '2.
|
198
|
+
version: '2.3'
|
193
199
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
194
200
|
requirements:
|
195
201
|
- - ">="
|
@@ -197,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
197
203
|
version: '0'
|
198
204
|
requirements: []
|
199
205
|
rubyforge_project:
|
200
|
-
rubygems_version: 2.6.
|
206
|
+
rubygems_version: 2.7.6.2
|
201
207
|
signing_key:
|
202
208
|
specification_version: 4
|
203
209
|
summary: Ruby wrapper for Taxjar API
|