Class: CDEKApiClient::API::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/cdek_api_client/api/order.rb

Overview

Handles order-related API requests.

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Order

Initializes the Order object.

Parameters:



10
11
12
# File 'lib/cdek_api_client/api/order.rb', line 10

def initialize(client)
  @client = client
end

Instance Method Details

#cancel(order_uuid) ⇒ Hash

Cancels an order by its UUID.

Parameters:

  • order_uuid (String)

    the UUID of the order to cancel.

Returns:

  • (Hash)

    the response from the API.



46
47
48
49
50
# File 'lib/cdek_api_client/api/order.rb', line 46

def cancel(order_uuid)
  validate_uuid(order_uuid)
  response = @client.request('post', "orders/#{order_uuid}/refusal")
  handle_response(response)
end

#create(order_data) ⇒ Hash

Creates a new order.

Parameters:

Returns:

  • (Hash)

    the response from the API.



18
19
20
21
# File 'lib/cdek_api_client/api/order.rb', line 18

def create(order_data)
  response = @client.request('post', 'orders', body: order_data)
  handle_response(response)
end

#delete(order_uuid) ⇒ Hash

Deletes an order by its UUID.

Parameters:

  • order_uuid (String)

    the UUID of the order to delete.

Returns:

  • (Hash)

    the response from the API.



36
37
38
39
40
# File 'lib/cdek_api_client/api/order.rb', line 36

def delete(order_uuid)
  validate_uuid(order_uuid)
  response = @client.request('delete', "orders/#{order_uuid}")
  handle_response(response)
end

#get_by_cdek_number(cdek_number) ⇒ Hash

Gets order information by CDEK number.

Parameters:

  • cdek_number (String)

    the CDEK order number.

Returns:

  • (Hash)

    the order information.



65
66
67
68
# File 'lib/cdek_api_client/api/order.rb', line 65

def get_by_cdek_number(cdek_number)
  response = @client.request('get', 'orders', query: { cdek_number: cdek_number })
  handle_response(response)
end

#get_by_im_number(im_number) ⇒ Hash

Gets order information by IM number.

Parameters:

  • im_number (String)

    the IM order number.

Returns:

  • (Hash)

    the order information.



74
75
76
77
# File 'lib/cdek_api_client/api/order.rb', line 74

def get_by_im_number(im_number)
  response = @client.request('get', 'orders', query: { im_number: im_number })
  handle_response(response)
end

#track(order_uuid) ⇒ Hash

Tracks an order by its UUID.

Parameters:

  • order_uuid (String)

    the UUID of the order.

Returns:

  • (Hash)

    the tracking information.



27
28
29
30
# File 'lib/cdek_api_client/api/order.rb', line 27

def track(order_uuid)
  response = @client.request('get', "orders/#{order_uuid}")
  handle_response(response)
end

#update(order_data) ⇒ Hash

Updates an existing order.

Parameters:

Returns:

  • (Hash)

    the response from the API.



56
57
58
59
# File 'lib/cdek_api_client/api/order.rb', line 56

def update(order_data)
  response = @client.request('patch', 'orders', body: order_data)
  handle_response(response)
end