taxjar-ruby 2.4.1 → 2.5.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
  SHA1:
3
- metadata.gz: b54cdb522b0b3744437e592154cf44893628a704
4
- data.tar.gz: 500b74d372d771d99d3dc2924ae9e354fc2d1078
3
+ metadata.gz: 1bfb85c8da4a0794eaa7fb2634d811d6e1d48d1d
4
+ data.tar.gz: 8ac52df47adcebb45a240649322bd80820d8298b
5
5
  SHA512:
6
- metadata.gz: 9dd20ccdf84c05232aaf5d68734043e99f16d3ef661aced05a6b0a1b2e22db1e940479bdcd52e38e87d4b7c32d672e4edce7f33c74b3eb803001c841b7bf17c7
7
- data.tar.gz: 9374fdd910a31995f41e94225fa7bc41684844e9bfe8ff10b38435a3a4b15fdb0fb803548fae93d840072697a4caf1e6d8dae447c3ea5d83a2b7c1ae535e6943
6
+ metadata.gz: 49c6eb22aa02d983f00e2fb33cdcc98b7958fda8d3d0cf2d6dc28a32098075ec8c76f1ac93d7a24354677fac3df9f4483735164e035588f904bd498a3d290b8a
7
+ data.tar.gz: 9783ad5245bb139312e63ccaa560f080e649d439daf4006c5c5e3aec854e3e174169bb383a2f204ca66f6e72ab73d3a61362ad69ea2db1c823c50e7255e6a7f3
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.5.0] - 2019-06-19
11
+ - Support `provider` param for marketplace exempt transactions
12
+ - Add proxy support when instantiating client
13
+
10
14
  ## [2.4.1] - 2019-02-04
11
15
  - Relax HTTP.rb gem version requirements
12
16
  - Add RubyGems metadata
@@ -27,7 +31,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
27
31
  - Update minimum required Ruby version to 2.0
28
32
  - Update HTTP (The Gem) to 2.2
29
33
 
30
- [Unreleased]: https://github.com/taxjar/taxjar-ruby/compare/v2.4.1...HEAD
34
+ [Unreleased]: https://github.com/taxjar/taxjar-ruby/compare/v2.5.0...HEAD
35
+ [2.5.0]: https://github.com/taxjar/taxjar-ruby/compare/v2.4.1...v2.5.0
31
36
  [2.4.1]: https://github.com/taxjar/taxjar-ruby/compare/v2.4.0...v2.4.1
32
37
  [2.4.0]: https://github.com/taxjar/taxjar-ruby/compare/v2.3.0...v2.4.0
33
38
  [2.3.0]: https://github.com/taxjar/taxjar-ruby/compare/v2.2.0...v2.3.0
