Class: DutyCalculator::Calculation

Inherits:
Object
  • Object
show all
Defined in:
lib/duty_calculator/calculation.rb

Class Method Summary collapse

Class Method Details

.get(params = {}) ⇒ Object

# docs.google.com/a/walkerandcobrands.com/document/d/16e_lh7MIjLGYvS_qZL7pUzOvTVte-cqTnr4jGo_VtIM/pub # from= alpha-3 country code or alpha-2 country code \ # &to= alpha-3 country code or alpha-2 country code \ # &province=alpha-2 province code of ‘importing to’ country (only required for Canada and Brazil) \ # &shipping_mode=mode \ # &commercial_importer=status (only required for Russia) \ # &imported_wt=weight of products imported during the month (only required for Russia) \ # &imported_value=value of products imported during the month (only required for Russia) \ # &classify_by=classification identifier \ # &cat=ID or category ID \ # &hs=HS code \ # &country_of_hs_code= alpha-3 country code or alpha-2 country code \ # &desc=description \ # &sku={item sku } \ # &value=per one item \ # &weight=of one item \ # &qty=quantity \ # &origin=alpha-3 country code or alpha-2 country code \ # &reference=reference \ # &shipping=cost \ # &insurance=of insurance \ # &currency=currency code preferential # &output_currency=currency code \ # &preferential_rates=to apply FTA and preferential rates, 0 to ignore FTA and preferential rates \ # &detailed_result=for detailed result, 0 for short result \ # &incl_hs_codes=HS code for each item in response #



49
50
51
52
53
54
55
56
# File 'lib/duty_calculator/calculation.rb', line 49

def self.get(params={})
  uri = Addressable::URI.new
  uri.query_values = validate_params(params)

  conn = DutyCalculator::Client.new
  resp = conn.get "#{DutyCalculator::Client.api_base}/calculation?#{uri.query}"
  resp.body
end

.validate_params(params) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/duty_calculator/calculation.rb', line 6

def validate_params(params)
  required = %w{from to shipping_mode classify_by shipping
                insurance currency preferential_rates detailed_result incl_hs_codes cat
                hs country_of_hs_code desc
                sku value weight qty origin reference}
  msg = []
  required.each do |r|
    msg << r unless params.has_key?(r)
  end
  raise ArgumentError, "Missing arguments from hash #{msg.to_s}" if msg.size
  return params
end