Class: Io::Flow::V0::Clients::Orders
- Inherits:
-
Object
- Object
- Io::Flow::V0::Clients::Orders
- Defined in:
- lib/flow_commerce/flow_api_v0_client.rb
Instance Method Summary collapse
-
#delete_by_number(organization, number) ⇒ Object
Delete an order.
-
#get(organization, incoming = {}) ⇒ Object
Search orders.
-
#get_by_number(organization, number, incoming = {}) ⇒ Object
Returns information about a specific order.
-
#get_identifier_by_identifier_number(organization, identifier_number, incoming = {}) ⇒ Object
Returns information about a specific order using an identifier number.
-
#get_versions(organization, incoming = {}) ⇒ Object
Provides visibility into recent changes of each order, including deletion.
-
#initialize(client) ⇒ Orders
constructor
A new instance of Orders.
-
#post(organization, order_form, incoming = {}) ⇒ Object
Create an order, using the localized information from the experience selected by the query parameters.
-
#put_by_number(organization, number, order_put_form, incoming = {}) ⇒ Object
Upserts an order.
-
#put_promotions_and_free_shipping_by_number_and_key(organization, number, key, free_shipping_order_promotion_form, incoming = {}) ⇒ Object
Creates a free shipping promotion to the order, automatically applying it to the order if the order meets the defined promotion trigger.
-
#put_submissions_by_number(organization, number, hash) ⇒ Object
Submits an order.
Constructor Details
#initialize(client) ⇒ Orders
Returns a new instance of Orders.
999 1000 1001 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 999 def initialize(client) @client = HttpClient::Preconditions.assert_class('client', client, ::Io::Flow::V0::Client) end |
Instance Method Details
#delete_by_number(organization, number) ⇒ Object
Delete an order. Note that production orders that have already been submitted cannot be deleted (you will see a 422 response in these cases).
1073 1074 1075 1076 1077 1078 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1073 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)}/orders/#{CGI.escape(number)}").delete nil end |
#get(organization, incoming = {}) ⇒ Object
Search orders. Always paginated.
1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1004 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) }), :identifier => (x = opts.delete(:identifier); x.nil? ? nil : HttpClient::Preconditions.assert_class('identifier', 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? ? "-created_at" : x), String), :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, String) }) }.delete_if { |k, v| v.nil? } r = @client.request("/#{CGI.escape(organization)}/orders").with_query(query).get r.map { |x| ::Io::Flow::V0::Models::Order.new(x) } end |
#get_by_number(organization, number, incoming = {}) ⇒ Object
Returns information about a specific order.
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1040 def get_by_number(organization, number, incoming={}) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('number', number, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, String) }) }.delete_if { |k, v| v.nil? } r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}").with_query(query).get ::Io::Flow::V0::Models::Order.new(r) end |
#get_identifier_by_identifier_number(organization, identifier_number, incoming = {}) ⇒ Object
Returns information about a specific order using an identifier number
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1108 def get_identifier_by_identifier_number(organization, identifier_number, incoming={}) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('identifier_number', identifier_number, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, String) }) }.delete_if { |k, v| v.nil? } r = @client.request("/#{CGI.escape(organization)}/orders/identifier/#{CGI.escape(identifier_number)}").with_query(query).get ::Io::Flow::V0::Models::Order.new(r) end |
#get_versions(organization, incoming = {}) ⇒ Object
Provides visibility into recent changes of each order, including deletion
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1120 def get_versions(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) }), :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? ? "journal_timestamp" : x), String) }.delete_if { |k, v| v.nil? } r = @client.request("/#{CGI.escape(organization)}/orders/versions").with_query(query).get r.map { |x| ::Io::Flow::V0::Models::OrderVersion.new(x) } end |
#post(organization, order_form, incoming = {}) ⇒ Object
Create an order, using the localized information from the experience selected by the query parameters. Note the order must be submitted before its expiration
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1023 def post(organization, order_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)), :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, String) }) }.delete_if { |k, v| v.nil? } (x = order_form; x.is_a?(::Io::Flow::V0::Models::OrderForm) ? x : ::Io::Flow::V0::Models::OrderForm.new(x)) r = @client.request("/#{CGI.escape(organization)}/orders").with_query(query).with_json(order_form.to_json).post ::Io::Flow::V0::Models::Order.new(r) end |
#put_by_number(organization, number, order_put_form, incoming = {}) ⇒ Object
Upserts an order. using the localized information from the experience selected by the query parameters. Note the order must be submitted before its expiration
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1054 def put_by_number(organization, number, order_put_form, incoming={}) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('number', number, 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)), :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, String) }) }.delete_if { |k, v| v.nil? } (x = order_put_form; x.is_a?(::Io::Flow::V0::Models::OrderPutForm) ? x : ::Io::Flow::V0::Models::OrderPutForm.new(x)) r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}").with_query(query).with_json(order_put_form.to_json).put ::Io::Flow::V0::Models::Order.new(r) end |
#put_promotions_and_free_shipping_by_number_and_key(organization, number, key, free_shipping_order_promotion_form, incoming = {}) ⇒ Object
Creates a free shipping promotion to the order, automatically applying it to the order if the order meets the defined promotion trigger.
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1082 def put_promotions_and_free_shipping_by_number_and_key(organization, number, key, free_shipping_order_promotion_form, incoming={}) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('number', number, String) HttpClient::Preconditions.assert_class('key', key, String) opts = HttpClient::Helper.symbolize_keys(incoming) query = { :expand => (x = opts.delete(:expand); x.nil? ? nil : HttpClient::Preconditions.assert_class('expand', x, Array).map { |v| HttpClient::Preconditions.assert_class('expand', v, String) }) }.delete_if { |k, v| v.nil? } (x = free_shipping_order_promotion_form; x.is_a?(::Io::Flow::V0::Models::FreeShippingOrderPromotionForm) ? x : ::Io::Flow::V0::Models::FreeShippingOrderPromotionForm.new(x)) r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}/promotions/#{CGI.escape(key)}/free_shipping").with_query(query).with_json(free_shipping_order_promotion_form.to_json).put ::Io::Flow::V0::Models::FreeShippingOrderPromotion.new(r) end |
#put_submissions_by_number(organization, number, hash) ⇒ Object
Submits an order. You will get a validation error if the order has already expired (and a new quote could not be automatically recreated for a lower or same price). This method is idempotent - submitting an order a second time has no effect.
1099 1100 1101 1102 1103 1104 1105 |
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 1099 def put_submissions_by_number(organization, number, hash) HttpClient::Preconditions.assert_class('organization', organization, String) HttpClient::Preconditions.assert_class('number', number, String) HttpClient::Preconditions.assert_class('hash', hash, Hash) r = @client.request("/#{CGI.escape(organization)}/orders/#{CGI.escape(number)}/submissions").with_json(hash.to_json).put ::Io::Flow::V0::Models::Order.new(r) end |