Class: EasyPost::Services::Batch

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

Constant Summary collapse

MODEL_CLASS =
EasyPost::Models::Batch

Instance Method Summary collapse

Methods inherited from Service

#initialize

Constructor Details

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

Instance Method Details

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

Add Shipments to a Batch.



49
50
51
52
53
# File 'lib/easypost/services/batch.rb', line 49

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

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

#all(params = {}) ⇒ Object



14
15
16
17
18
# File 'lib/easypost/services/batch.rb', line 14

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

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

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

Buy a Batch.



28
29
30
31
32
# File 'lib/easypost/services/batch.rb', line 28

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

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

#create(params = {}) ⇒ Object

Create a Batch.



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

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

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

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

Create a ScanForm for a Batch.



56
57
58
59
60
# File 'lib/easypost/services/batch.rb', line 56

def create_scan_form(id, params = {})
  response = @client.make_request(:post, "batches/#{id}/scan_form", params)

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

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

Convert the label format of a Batch.



35
36
37
38
39
# File 'lib/easypost/services/batch.rb', line 35

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

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

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

Remove Shipments from a Batch.



42
43
44
45
46
# File 'lib/easypost/services/batch.rb', line 42

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

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

#retrieve(id) ⇒ Object

Retrieve a Batch



21
22
23
24
25
# File 'lib/easypost/services/batch.rb', line 21

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

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