duty_calculator 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/duty_calculator.gemspec +2 -2
- data/lib/duty_calculator/calculation.rb +19 -13
- data/lib/duty_calculator/client.rb +0 -2
- data/lib/duty_calculator/version.rb +1 -1
- data/spec/duty_calculator/calculation_spec.rb +53 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: da4d51bf8a977b247e81ccc0e740f83e6d32a513
|
4
|
+
data.tar.gz: ad9381a27607fb9e63ab1d388ad5c2fba5fd05c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dbc1d596554960cc2c69d812de23aa99cdd4197a13652028f61af8a7d99057c7444cb56ad69f3bc2eee424233f36282fd74d6ccc7bdf5d32351dec1fd82b5f5c
|
7
|
+
data.tar.gz: f1531aff60374c32f2769ca52094464bbc5eb331e8c3d65a5a5de3372c848bdf239d168e340c6819bf4541f6e25f6f9e0afa2d352d90e1a0e3dde83a0490757a
|
data/duty_calculator.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'duty_calculator/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "duty_calculator"
|
8
8
|
spec.version = DutyCalculator::VERSION
|
9
|
-
spec.authors = ["Thomas Hanley"]
|
10
|
-
spec.email = ["tom@walkerandcompany.com"]
|
9
|
+
spec.authors = ["Thomas Hanley", "Rachel Heaton"]
|
10
|
+
spec.email = ["tom@walkerandcompany.com", "rachel@walkerandcompany.com"]
|
11
11
|
spec.summary = %q{Wrapper for dutycalculator.com}
|
12
12
|
spec.description = %q{API documentation http://www.dutycalculator.com/api-center/dutycalculator-api-2-1-documentation/}
|
13
13
|
spec.homepage = "https://github.com/tjhanley/duty-calculator"
|
@@ -16,26 +16,32 @@ module DutyCalculator
|
|
16
16
|
raise ArgumentError, "Missing arguments from hash #{msg.to_s}" if msg.size >= 1
|
17
17
|
return params
|
18
18
|
end
|
19
|
-
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
memo
|
30
|
-
else
|
31
|
-
"#{k}=#{v}"
|
20
|
+
def transform_params(params)
|
21
|
+
params.inject({}) do |transformed, key_value|
|
22
|
+
k = key_value.first
|
23
|
+
v = key_value.last
|
24
|
+
if v.kind_of?(Array)
|
25
|
+
transformed[k] = {}
|
26
|
+
v.each_with_index do |value, index|
|
27
|
+
transformed[k][index] = value
|
32
28
|
end
|
29
|
+
else
|
30
|
+
transformed[k] = v
|
33
31
|
end
|
32
|
+
transformed
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.get(params={})
|
38
|
+
transformed_params = transform_params(validate_params(params))
|
34
39
|
conn = DutyCalculator::Client.new
|
35
|
-
resp = conn.get "#{DutyCalculator::Client.api_base}/calculation
|
40
|
+
resp = conn.get "#{DutyCalculator::Client.api_base}/calculation", transformed_params
|
36
41
|
raise Exception, "Duty Calculator Error: #{DutyCalculator::ErrorMessages.for_code(resp.body["error"]["code"])}" if resp.body["error"]
|
37
42
|
raise Exception, "HTTP Status Code #{resp.status}" if resp.status.to_i != 200
|
38
43
|
return resp.body
|
39
44
|
end
|
45
|
+
|
40
46
|
end
|
41
47
|
end
|
@@ -6,8 +6,6 @@ module DutyCalculator
|
|
6
6
|
# middleware
|
7
7
|
faraday.use FaradayMiddleware::FollowRedirects
|
8
8
|
faraday.use FaradayMiddleware::EncodeJson
|
9
|
-
# request defs
|
10
|
-
faraday.use Faraday::Request::UrlEncoded
|
11
9
|
# response defs
|
12
10
|
faraday.use Faraday::Response::ParseXml
|
13
11
|
faraday.use Faraday::Response::Mashify
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module DutyCalculator
|
4
|
+
describe Configuration do
|
5
|
+
describe ".transform_params" do
|
6
|
+
context "for a single product" do
|
7
|
+
let(:params) do
|
8
|
+
{
|
9
|
+
from: "US",
|
10
|
+
to: "CA",
|
11
|
+
shipping_mode: "USPS",
|
12
|
+
insurance: 0.0,
|
13
|
+
currency: "USD",
|
14
|
+
cat: [ "1234.00" ],
|
15
|
+
hs: [ "CA" ],
|
16
|
+
sku: [ "300101" ],
|
17
|
+
qty: [ 1 ]
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
it "makes a hash with numerical index keys for array values" do
|
22
|
+
transformed = DutyCalculator::Calculation.transform_params(params)
|
23
|
+
|
24
|
+
expect(transformed["from"]).to eq(params[:from])
|
25
|
+
expect(transformed["cat"]).to eq({ 0 => params[:cat].first })
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "for multiple products" do
|
30
|
+
let(:params) do
|
31
|
+
{
|
32
|
+
from: "US",
|
33
|
+
to: "CA",
|
34
|
+
shipping_mode: "USPS",
|
35
|
+
insurance: 0.0,
|
36
|
+
currency: "USD",
|
37
|
+
cat: [ "1234.00", "5678.00" ],
|
38
|
+
hs: [ "CA", "CA" ],
|
39
|
+
sku: [ "300101", "300102" ],
|
40
|
+
qty: [ 1, 2 ]
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
it "makes a hash with numerical index keys for array values" do
|
45
|
+
transformed = DutyCalculator::Calculation.transform_params(params)
|
46
|
+
|
47
|
+
expect(transformed["from"]).to eq(params[:from])
|
48
|
+
expect(transformed["cat"]).to eq({ 0 => params[:cat].first, 1 => params[:cat].last })
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duty_calculator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Hanley
|
8
|
+
- Rachel Heaton
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
12
|
+
date: 2015-03-30 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -111,6 +112,7 @@ dependencies:
|
|
111
112
|
description: API documentation http://www.dutycalculator.com/api-center/dutycalculator-api-2-1-documentation/
|
112
113
|
email:
|
113
114
|
- tom@walkerandcompany.com
|
115
|
+
- rachel@walkerandcompany.com
|
114
116
|
executables: []
|
115
117
|
extensions: []
|
116
118
|
extra_rdoc_files: []
|
@@ -132,6 +134,7 @@ files:
|
|
132
134
|
- lib/duty_calculator/currency.rb
|
133
135
|
- lib/duty_calculator/error_messages.rb
|
134
136
|
- lib/duty_calculator/version.rb
|
137
|
+
- spec/duty_calculator/calculation_spec.rb
|
135
138
|
- spec/duty_calculator/configuration_spec.rb
|
136
139
|
- spec/duty_calculator/currency_spec.rb
|
137
140
|
- spec/spec_helper.rb
|
@@ -160,6 +163,7 @@ signing_key:
|
|
160
163
|
specification_version: 4
|
161
164
|
summary: Wrapper for dutycalculator.com
|
162
165
|
test_files:
|
166
|
+
- spec/duty_calculator/calculation_spec.rb
|
163
167
|
- spec/duty_calculator/configuration_spec.rb
|
164
168
|
- spec/duty_calculator/currency_spec.rb
|
165
169
|
- spec/spec_helper.rb
|