duty_calculator 0.0.3 → 0.0.4
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 +4 -4
- data/lib/duty_calculator/calculation.rb +20 -38
- data/lib/duty_calculator/version.rb +1 -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: 5ed8beb4c4232821afa3d6f8be62dd98ed3b179f
|
4
|
+
data.tar.gz: ec47b5f65e53b2be578322d7bf25d04737692c7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69ae696b897280cf5a2376a8a06fc87d7b784d87bd0acb3d59ec073af2ccd9668e134a38d1cce1d8e6edebda096ecc073a97be17375077e4fb40224ab3b67865
|
7
|
+
data.tar.gz: 88dbb06e724660c0ee0285cf651e13a3caf633f4f7fec2c18a8253918022a11c8a0df29d57e11e61d9d42ce2e849b318b5c50092593268f0351bcab96e63df39
|
@@ -4,56 +4,38 @@ module DutyCalculator
|
|
4
4
|
class Calculation
|
5
5
|
class << self
|
6
6
|
def validate_params(params)
|
7
|
-
required = %w{from to shipping_mode
|
7
|
+
required = %w{from to shipping_mode shipping
|
8
8
|
insurance currency preferential_rates detailed_result incl_hs_codes cat
|
9
9
|
hs country_of_hs_code desc
|
10
10
|
sku value weight qty origin reference}
|
11
11
|
msg = []
|
12
12
|
required.each do |r|
|
13
|
-
|
13
|
+
# ensure keys are strings
|
14
|
+
msg << r unless params.inject({}){|memo,(k,v)| memo[k.to_s] = v; memo}.has_key?(r)
|
14
15
|
end
|
15
|
-
raise ArgumentError, "Missing arguments from hash #{msg.to_s}" if msg.size
|
16
|
+
raise ArgumentError, "Missing arguments from hash #{msg.to_s}" if msg.size >= 1
|
16
17
|
return params
|
17
18
|
end
|
18
19
|
end
|
19
20
|
|
20
|
-
=begin
|
21
|
-
# https://docs.google.com/a/walkerandcobrands.com/document/d/16e_lh7MIjLGYvS_qZL7pUzOvTVte-cqTnr4jGo_VtIM/pub
|
22
|
-
# from={ISO alpha-3 country code or alpha-2 country code} \
|
23
|
-
# &to={ISO alpha-3 country code or alpha-2 country code} \
|
24
|
-
# &province={ISO alpha-2 province code of ‘importing to’ country (only required for Canada and Brazil)} \
|
25
|
-
# &shipping_mode={shipping mode} \
|
26
|
-
# &commercial_importer={importer status (only required for Russia)} \
|
27
|
-
# &imported_wt={total weight of products imported during the month (only required for Russia)} \
|
28
|
-
# &imported_value={total value of products imported during the month (only required for Russia)} \
|
29
|
-
# &classify_by={items classification identifier} \
|
30
|
-
# &cat[0]={item ID or category ID} \
|
31
|
-
# &hs[0]={item HS code} \
|
32
|
-
# &country_of_hs_code[0]={ISO alpha-3 country code or alpha-2 country code} \
|
33
|
-
# &desc[0]={product description} \
|
34
|
-
# &sku[0]={item sku } \
|
35
|
-
# &value[0]={value per one item} \
|
36
|
-
# &weight[0]={weight of one item} \
|
37
|
-
# &qty[0]={item quantity} \
|
38
|
-
# &origin[0]={ISO alpha-3 country code or alpha-2 country code} \
|
39
|
-
# &reference[0]={product reference} \
|
40
|
-
# &shipping={shipping cost} \
|
41
|
-
# &insurance={cost of insurance} \
|
42
|
-
# ¤cy={ISO currency code} \preferential
|
43
|
-
# &output_currency={ISO currency code} \
|
44
|
-
# &preferential_rates={1 to apply FTA and preferential rates, 0 to ignore FTA and preferential rates} \
|
45
|
-
# &detailed_result={1 for detailed result, 0 for short result} \
|
46
|
-
# &incl_hs_codes={include HS code for each item in response}
|
47
|
-
#
|
48
|
-
=end
|
49
21
|
def self.get(params={})
|
50
|
-
|
51
|
-
|
52
|
-
|
22
|
+
qs = params.collect do |k,v|
|
23
|
+
if v.kind_of?(Array)
|
24
|
+
memo = ""
|
25
|
+
v.each_with_index do |value, index|
|
26
|
+
memo << "#{k}[#{index}]=#{value}"
|
27
|
+
memo << "&" if v.size > (index+1)
|
28
|
+
end
|
29
|
+
memo
|
30
|
+
else
|
31
|
+
"#{k}=#{v}"
|
32
|
+
end
|
33
|
+
end
|
53
34
|
conn = DutyCalculator::Client.new
|
54
|
-
resp = conn.get "#{DutyCalculator::Client.api_base}/calculation?#{
|
55
|
-
resp.body
|
35
|
+
resp = conn.get "#{DutyCalculator::Client.api_base}/calculation?#{qs.join('&')}"
|
36
|
+
raise Exception, "Duty Calculator Error: #{DutyCalculator::ErrorMessages.for_code(resp.body["error"]["code"])}" if resp.body["error"]
|
37
|
+
raise Exception, "HTTP Status Code #{resp.status}" if resp.status.to_i != 200
|
38
|
+
return resp.body
|
56
39
|
end
|
57
40
|
end
|
58
41
|
end
|
59
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Hanley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|