Class: Io::Flow::V0::Clients::HsCodes

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ HsCodes

Returns a new instance of HsCodes.



2355
2356
2357
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2355

def initialize(client)
  @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client)
end

Instance Method Details

#get(incoming = {}) ⇒ Object

Search harmonization codes. Always paginated.



2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2360

def get(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :code => (x = opts.delete(:code); x.nil? ? nil : HttpClient::Preconditions.assert_class('code', x, Array).map { |v| HttpClient::Preconditions.assert_class('code', v, String) }),
    :parent => (x = opts.delete(:parent); x.nil? ? nil : HttpClient::Preconditions.assert_class('parent', x, String)),
    :has_parent => (x = opts.delete(:has_parent); x.nil? ? nil : HttpClient::Preconditions.assert_boolean('has_parent', x)),
    :limit => HttpClient::Preconditions.assert_class('limit', (x = opts.delete(:limit); x.nil? ? 25 : x), Integer),
    :offset => HttpClient::Preconditions.assert_class('offset', (x = opts.delete(:offset); x.nil? ? 0 : x), Integer),
    :sort => HttpClient::Preconditions.assert_class('sort', (x = opts.delete(:sort); x.nil? ? "code" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/harmonization/codes").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::HsCode.new(x) }
end

#get_by_code(code) ⇒ Object

Returns information about a specific harmonization code.



2375
2376
2377
2378
2379
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 2375

def get_by_code(code)
  HttpClient::Preconditions.assert_class('code', code, String)
  r = @client.request("/harmonization/codes/#{CGI.escape(code)}").get
  ::Io::Flow::V0::Models::HsCode.new(r)
end