Class: Io::Flow::V0::Clients::DutyItemProducers

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ DutyItemProducers

Returns a new instance of DutyItemProducers.



6014
6015
6016
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6014

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

Instance Method Details

#delete_by_key(organization, key) ⇒ Object



6057
6058
6059
6060
6061
6062
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6057

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

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

Retrieve duty item producers.



6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6019

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) }),
    :key => (x = opts.delete(:key); x.nil? ? nil : HttpClient::Preconditions.assert_class('key', x, 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? ? "name" : x), String)
  }.delete_if { |k, v| v.nil? }
  r = @client.request("/#{CGI.escape(organization)}/duty/item/producers").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::DutyItemProducer.new(x) }
end

#get_by_key(organization, key) ⇒ Object

Retrieve a duty item producer.



6042
6043
6044
6045
6046
6047
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6042

def get_by_key(organization, key)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  r = @client.request("/#{CGI.escape(organization)}/duty/item/producers/#{CGI.escape(key)}").get
  ::Io::Flow::V0::Models::DutyItemProducer.new(r)
end

#post(organization, duty_item_producer) ⇒ Object

Add a duty item producer.



6034
6035
6036
6037
6038
6039
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6034

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

#put_by_key(organization, key, duty_item_producer) ⇒ Object



6049
6050
6051
6052
6053
6054
6055
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6049

def put_by_key(organization, key, duty_item_producer)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('key', key, String)
  (x = duty_item_producer; x.is_a?(::Io::Flow::V0::Models::DutyItemProducer) ? x : ::Io::Flow::V0::Models::DutyItemProducer.new(x))
  r = @client.request("/#{CGI.escape(organization)}/duty/item/producers/#{CGI.escape(key)}").with_json(duty_item_producer.to_json).put
  ::Io::Flow::V0::Models::DutyItemProducer.new(r)
end