Class: EasyPost::Services::Pickup

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

Constant Summary collapse

MODEL_CLASS =
EasyPost::Models::Pickup

Instance Method Summary collapse

Methods inherited from Service

#initialize

Constructor Details

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

Instance Method Details

#all(params = {}) ⇒ Object

Retrieve all Pickup objects



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

def all(params = {})
  filters = { key: 'pickups' }

  get_all_helper('pickups', MODEL_CLASS, params, filters)
end

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

Buy a Pickup



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

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

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

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

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

Cancel a Pickup



40
41
42
43
44
# File 'lib/easypost/services/pickup.rb', line 40

def cancel(id, params = {})
  response = @client.make_request(:post, "pickups/#{id}/cancel", params)

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

#create(params = {}) ⇒ Object

Create a Pickup object



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

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

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

#get_next_page(collection, page_size = nil) ⇒ Object

Get next page of Pickups



47
48
49
50
51
52
53
54
# File 'lib/easypost/services/pickup.rb', line 47

def get_next_page(collection, page_size = nil)
  raise EasyPost::Errors::EndOfPaginationError.new unless more_pages?(collection)

  params = { before_id: collection.pickups.last.id }
  params[:page_size] = page_size unless page_size.nil?

  all(params)
end

#retrieve(id) ⇒ Object

Retrieve a Pickup object



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

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

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