Class: Io::Flow::V0::Clients::ShopifyCarts

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ShopifyCarts

Returns a new instance of ShopifyCarts.



6534
6535
6536
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6534

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

Instance Method Details

#get_by_id(id) ⇒ Object

Retrieve representation of a Shopify cart given the unique cart id.



6553
6554
6555
6556
6557
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6553

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

#get_by_id_html(id) ⇒ Object

Retrieve representation of a Shopify cart given the unique cart id.



6546
6547
6548
6549
6550
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6546

def get_by_id_html(id)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/shopify/carts/#{CGI.escape(id)}").get
  r
end

#get_order_by_number(number) ⇒ Object

Retrieve representation of a Shopify cart for the given order number.



6539
6540
6541
6542
6543
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6539

def get_order_by_number(number)
  HttpClient::Preconditions.assert_class('number', number, String)
  r = @client.request("/shopify/carts/order/#{CGI.escape(number)}").get
  ::Io::Flow::V0::Models::ShopifyCart.new(r)
end

#post_add_by_id(id, shopify_cart_add_form) ⇒ Object

Add an item to a Shopify cart given the unique cart id.



6560
6561
6562
6563
6564
6565
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6560

def post_add_by_id(id, shopify_cart_add_form)
  HttpClient::Preconditions.assert_class('id', id, String)
  (x = shopify_cart_add_form; x.is_a?(::Io::Flow::V0::Models::ShopifyCartAddForm) ? x : ::Io::Flow::V0::Models::ShopifyCartAddForm.from_json(x))
  r = @client.request("/shopify/carts/#{CGI.escape(id)}/add").with_json(shopify_cart_add_form.to_json).post
  ::Io::Flow::V0::Models::ShopifyCart.new(r)
end

#post_change_by_id(id, shopify_cart_change_form) ⇒ Object

Change/Update an item in a Shopify cart given the unique cart id.



6576
6577
6578
6579
6580
6581
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6576

def post_change_by_id(id, shopify_cart_change_form)
  HttpClient::Preconditions.assert_class('id', id, String)
  (x = shopify_cart_change_form; x.is_a?(::Io::Flow::V0::Models::ShopifyCartChangeForm) ? x : ::Io::Flow::V0::Models::ShopifyCartChangeForm.new(x))
  r = @client.request("/shopify/carts/#{CGI.escape(id)}/change").with_json(shopify_cart_change_form.to_json).post
  ::Io::Flow::V0::Models::ShopifyCart.new(r)
end

#post_clear_by_id(id) ⇒ Object

Remove all cart items given the unique cart id .



6584
6585
6586
6587
6588
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6584

def post_clear_by_id(id)
  HttpClient::Preconditions.assert_class('id', id, String)
  r = @client.request("/shopify/carts/#{CGI.escape(id)}/clear").post
  ::Io::Flow::V0::Models::ShopifyCart.new(r)
end

#post_orders_by_id(id, incoming = {}) ⇒ Object

Create an order from a Flow cart.



6599
6600
6601
6602
6603
6604
6605
6606
6607
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6599

def post_orders_by_id(id, incoming={})
  HttpClient::Preconditions.assert_class('id', id, 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("/shopify/carts/#{CGI.escape(id)}/orders").with_query(query).post
  ::Io::Flow::V0::Models::Order.new(r)
end

#put_attributes_by_id(id, shopify_order_attributes_form) ⇒ Object

Update the attribute information for the cart.



6568
6569
6570
6571
6572
6573
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6568

def put_attributes_by_id(id, shopify_order_attributes_form)
  HttpClient::Preconditions.assert_class('id', id, String)
  (x = shopify_order_attributes_form; x.is_a?(::Io::Flow::V0::Models::ShopifyOrderAttributesForm) ? x : ::Io::Flow::V0::Models::ShopifyOrderAttributesForm.new(x))
  r = @client.request("/shopify/carts/#{CGI.escape(id)}/attributes").with_json(shopify_order_attributes_form.to_json).put
  ::Io::Flow::V0::Models::ShopifyCart.new(r)
end

#put_geo_by_id(id, geo_form) ⇒ Object

Update the geo information for the cart.



6591
6592
6593
6594
6595
6596
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6591

def put_geo_by_id(id, geo_form)
  HttpClient::Preconditions.assert_class('id', id, String)
  (x = geo_form; x.is_a?(::Io::Flow::V0::Models::GeoForm) ? x : ::Io::Flow::V0::Models::GeoForm.new(x))
  r = @client.request("/shopify/carts/#{CGI.escape(id)}/geo").with_json(geo_form.to_json).put
  ::Io::Flow::V0::Models::ShopifyCart.new(r)
end