Sha256: 6cec598ccdcd33d7c327b3b62fae96eb8a54e0a83863cd6eec79146f8f2e9827

Contents?: true

Size: 987 Bytes

Versions: 2

Compression:

Stored size: 987 Bytes

Contents

# frozen_string_literal: true

# The Pickup object allows you to schedule a pickup from your carrier from your customer's residence or place of business.
class EasyPost::Pickup < EasyPost::Resource
  # Buy a Pickup.
  def buy(params = {})
    if params.instance_of?(EasyPost::PickupRate)
      temp = params.clone
      params = {}
      params[:carrier] = temp.carrier
      params[:service] = temp.service
    end

    response = EasyPost.make_request(:post, "#{url}/buy", @api_key, params)
    refresh_from(response, @api_key)

    self
  end

  # Cancel a Pickup.
  def cancel(params = {})
    response = EasyPost.make_request(:post, "#{url}/cancel", @api_key, params)
    refresh_from(response, @api_key)

    self
  end

  # Get the lowest rate of a Pickup (can exclude by having `'!'` as the first element of your optional filter lists).
  def lowest_rate(carriers = [], services = [])
    EasyPost::Util.get_lowest_object_rate(self, carriers, services, 'pickup_rates')
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
easypost-4.12.0 lib/easypost/pickup.rb
easypost-4.11.0 lib/easypost/pickup.rb