Class: EasyPost::Services::Order

Inherits:
Service
  • Object
show all
Defined in:
lib/easypost/services/order.rb

Constant Summary collapse

MODEL_CLASS =
EasyPost::Models::Order

Instance Method Summary collapse

Methods inherited from Service

#initialize

Constructor Details

This class inherits a constructor from EasyPost::Services::Service

Instance Method Details

#buy(id, params = {}) ⇒ Object

Buy an Order object



29
30
31
32
33
34
35
36
37
# File 'lib/easypost/services/order.rb', line 29

def buy(id, params = {})
  if params.instance_of?(EasyPost::Models::Rate)
    params = { carrier: params[:carrier], service: params[:service] }
  end

  response = @client.make_request(:post, "orders/#{id}/buy", params)

  EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS)
end

#create(params = {}) ⇒ Object

Create an Order object



7
8
9
10
11
12
# File 'lib/easypost/services/order.rb', line 7

def create(params = {})
  wrapped_params = { order: params }
  response = @client.make_request(:post, 'orders', wrapped_params)

  EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS)
end

#get_rates(id, params = {}) ⇒ Object

Retrieve new rates for an Order object



22
23
24
25
26
# File 'lib/easypost/services/order.rb', line 22

def get_rates(id, params = {})
  response = @client.make_request(:get, "orders/#{id}/rates", params)

  EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS)
end

#retrieve(id) ⇒ Object

Retrieve an Order object



15
16
17
18
19
# File 'lib/easypost/services/order.rb', line 15

def retrieve(id)
  response = @client.make_request(:get, "orders/#{id}")

  EasyPost::InternalUtilities::Json.convert_json_to_object(response, MODEL_CLASS)
end