Class: Cookie::Resources::Orders

Inherits:
Object
  • Object
show all
Defined in:
lib/cookie/resources/orders.rb

Overview

Handles order-related operations with the Digital Cookie API

Examples:

client = Cookie::Client.new(api_key: "your_key")
orders = client.orders.get_hand_delivery("12345")
puts orders.total_order_count

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Orders

Returns a new instance of Orders.



16
17
18
# File 'lib/cookie/resources/orders.rb', line 16

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)



14
15
16
# File 'lib/cookie/resources/orders.rb', line 14

def client
  @client
end

Instance Method Details

#get_hand_delivery(troop_id) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/cookie/resources/orders.rb', line 20

def get_hand_delivery(troop_id)
  response = @client.connection.get("getAllOrders/hand-delivery/#{troop_id}")
  order_response = Models::OrderResponse.new(response.body)

  if order_response.error?
    raise ApiError, order_response.error_message
  end

  order_response
rescue Faraday::Error => e
  raise ApiError, "Request failed: #{e.message}"
end