Class: InstacartApi::Cart
- Inherits:
-
Object
- Object
- InstacartApi::Cart
- 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
-
#cart_type ⇒ Object
readonly
Returns the value of attribute cart_type.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#item_count ⇒ Object
readonly
Returns the value of attribute item_count.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#retailer_id ⇒ Object
readonly
Returns the value of attribute retailer_id.
Instance Method Summary collapse
-
#initialize(data) ⇒ Cart
constructor
A new instance of Cart.
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_type ⇒ Object (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 |
#id ⇒ Object (readonly)
Returns the value of attribute id.
21 22 23 |
# File 'lib/instacart_api/models/cart.rb', line 21 def id @id end |
#item_count ⇒ Object (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 |
#items ⇒ Object (readonly)
Returns the value of attribute items.
21 22 23 |
# File 'lib/instacart_api/models/cart.rb', line 21 def items @items end |
#retailer_id ⇒ Object (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 |