Class: Io::Flow::V0::Clients::DutyItems

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ DutyItems

Returns a new instance of DutyItems.



5942
5943
5944
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5942

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

Instance Method Details

#delete_by_number(organization, number) ⇒ Object



5987
5988
5989
5990
5991
5992
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5987

def delete_by_number(organization, number)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  r = @client.request("/#{CGI.escape(organization)}/duty/items/#{CGI.escape(number)}").delete
  nil
end

#get(organization, incoming = {}) ⇒ Object

Retrieve duty items.



5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5947

def get(organization, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :id => (x = opts.delete(:id); x.nil? ? nil : HttpClient::Preconditions.assert_class('id', x, Array).map { |v| HttpClient::Preconditions.assert_class('id', v, String) }),
    :number => (x = opts.delete(:number); x.nil? ? nil : HttpClient::Preconditions.assert_class('number', x, Array).map { |v| HttpClient::Preconditions.assert_class('number', v, String) }),
    :product_id => (x = opts.delete(:product_id); x.nil? ? nil : HttpClient::Preconditions.assert_class('product_id', x, Array).map { |v| HttpClient::Preconditions.assert_class('product_id', v, String) }),
    :sku => (x = opts.delete(:sku); x.nil? ? nil : HttpClient::Preconditions.assert_class('sku', x, Array).map { |v| HttpClient::Preconditions.assert_class('sku', v, String) }),
    :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? ? "-created_at" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/duty/items").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::DutyItem.new(x) }
end

#get_by_number(organization, number) ⇒ Object

Retrieve a duty item.



5972
5973
5974
5975
5976
5977
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5972

def get_by_number(organization, number)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  r = @client.request("/#{CGI.escape(organization)}/duty/items/#{CGI.escape(number)}").get
  ::Io::Flow::V0::Models::DutyItem.new(r)
end

#post(organization, duty_item_form) ⇒ Object

Add a duty item.



5964
5965
5966
5967
5968
5969
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5964

def post(organization, duty_item_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  (x = duty_item_form; x.is_a?(::Io::Flow::V0::Models::DutyItemForm) ? x : ::Io::Flow::V0::Models::DutyItemForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/duty/items").with_json(duty_item_form.to_json).post
  ::Io::Flow::V0::Models::DutyItem.new(r)
end

#put_by_number(organization, number, duty_item_form) ⇒ Object



5979
5980
5981
5982
5983
5984
5985
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 5979

def put_by_number(organization, number, duty_item_form)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('number', number, String)
  (x = duty_item_form; x.is_a?(::Io::Flow::V0::Models::DutyItemForm) ? x : ::Io::Flow::V0::Models::DutyItemForm.new(x))
  r = @client.request("/#{CGI.escape(organization)}/duty/items/#{CGI.escape(number)}").with_json(duty_item_form.to_json).put
  ::Io::Flow::V0::Models::DutyItem.new(r)
end