Class: Io::Flow::V0::Clients::TradeAgreements

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ TradeAgreements

Returns a new instance of TradeAgreements.



8994
8995
8996
# 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

Instance Method Details

#delete_by_key(key) ⇒ Object



9037
9038
9039
9040
9041
# 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 = {}) ⇒ Object

Retrieve global trade agreements.



8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
# 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) ⇒ Object

Retrieve a global trade agreement.



9024
9025
9026
9027
9028
# 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) ⇒ Object

Add a global trade agreement.



9017
9018
9019
9020
9021
# 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) ⇒ Object



9030
9031
9032
9033
9034
9035
# 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