taxjar-ruby 1.3.0 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: de60a587fe7825100a642391d002f1c99d52f0ab
4
- data.tar.gz: e92d5eec0d405dfe7ac2de168bbb996d714fb687
3
+ metadata.gz: f04cd937c37f90f63af9d8f4eaacd665b1eae8fc
4
+ data.tar.gz: a8af540ee6ce4f1b7a86803d36caee6015de2460
5
5
  SHA512:
6
- metadata.gz: 99d505a853e4c8d01f1126ff3f5dbfb8698a3e2dbc63bb14ff9fcd431cd196d9a73e584775587cc61d101b1b78e26b80eb8212ae5a478903530d6d226cf705d4
7
- data.tar.gz: 6ea9d5d6d01e8235f2d2d47e5e4e21c5a2388e83ddb05bbdf4b09611bcbef0595b79bf3f522cd16fed2cde859134b8860ca0c9bdf90704e898d8f8c214eca6de
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:
@@ -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|
@@ -10,7 +10,7 @@ module Taxjar
10
10
  end
11
11
 
12
12
  def patch
13
- 0
13
+ 1
14
14
  end
15
15
 
16
16
  def pre
@@ -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, :body => '{}',
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.0
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-03-04 00:00:00.000000000 Z
11
+ date: 2016-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable