taxjar-ruby 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -0
- data/lib/taxjar/api/request.rb +9 -1
- data/lib/taxjar/version.rb +1 -1
- data/spec/taxjar/api/request_spec.rb +18 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f04cd937c37f90f63af9d8f4eaacd665b1eae8fc
|
4
|
+
data.tar.gz: a8af540ee6ce4f1b7a86803d36caee6015de2460
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0948d65a802c3da92511a371225e7f0f6009f9c7f741819bcd51337a677bf34b616a1278ff0b7491c8c7da809244f2ca4b39e2d55aa72650ca0e4aa414c4f6c1
|
7
|
+
data.tar.gz: 7618b19eebd584ef60861e95186e33d9b6c4fa7b711a09a308bfdc4049ae6796fe5fb6ab32137ea148a395736327e8a7e1dd154beab29f0210117dfe6b342bbc
|
data/README.md
CHANGED
@@ -879,6 +879,18 @@ summarized_rates = client.summary_rates
|
|
879
879
|
]
|
880
880
|
```
|
881
881
|
|
882
|
+
### Custom Options
|
883
|
+
|
884
|
+
Pass a hash to any API method above for the following options:
|
885
|
+
|
886
|
+
#### Timeouts
|
887
|
+
|
888
|
+
Set request timeout in seconds:
|
889
|
+
|
890
|
+
```ruby
|
891
|
+
client.tax_for_order({ timeout: 30 })
|
892
|
+
```
|
893
|
+
|
882
894
|
## Tests
|
883
895
|
|
884
896
|
An RSpec test suite is available to ensure API functionality:
|
data/lib/taxjar/api/request.rb
CHANGED
@@ -20,11 +20,12 @@ module Taxjar
|
|
20
20
|
set_request_headers
|
21
21
|
@object_key = object_key
|
22
22
|
@options = options
|
23
|
+
set_http_timeout
|
23
24
|
end
|
24
25
|
|
25
26
|
def perform
|
26
27
|
options_key = @request_method == :get ? :params : :json
|
27
|
-
response = HTTP.with(headers).public_send(request_method, uri.to_s, options_key => @options)
|
28
|
+
response = HTTP.timeout(@http_timeout).with(headers).public_send(request_method, uri.to_s, options_key => @options)
|
28
29
|
response_body = symbolize_keys!(response.parse)
|
29
30
|
fail_or_return_response_body(response.code, response_body)
|
30
31
|
end
|
@@ -37,6 +38,13 @@ module Taxjar
|
|
37
38
|
@headers[:authorization] = "Bearer #{client.api_key}"
|
38
39
|
end
|
39
40
|
|
41
|
+
def set_http_timeout
|
42
|
+
@http_timeout = {}
|
43
|
+
@http_timeout[:write] = @options[:timeout]
|
44
|
+
@http_timeout[:connect] = @options[:timeout]
|
45
|
+
@http_timeout[:read] = @options[:timeout]
|
46
|
+
end
|
47
|
+
|
40
48
|
def symbolize_keys!(object)
|
41
49
|
if object.is_a?(Array)
|
42
50
|
object.each_with_index do |val, index|
|
data/lib/taxjar/version.rb
CHANGED
@@ -65,6 +65,23 @@ describe Taxjar::API::Request do
|
|
65
65
|
subject = Taxjar::API::Request.new(client, :get, '/api_path', 'object', options)
|
66
66
|
expect(subject.options).to eq(options)
|
67
67
|
end
|
68
|
+
|
69
|
+
context 'timeout' do
|
70
|
+
it 'should initialize nil timeout if not set' do
|
71
|
+
client = Taxjar::Client.new(api_key: 'AK')
|
72
|
+
subject = Taxjar::API::Request.new(client, :get, '/api_path', 'object', {})
|
73
|
+
|
74
|
+
expect(subject.instance_variable_get(:@http_timeout)).to eq({write: nil, read: nil, connect: nil})
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should take a timeout option and set timeout for request' do
|
78
|
+
options = {timeout: 1}
|
79
|
+
client = Taxjar::Client.new(api_key: 'AK')
|
80
|
+
subject = Taxjar::API::Request.new(client, :get, '/api_path', 'object', options)
|
81
|
+
|
82
|
+
expect(subject.instance_variable_get(:@http_timeout)).to eq({write: 1, read: 1, connect: 1})
|
83
|
+
end
|
84
|
+
end
|
68
85
|
end
|
69
86
|
|
70
87
|
end
|
@@ -119,7 +136,7 @@ describe Taxjar::API::Request do
|
|
119
136
|
with(:headers => {'Authorization'=>'Bearer AK', 'Connection'=>'close',
|
120
137
|
'Host'=>'api.taxjar.com',
|
121
138
|
'User-Agent'=>"TaxjarRubyGem/#{Taxjar::Version.to_s}"}).
|
122
|
-
to_return(:status => status,
|
139
|
+
to_return(:status => status,
|
123
140
|
:body => '{"error": "Not Acceptable",
|
124
141
|
"detail": "error explanation",
|
125
142
|
"status": "'+ status.to_s + '"}',
|
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: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TaxJar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|