data/README.md CHANGED
@@ -18,7 +18,7 @@ Installing this gem also bundles the following dependencies:
18
18
  * [http](https://github.com/httprb/http.rb) - Fast Ruby HTTP client with a chainable API and full streaming support.
19
19
  * [addressable](https://github.com/sporkmonger/addressable) - Replacement for the URI implementation that is part of Ruby's standard library. It more closely conforms to the relevant RFCs and adds support for IRIs and URI templates.
20
20
  * [memoizable](https://github.com/dkubb/memoizable) - Memoize method return values.
21
- * [model_attribute](https://github.com/yammer/model_attribute) - Type casted attributes for non-ActiveRecord models. [Forked](https://github.com/taxjar/model_attribute) to handle floats and more types.
21
+ * [model_attribute](https://github.com/yammer/model_attribute) - Type casted attributes for non-ActiveRecord models.
22
22
 
23
23
  ## Installation
24
24
 
@@ -26,15 +26,20 @@ module Taxjar
26
26
  end
27
27
 
28
28
  def perform
29
- options_key = @request_method == :get ? :params : :json
30
- response = HTTP.timeout(@http_timeout).headers(headers)
31
- .request(request_method, uri.to_s, options_key => @options)
29
+ options_key = [:get, :delete].include?(@request_method) ? :params : :json
30
+ response = build_http_client.request(request_method, uri.to_s, options_key => @options)
32
31
  response_body = symbolize_keys!(response.parse)
33
32
  fail_or_return_response_body(response.code, response_body)
34
33
  end
35
34
 
36
35
  private
37
36
 
37
+ def build_http_client
38
+ http_client = HTTP.timeout(@http_timeout).headers(headers)
39
+ http_client = http_client.via(*client.http_proxy) if client.http_proxy
40
+ http_client
41
+ end
42
+
38
43
  def set_request_headers(custom_headers = {})
39
44
  @headers = {}
40
45
  @headers[:user_agent] = client.user_agent
@@ -16,6 +16,7 @@ module Taxjar
16
16
  attr_accessor :api_key
17
17
  attr_accessor :api_url
18
18
  attr_accessor :headers
19
+ attr_accessor :http_proxy
19
20
 
20
21
  def initialize(options = {})
21
22
  options.each do |key, value|
@@ -3,10 +3,11 @@ require 'taxjar/base'
3
3
  module Taxjar
4
4
  class Order < Taxjar::Base
5
5
  extend ModelAttribute
6
-
6
+
7
7
  attribute :transaction_id, :string
8
8
  attribute :user_id, :integer
9
9
  attribute :transaction_date, :string
10
+ attribute :provider, :string
10
11
  attribute :from_country, :string
11
12
  attribute :from_zip, :string
12
13
  attribute :from_state, :string
@@ -3,11 +3,12 @@ require 'taxjar/base'
3
3
  module Taxjar
4
4
  class Refund < Taxjar::Base
5
5
  extend ModelAttribute
6
-
6
+
7
7
  attribute :transaction_id, :string
8
8
  attribute :user_id, :integer
9
9
  attribute :transaction_date, :string
10
10
  attribute :transaction_reference_id, :string
11
+ attribute :provider, :string
11
12
  attribute :from_country, :string
12
13
  attribute :from_zip, :string
13
14
  attribute :from_state, :string
@@ -6,11 +6,11 @@ module Taxjar
6
6
  end
7
7
 
8
8
  def minor
9
- 4
9
+ 5
10
10
  end
11
11
 
12
12
  def patch
13
- 1
13
+ 0
14
14
  end
15
15
 
16
16
  def pre
@@ -3,6 +3,7 @@
3
3
  "transaction_id": "123",
4
4
  "user_id": 10649,
5
5
  "transaction_date": "2015-05-14T00:00:00Z",
6
+ "provider": "api",
6
7
  "from_country": "US",
7
8
  "from_zip": "93107",
8
9
  "from_state": "CA",
@@ -4,6 +4,7 @@
4
4
  "user_id": 10649,
5
5
  "transaction_date": "2015-05-14T00:00:00Z",
6
6
  "transaction_reference_id": "123",
7
+ "provider": "api",
7
8
  "from_country": "US",
8
9
  "from_zip": "93107",
9
10
  "from_state": "CA",
@@ -28,7 +28,7 @@ describe Taxjar::API::Order do
28
28
 
29
29
  context "with parameters" do
30
30
  before do
31
- stub_get('/v2/transactions/orders?from_transaction_date=2015/05/01&to_transaction_date=2015/05/31').
31
+ stub_get('/v2/transactions/orders?from_transaction_date=2015/05/01&to_transaction_date=2015/05/31&provider=api').
32
32
  to_return(body: fixture('orders.json'),
33
33
  headers: {content_type: 'application/json; charset=utf-8'})
34
34
 
@@ -36,13 +36,15 @@ describe Taxjar::API::Order do
36
36
 
37
37
  it 'requests the right resource' do
38
38
  @client.list_orders(from_transaction_date: '2015/05/01',
39
- to_transaction_date: '2015/05/31')
40
- expect(a_get('/v2/transactions/orders?from_transaction_date=2015/05/01&to_transaction_date=2015/05/31')).to have_been_made
39
+ to_transaction_date: '2015/05/31',
40
+ provider: 'api')
41
+ expect(a_get('/v2/transactions/orders?from_transaction_date=2015/05/01&to_transaction_date=2015/05/31&provider=api')).to have_been_made
41
42
  end
42
43
 
43
44
  it 'returns the requested orders' do
44
45
  orders = @client.list_orders(from_transaction_date: '2015/05/01',
45
- to_transaction_date: '2015/05/31')
46
+ to_transaction_date: '2015/05/31',
47
+ provider: 'api')
46
48
  expect(orders).to be_an Array
47
49
  expect(orders.first).to be_a String
48
50
  expect(orders.first).to eq('123')
@@ -52,22 +54,23 @@ describe Taxjar::API::Order do
52
54
 
53
55
  describe "#show_order" do
54
56
  before do
55
- stub_get('/v2/transactions/orders/123').
57
+ stub_get('/v2/transactions/orders/123?provider=api').
56
58
  to_return(body: fixture('order.json'),
57
59
  headers: {content_type: 'application/json; charset=utf-8'})
58
60
  end
59
61
 
60
62
  it 'requests the right resource' do
61
- @client.show_order('123')
62
- expect(a_get('/v2/transactions/orders/123')).to have_been_made
63
+ @client.show_order('123', provider: 'api')
64
+ expect(a_get('/v2/transactions/orders/123?provider=api')).to have_been_made
63
65
  end
64
66
 
65
67
  it 'returns the requested order' do
66
- order = @client.show_order('123')
68
+ order = @client.show_order('123', provider: 'api')
67
69
  expect(order).to be_an Taxjar::Order
68
70
  expect(order.transaction_id).to eq('123')
69
71
  expect(order.user_id).to eq(10649)
70
72
  expect(order.transaction_date).to eq('2015-05-14T00:00:00Z')
73
+ expect(order.provider).to eq('api')
71
74
  expect(order.from_country).to eq('US')
72
75
  expect(order.from_zip).to eq('93107')
73
76
  expect(order.from_state).to eq('CA')
@@ -84,7 +87,7 @@ describe Taxjar::API::Order do
84
87
  end
85
88
 
86
89
  it 'allows access to line_items' do
87
- order = @client.show_order('123')
90
+ order = @client.show_order('123', provider: 'api')
88
91
  expect(order.line_items[0].id).to eq('1')
89
92
  expect(order.line_items[0].quantity).to eq(1)
90
93
  expect(order.line_items[0].product_identifier).to eq('12-34243-9')
@@ -103,6 +106,7 @@ describe Taxjar::API::Order do
103
106
 
104
107
  @order = {:transaction_id => '123',
105
108
  :transaction_date => '2015/05/14',
109
+ :provider => 'api',
106
110
  :to_country => 'US',
107
111
  :to_zip => '90002',
108
112
  :to_city => 'Los Angeles',
@@ -132,6 +136,7 @@ describe Taxjar::API::Order do
132
136
  expect(order.transaction_id).to eq('123')
133
137
  expect(order.user_id).to eq(10649)
134
138
  expect(order.transaction_date).to eq("2015-05-14T00:00:00Z")
139
+ expect(order.provider).to eq('api')
135
140
  expect(order.from_country).to eq('US')
136
141
  expect(order.from_zip).to eq('93107')
137
142
  expect(order.from_state).to eq('CA')
@@ -146,7 +151,7 @@ describe Taxjar::API::Order do
146
151
  expect(order.shipping).to eq(1.5)
147
152
  expect(order.sales_tax).to eq(0.95)
148
153
  end
149
-
154
+
150
155
  it 'allows access to line_items' do
151
156
  order = @client.create_order(@order)
152
157
  expect(order.line_items[0].id).to eq('1')
@@ -191,6 +196,7 @@ describe Taxjar::API::Order do
191
196
  expect(order.transaction_id).to eq('123')
192
197
  expect(order.user_id).to eq(10649)
193
198
  expect(order.transaction_date).to eq("2015-05-14T00:00:00Z")
199
+ expect(order.provider).to eq('api')
194
200
  expect(order.from_country).to eq('US')
195
201
  expect(order.from_zip).to eq('93107')
196
202
  expect(order.from_state).to eq('CA')
@@ -205,7 +211,7 @@ describe Taxjar::API::Order do
205
211
  expect(order.shipping).to eq(1.5)
206
212
  expect(order.sales_tax).to eq(0.95)
207
213
  end
208
-
214
+
209
215
  it 'allows access to line_items' do
210
216
  order = @client.update_order(@order)
211
217
  expect(order.line_items[0].id).to eq('1')
@@ -221,22 +227,23 @@ describe Taxjar::API::Order do
221
227
 
222
228
  describe "#delete_order" do
223
229
  before do
224
- stub_delete('/v2/transactions/orders/123').
230
+ stub_delete('/v2/transactions/orders/123?provider=api').
225
231
  to_return(body: fixture('order.json'),
226
232
  headers: {content_type: 'application/json; charset=utf-8'})
227
233
  end
228
234
 
229
235
  it 'requests the right resource' do
230
- @client.delete_order('123')
231
- expect(a_delete('/v2/transactions/orders/123')).to have_been_made
236
+ @client.delete_order('123', provider: 'api')
237
+ expect(a_delete('/v2/transactions/orders/123?provider=api')).to have_been_made
232
238
  end
233
239
 
234
240
  it 'returns the deleted order' do
235
- order = @client.delete_order('123')
241
+ order = @client.delete_order('123', provider: 'api')
236
242
  expect(order).to be_an Taxjar::Order
237
243
  expect(order.transaction_id).to eq('123')
238
244
  expect(order.user_id).to eq(10649)
239
245
  expect(order.transaction_date).to eq("2015-05-14T00:00:00Z")
246
+ expect(order.provider).to eq('api')
240
247
  expect(order.from_country).to eq('US')
241
248
  expect(order.from_zip).to eq('93107')
242
249
  expect(order.from_state).to eq('CA')
@@ -251,9 +258,9 @@ describe Taxjar::API::Order do
251
258
  expect(order.shipping).to eq(1.5)
252
259
  expect(order.sales_tax).to eq(0.95)
253
260
  end
254
-
261
+
255
262
  it 'allows access to line items' do
256
- order = @client.delete_order('123')
263
+ order = @client.delete_order('123', provider: 'api')
257
264
  expect(order.line_items[0].id).to eq('1')
258
265
  expect(order.line_items[0].quantity).to eq(1)
259
266
  expect(order.line_items[0].product_identifier).to eq('12-34243-9')
@@ -28,7 +28,7 @@ describe Taxjar::API::Refund do
28
28
 
29
29
  context "with parameters" do
30
30
  before do
31
- stub_get('/v2/transactions/refunds?from_transaction_date=2015/05/01&to_transaction_date=2015/05/31').
31
+ stub_get('/v2/transactions/refunds?from_transaction_date=2015/05/01&to_transaction_date=2015/05/31&provider=api').
32
32
  to_return(body: fixture('refunds.json'),
33
33
  headers: {content_type: 'application/json; charset=utf-8'})
34
34
 
@@ -36,13 +36,15 @@ describe Taxjar::API::Refund do
36
36
 
37
37
  it 'requests the right resource' do
38
38
  @client.list_refunds(from_transaction_date: '2015/05/01',
39
- to_transaction_date: '2015/05/31')
40
- expect(a_get('/v2/transactions/refunds?from_transaction_date=2015/05/01&to_transaction_date=2015/05/31')).to have_been_made
39
+ to_transaction_date: '2015/05/31',
40
+ provider: 'api')
41
+ expect(a_get('/v2/transactions/refunds?from_transaction_date=2015/05/01&to_transaction_date=2015/05/31&provider=api')).to have_been_made
41
42
  end
42
43
 
43
44
  it 'returns the requested refunds' do
44
45
  refunds = @client.list_refunds(from_transaction_date: '2015/05/01',
45
- to_transaction_date: '2015/05/31')
46
+ to_transaction_date: '2015/05/31',
47
+ provider: 'api')
46
48
  expect(refunds).to be_an Array
47
49
  expect(refunds.first).to be_a String
48
50
  expect(refunds.first).to eq('321')
@@ -52,23 +54,24 @@ describe Taxjar::API::Refund do
52
54
 
53
55
  describe "#show_refund" do
54
56
  before do
55
- stub_get('/v2/transactions/refunds/321').
57
+ stub_get('/v2/transactions/refunds/321?provider=api').
56
58
  to_return(body: fixture('refund.json'),
57
59
  headers: {content_type: 'application/json; charset=utf-8'})
58
60
  end
59
61
 
60
62
  it 'requests the right resource' do
61
- @client.show_refund('321')
62
- expect(a_get('/v2/transactions/refunds/321')).to have_been_made
63
+ @client.show_refund('321', provider: 'api')
64
+ expect(a_get('/v2/transactions/refunds/321?provider=api')).to have_been_made
63
65
  end
64
66
 
65
67
  it 'returns the requested refund' do
66
- refund = @client.show_refund('321')
68
+ refund = @client.show_refund('321', provider: 'api')
67
69
  expect(refund).to be_an Taxjar::Refund
68
70
  expect(refund.transaction_id).to eq('321')
69
71
  expect(refund.user_id).to eq(10649)
70
72
  expect(refund.transaction_date).to eq("2015-05-14T00:00:00Z")
71
73
  expect(refund.transaction_reference_id).to eq("123")
74
+ expect(refund.provider).to eql('api')
72
75
  expect(refund.from_country).to eq('US')
73
76
  expect(refund.from_zip).to eq('93107')
74
77
  expect(refund.from_state).to eq('CA')
@@ -83,9 +86,9 @@ describe Taxjar::API::Refund do
83
86
  expect(refund.shipping).to eq(1.5)
84
87
  expect(refund.sales_tax).to eq(0.95)
85
88
  end
86
-
89
+
87
90
  it 'allows access to line_items' do
88
- refund = @client.show_refund('321')
91
+ refund = @client.show_refund('321', provider: 'api')
89
92
  expect(refund.line_items[0].id).to eq('1')
90
93
  expect(refund.line_items[0].quantity).to eq(1)
91
94
  expect(refund.line_items[0].product_identifier).to eq('12-34243-9')
@@ -105,6 +108,7 @@ describe Taxjar::API::Refund do
105
108
  @refund = {:transaction_id => '321',
106
109
  :transaction_date => '2015/05/14',
107
110
  :transaction_reference_id => '123',
111
+ :provider => 'api',
108
112
  :to_country => 'US',
109
113
  :to_zip => '90002',
110
114
  :to_state => 'CA',
@@ -135,6 +139,7 @@ describe Taxjar::API::Refund do
135
139
  expect(refund.user_id).to eq(10649)
136
140
  expect(refund.transaction_date).to eq("2015-05-14T00:00:00Z")
137
141
  expect(refund.transaction_reference_id).to eq("123")
142
+ expect(refund.provider).to eq('api')
138
143
  expect(refund.from_country).to eq('US')
139
144
  expect(refund.from_zip).to eq('93107')
140
145
  expect(refund.from_state).to eq('CA')
@@ -149,7 +154,7 @@ describe Taxjar::API::Refund do
149
154
  expect(refund.shipping).to eq(1.5)
150
155
  expect(refund.sales_tax).to eq(0.95)
151
156
  end
152
-
157
+
153
158
  it 'allows access to line_items' do
154
159
  refund = @client.create_refund(@refund)
155
160
  expect(refund.line_items[0].id).to eq('1')
@@ -195,6 +200,7 @@ describe Taxjar::API::Refund do
195
200
  expect(refund.user_id).to eq(10649)
196
201
  expect(refund.transaction_date).to eq("2015-05-14T00:00:00Z")
197
202
  expect(refund.transaction_reference_id).to eq("123")
203
+ expect(refund.provider).to eq('api')
198
204
  expect(refund.from_country).to eq('US')
199
205
  expect(refund.from_zip).to eq('93107')
200
206
  expect(refund.from_state).to eq('CA')
@@ -209,7 +215,7 @@ describe Taxjar::API::Refund do
209
215
  expect(refund.shipping).to eq(1.5)
210
216
  expect(refund.sales_tax).to eq(0.95)
211
217
  end
212
-
218
+
213
219
  it 'allows access to line_items' do
214
220
  refund = @client.update_refund(@refund)
215
221
  expect(refund.line_items[0].id).to eq('1')
@@ -225,23 +231,24 @@ describe Taxjar::API::Refund do
225
231
 
226
232
  describe "#delete_refund" do
227
233
  before do
228
- stub_delete('/v2/transactions/refunds/321').
234
+ stub_delete('/v2/transactions/refunds/321?provider=api').
229
235
  to_return(body: fixture('refund.json'),
230
236
  headers: {content_type: 'application/json; charset=utf-8'})
231
237
  end
232
238
 
233
239
  it 'requests the right resource' do
234
- @client.delete_refund('321')
235
- expect(a_delete('/v2/transactions/refunds/321')).to have_been_made
240
+ @client.delete_refund('321', provider: 'api')
241
+ expect(a_delete('/v2/transactions/refunds/321?provider=api')).to have_been_made
236
242
  end
237
243
 
238
- it 'returns the delete refund' do
239
- refund = @client.delete_refund('321')
244
+ it 'returns the deleted refund' do
245
+ refund = @client.delete_refund('321', provider: 'api')
240
246
  expect(refund).to be_an Taxjar::Refund
241
247
  expect(refund.transaction_id).to eq('321')
242
248
  expect(refund.user_id).to eq(10649)
243
249
  expect(refund.transaction_date).to eq("2015-05-14T00:00:00Z")
244
250
  expect(refund.transaction_reference_id).to eq("123")
251
+ expect(refund.provider).to eq('api')
245
252
  expect(refund.from_country).to eq('US')
246
253
  expect(refund.from_zip).to eq('93107')
247
254
  expect(refund.from_state).to eq('CA')
@@ -256,9 +263,9 @@ describe Taxjar::API::Refund do
256
263
  expect(refund.shipping).to eq(1.5)
257
264
  expect(refund.sales_tax).to eq(0.95)
258
265
  end
259
-
266
+
260
267
  it 'allows access to line_items' do
261
- refund = @client.delete_refund('321')
268
+ refund = @client.delete_refund('321', provider: 'api')
262
269
  expect(refund.line_items[0].id).to eq('1')
263
270
  expect(refund.line_items[0].quantity).to eq(1)
264
271
  expect(refund.line_items[0].product_identifier).to eq('12-34243-9')
@@ -119,6 +119,21 @@ 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
+ 'User-Agent'=>"TaxjarRubyGem/#{Taxjar::Version.to_s}"}).
129
+ to_return(:status => 200, :body => '{"object": {"id": "3"}}',
130
+ :headers => {content_type: 'application/json; charset=UTF-8'})
131
+
132
+ expect(subject.perform).to eq({id: '3'})
133
+ expect(subject.send(:build_http_client).default_options.proxy).to eq({proxy_address: "127.0.0.1", proxy_port: 8080})
134
+ end
135
+ end
136
+
122
137
  context 'with get' do
123
138
  it 'should return a body if no errors' do
124
139
  stub_request(:get, "https://api.taxjar.com/api_path").
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.4.1
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TaxJar
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-04 00:00:00.000000000 Z
11
+ date: 2019-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable