Sha256: e6e201e9aebebd22e8b037f9819c9f953ae883c6ea57b22e994bb74d2e5917aa

Contents?: true

Size: 842 Bytes

Versions: 6

Compression:

Stored size: 842 Bytes

Contents

# frozen_string_literal: true

class EasyPost::Services::Order < EasyPost::Services::Service
  MODEL_CLASS = EasyPost::Models::Order

  # Create an Order object
  def create(params = {})
    wrapped_params = { order: params }
    @client.make_request(:post, 'orders', MODEL_CLASS, wrapped_params)
  end

  # Retrieve an Order object
  def retrieve(id)
    @client.make_request(:get, "orders/#{id}", MODEL_CLASS)
  end

  # Retrieve new rates for an Order object
  def get_rates(id, params = {})
    @client.make_request(:get, "orders/#{id}/rates", MODEL_CLASS, params)
  end

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
easypost-5.3.0 lib/easypost/services/order.rb
easypost-5.2.0 lib/easypost/services/order.rb
easypost-5.1.1 lib/easypost/services/order.rb
easypost-5.1.0 lib/easypost/services/order.rb
easypost-5.0.1 lib/easypost/services/order.rb
easypost-5.0.0 lib/easypost/services/order.rb