Class: FulfilApi::CustomerShipment

Inherits:
Resource
  • Object
show all
Defined in:
lib/fulfil_api/customer_shipment.rb

Overview

The CustomerShipment represents a single StockShipmentOut resource returned

by the API endpoints of Fulfil.

Constant Summary collapse

MODEL_NAME =
"stock.shipment.out"

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#[], #errors, #id, #initialize, relation, #to_h

Methods included from Resource::Serializable

#as_json, #to_json

Methods included from Resource::Persistable

#create, #create!, #save, #save!, #update, #update!

Methods included from Resource::Comparable

#==, #eql?, #hash

Methods included from Resource::AttributeAssignable

#assign_attribute, #assign_attributes

Constructor Details

This class inherits a constructor from FulfilApi::Resource

Class Method Details

.hold!(id_or_ids, note:) ⇒ Boolean

Sets the fulfillment status of the customer shipment on hold

Examples:

Hold a customer shipment

FulfilApi::CustomerShipment.hold(123, note: "Double booking")

Hold multipe customer shipments

FulfilApi::CustomerShipment.hold([123, 456], note: "Double booking")

Parameters:

  • id_or_ids (String, Integer, Array[String], Array[Integer])

    The ID(s) of the customer shipment(s) to hold.

  • note (String)

    A note to define the reason for holding.

Returns:

  • (Boolean)

    Returns true if hold successfully.

Raises:

  • (FulfilApi::Error)

    If an error occurs during holding the customer shipment.



22
23
24
25
# File 'lib/fulfil_api/customer_shipment.rb', line 22

def hold!(id_or_ids, note:)
  FulfilApi.client.put("/model/#{MODEL_NAME}/hold", body: [[*id_or_ids].flatten, note])
  true
end

.unhold!(id_or_ids, note:) ⇒ Boolean

Unholds the fulfillment status of the customer shipment

Examples:

Unhold a customer shipment

FulfilApi::CustomerShipment.unhold(123, note: "All clear")

Unhold a customer shipment

FulfilApi::CustomerShipment.unhold([123, 456], note: "All clear")

Parameters:

  • id_or_ids (String, Integer, Array[String], Array[Integer])

    The ID(s) of the customer shipment(s) to unhold.

  • note (String)

    A note to define the reason for unholding.

Returns:

  • (Boolean)

    Returns true if hold successfully.

Raises:

  • (FulfilApi::Error)

    If an error occurs during holding the customer shipment.



40
41
42
43
# File 'lib/fulfil_api/customer_shipment.rb', line 40

def unhold!(id_or_ids, note:)
  FulfilApi.client.put("/model/#{MODEL_NAME}/unhold", body: [[*id_or_ids].flatten, note])
  true
end

Instance Method Details

#hold(note) ⇒ Boolean

Sets the current customer shipment on hold, rescuing any errors that occur and handling them based on error type.

Examples:

Holds a customer_shipment

customer_shipment.hold("Holding the shipment for 30 minutes to allow edits to the order")

Parameters:

  • note (String)

    A note to define the reason for holding.

Returns:

  • (Boolean)

    Returns true if hold successfully, otherwise false.



53
54
55
56
57
58
# File 'lib/fulfil_api/customer_shipment.rb', line 53

def hold(note)
  self.class.hold!(id, note: note)
rescue FulfilApi::Error => e
  handle_exception(e)
  false
end

#unhold(note) ⇒ Boolean

Unholds the current customer shipment, rescuing any errors that occur and handling them based on error type.

Examples:

Unholds a customer_shipment

customer_shipment.unhold("Ship out these items to the customer")

Parameters:

  • note (String)

    A note to define the reason for unholding.

Returns:

  • (Boolean)

    Returns true if unhold successfully, otherwise false.



67
68
69
70
71
72
# File 'lib/fulfil_api/customer_shipment.rb', line 67

def unhold(note)
  self.class.unhold!(id, note: note)
rescue FulfilApi::Error => e
  handle_exception(e)
  false
end