class Io::Flow::V0::Clients::TradeAgreements

Public Class Methods

new(client) click to toggle source
# File lib/flow_commerce/flow_api_v0_client.rb, line 8994
def initialize(client)
  @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client)
end

Public Instance Methods

delete_by_key(key) click to toggle source
# File lib/flow_commerce/flow_api_v0_client.rb, line 9037
def delete_by_key(key)
  HttpClient::Preconditions.assert_class('key', key, String)
  r = @client.request("/trade/agreements/#{CGI.escape(key)}").delete
  nil
end
get(incoming={}) click to toggle source

Retrieve global trade agreements.

# File lib/flow_commerce/flow_api_v0_client.rb, line 8999
def get(incoming={})
  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)),
    :name => (x = opts.delete(:name); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::TradeAgreementName) ? x : ::Io::Flow::V0::Models::TradeAgreementName.apply(x)).value),
    :origin => (x = opts.delete(:origin); x.nil? ? nil : HttpClient::Preconditions.assert_class('origin', x, String)),
    :destinations => (x = opts.delete(:destinations); x.nil? ? nil : HttpClient::Preconditions.assert_class('destinations', x, Array).map { |v| HttpClient::Preconditions.assert_class('destinations', v, String) }),
    :ship_from => (x = opts.delete(:ship_from); x.nil? ? nil : HttpClient::Preconditions.assert_class('ship_from', x, Array).map { |v| HttpClient::Preconditions.assert_class('ship_from', 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("/trade/agreements").with_query(query).get
  r.map { |x| ::Io::Flow::V0::Models::TradeAgreement.new(x) }
end
get_by_key(key) click to toggle source

Retrieve a global trade agreement.

# File lib/flow_commerce/flow_api_v0_client.rb, line 9024
def get_by_key(key)
  HttpClient::Preconditions.assert_class('key', key, String)
  r = @client.request("/trade/agreements/#{CGI.escape(key)}").get
  ::Io::Flow::V0::Models::TradeAgreement.new(r)
end
post(trade_agreement) click to toggle source

Add a global trade agreement.

# File lib/flow_commerce/flow_api_v0_client.rb, line 9017
def post(trade_agreement)
  (x = trade_agreement; x.is_a?(::Io::Flow::V0::Models::TradeAgreement) ? x : ::Io::Flow::V0::Models::TradeAgreement.new(x))
  r = @client.request("/trade/agreements").with_json(trade_agreement.to_json).post
  ::Io::Flow::V0::Models::TradeAgreement.new(r)
end
put_by_key(key, trade_agreement) click to toggle source
# File lib/flow_commerce/flow_api_v0_client.rb, line 9030
def put_by_key(key, trade_agreement)
  HttpClient::Preconditions.assert_class('key', key, String)
  (x = trade_agreement; x.is_a?(::Io::Flow::V0::Models::TradeAgreement) ? x : ::Io::Flow::V0::Models::TradeAgreement.new(x))
  r = @client.request("/trade/agreements/#{CGI.escape(key)}").with_json(trade_agreement.to_json).put
  ::Io::Flow::V0::Models::TradeAgreement.new(r)
end