Class: InstacartApi::Cart

Inherits:
Object
  • Object
show all
Defined in:
lib/instacart_api/models/cart.rb

Overview

A shopping cart, as returned by the cart mutation/queries. Instacart keeps a separate cart per retailer; item_count is the total line quantity.

Defined Under Namespace

Classes: LineItem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Cart

Returns a new instance of Cart.



23
24
25
26
27
28
29
30
31
# File 'lib/instacart_api/models/cart.rb', line 23

def initialize(data)
  @id = data["id"]
  @cart_type = data["cartType"]
  @retailer_id = data["retailerId"]
  @item_count = data["itemCount"]

  line_items = data.dig("cartItemCollection", "cartItems") || []
  @items = line_items.map { |line_item| LineItem.new(line_item) }
end

Instance Attribute Details

#cart_typeObject (readonly)

Returns the value of attribute cart_type.



21
22
23
# File 'lib/instacart_api/models/cart.rb', line 21

def cart_type
  @cart_type
end

#idObject (readonly)

Returns the value of attribute id.



21
22
23
# File 'lib/instacart_api/models/cart.rb', line 21

def id
  @id
end

#item_countObject (readonly)

Returns the value of attribute item_count.



21
22
23
# File 'lib/instacart_api/models/cart.rb', line 21

def item_count
  @item_count
end

#itemsObject (readonly)

Returns the value of attribute items.



21
22
23
# File 'lib/instacart_api/models/cart.rb', line 21

def items
  @items
end

#retailer_idObject (readonly)

Returns the value of attribute retailer_id.



21
22
23
# File 'lib/instacart_api/models/cart.rb', line 21

def retailer_id
  @retailer_id
end