duty_calculator 0.0.3 → 0.0.4

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: 4e17b38949cd151f57b962118f76e516b0caaa5b
4
- data.tar.gz: 0b6202df8eebd58bccf47481085e7d280f7b56c2
3
+ metadata.gz: 5ed8beb4c4232821afa3d6f8be62dd98ed3b179f
4
+ data.tar.gz: ec47b5f65e53b2be578322d7bf25d04737692c7f
5
5
  SHA512:
6
- metadata.gz: de3cd369e239766070b6063cd4d8c1a449f224ec7d79d973156d1bd9c366e46d2e95648429b6a50c6ebc6ad9a58944d530e95fe1ea4542f339c6b5016790d53c
7
- data.tar.gz: d13462fcd66f9895397c1061555768f4921ec940b9430661a9cbf667affc47ea1c1e76d9668b61d1a71259ca01839d204cbde81c0da4bd22830a904f1ef2bd3a
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 classify_by shipping
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
- msg << r unless params.has_key?(r)
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
- # &currency={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
- uri = Addressable::URI.new
51
- uri.query_values = validate_params(params)
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?#{uri.query}"
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
-
@@ -1,3 +1,3 @@
1
1
  module DutyCalculator
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
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.3
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-02-06 00:00:00.000000000 Z
11
+ date: 2015-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler