Class: TerminalShop::Resources::Cart

Inherits:
Object
  • Object
show all
Defined in:
lib/terminal_shop/resources/cart.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Cart

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Cart.



131
132
133
# File 'lib/terminal_shop/resources/cart.rb', line 131

def initialize(client:)
  @client = client
end

Instance Method Details

#clear(request_options: {}) ⇒ TerminalShop::Models::CartClearResponse

Clear the current user’s cart.



15
16
17
18
19
20
21
22
# File 'lib/terminal_shop/resources/cart.rb', line 15

def clear(params = {})
  @client.request(
    method: :delete,
    path: "cart",
    model: TerminalShop::Models::CartClearResponse,
    options: params[:request_options]
  )
end

#convert(request_options: {}) ⇒ TerminalShop::Models::CartConvertResponse

Convert the current user’s cart to an order.



33
34
35
36
37
38
39
40
# File 'lib/terminal_shop/resources/cart.rb', line 33

def convert(params = {})
  @client.request(
    method: :post,
    path: "cart/convert",
    model: TerminalShop::Models::CartConvertResponse,
    options: params[:request_options]
  )
end

#get(request_options: {}) ⇒ TerminalShop::Models::CartGetResponse

Get the current user’s cart.



51
52
53
54
55
56
57
58
# File 'lib/terminal_shop/resources/cart.rb', line 51

def get(params = {})
  @client.request(
    method: :get,
    path: "cart",
    model: TerminalShop::Models::CartGetResponse,
    options: params[:request_options]
  )
end

#set_address(address_id: , request_options: {}) ⇒ TerminalShop::Models::CartSetAddressResponse

Set the shipping address for the current user’s cart.



71
72
73
74
75
76
77
78
79
80
# File 'lib/terminal_shop/resources/cart.rb', line 71

def set_address(params)
  parsed, options = TerminalShop::CartSetAddressParams.dump_request(params)
  @client.request(
    method: :put,
    path: "cart/address",
    body: parsed,
    model: TerminalShop::Models::CartSetAddressResponse,
    options: options
  )
end

#set_card(card_id: , request_options: {}) ⇒ TerminalShop::Models::CartSetCardResponse

Set the credit card for the current user’s cart.



93
94
95
96
97
98
99
100
101
102
# File 'lib/terminal_shop/resources/cart.rb', line 93

def set_card(params)
  parsed, options = TerminalShop::CartSetCardParams.dump_request(params)
  @client.request(
    method: :put,
    path: "cart/card",
    body: parsed,
    model: TerminalShop::Models::CartSetCardResponse,
    options: options
  )
end

#set_item(product_variant_id: , quantity: , request_options: {}) ⇒ TerminalShop::Models::CartSetItemResponse

Add an item to the current user’s cart.



117
118
119
120
121
122
123
124
125
126
# File 'lib/terminal_shop/resources/cart.rb', line 117

def set_item(params)
  parsed, options = TerminalShop::CartSetItemParams.dump_request(params)
  @client.request(
    method: :put,
    path: "cart/item",
    body: parsed,
    model: TerminalShop::Models::CartSetItemResponse,
    options: options
  )
end