Class: Io::Flow::V0::Clients::OrderEstimates

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ OrderEstimates

Returns a new instance of OrderEstimates.



967
968
969
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 967

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

Instance Method Details

#get_by_id(organization, id) ⇒ Object



990
991
992
993
994
995
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 990

def get_by_id(organization, id)
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/#{CGI.escape(organization)}/order-estimates/#{CGI.escape(id)}").get
  ::Io::Flow::V0::Models::Experience.new(r)
end

#post(organization, order_estimate_form, incoming = {}) ⇒ Object

Create an order estimate, using the localized information from the experience selected by the query parameters. This is similar to the POST orders endpoint, except this just returns an estimate and cannot be submitted.



975
976
977
978
979
980
981
982
983
984
985
986
987
988
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 975

def post(organization, order_estimate_form, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :experience => (x = opts.delete(:experience); x.nil? ? nil : HttpClient::Preconditions.assert_class('experience', x, String)),
    :country => (x = opts.delete(:country); x.nil? ? nil : HttpClient::Preconditions.assert_class('country', x, String)),
    :ip => (x = opts.delete(:ip); x.nil? ? nil : HttpClient::Preconditions.assert_class('ip', x, String)),
    :currency => (x = opts.delete(:currency); x.nil? ? nil : HttpClient::Preconditions.assert_class('currency', x, String)),
    :language => (x = opts.delete(:language); x.nil? ? nil : HttpClient::Preconditions.assert_class('language', x, String))
  }.delete_if { |k, v| v.nil? }
  HttpClient::Preconditions.assert_class('order_estimate_form', order_estimate_form, ::Io::Flow::V0::Models::OrderEstimateForm)
  r = @client.request("/#{CGI.escape(organization)}/order-estimates").with_query(query).with_json(order_estimate_form.to_json).post
  ::Io::Flow::V0::Models::OrderEstimate.new(r)
end

#put_by_id(organization, id, order_estimate_form, incoming = {}) ⇒ Object



997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 997

def put_by_id(organization, id, order_estimate_form, incoming={})
  HttpClient::Preconditions.assert_class('organization', organization, String)
  HttpClient::Preconditions.assert_class('id', id, String)
  opts = HttpClient::Helper.symbolize_keys(incoming)
  query = {
    :experience => (x = opts.delete(:experience); x.nil? ? nil : HttpClient::Preconditions.assert_class('experience', x, String)),
    :country => (x = opts.delete(:country); x.nil? ? nil : HttpClient::Preconditions.assert_class('country', x, String)),
    :ip => (x = opts.delete(:ip); x.nil? ? nil : HttpClient::Preconditions.assert_class('ip', x, String)),
    :currency => (x = opts.delete(:currency); x.nil? ? nil : HttpClient::Preconditions.assert_class('currency', x, String)),
    :language => (x = opts.delete(:language); x.nil? ? nil : HttpClient::Preconditions.assert_class('language', x, String))
  }.delete_if { |k, v| v.nil? }
  HttpClient::Preconditions.assert_class('order_estimate_form', order_estimate_form, ::Io::Flow::V0::Models::OrderEstimateForm)
  r = @client.request("/#{CGI.escape(organization)}/order-estimates/#{CGI.escape(id)}").with_query(query).with_json(order_estimate_form.to_json).put
  ::Io::Flow::V0::Models::OrderEstimate.new(r)
end