class Iupick::Shipment

This is the class object for the shipments.

Public Class Methods

add_information( shipment_token, waypoint_id, shipper_address, shipper_contact, recipient_contact, third_party_reference, recipient_address = Iupick.empty_address() ) click to toggle source

This method allows you to fill the information required for the package, and receive a confirmation_token in exchange.

# File lib/iupick/shipment.rb, line 27
def self.add_information(
  shipment_token,
  waypoint_id,
  shipper_address,
  shipper_contact,
  recipient_contact,
  third_party_reference,
  recipient_address = Iupick.empty_address()
)

  waypoint_id = waypoint_id ? waypoint_id : nil;
  recipient_address = recipient_address ?
    recipient_address :
    Iupick.emptyAddress();


  if waypoint_id or recipient_address != Iupick.empty_address()
    url = Iupick.get_base_url() +
      'fill-shipment-information/' + shipment_token + '/'
    headers = Iupick.generate_headers(auth = 'public')
    payload = {
      'waypoint': waypoint_id,
      'shipper_address': shipper_address,
      'shipper_contact': shipper_contact,
      'recipient_address': recipient_address,
      'recipient_contact': recipient_contact,
      'third_party_reference': third_party_reference
    }

    response = Unirest.post url,
      headers: headers,
      parameters: payload.to_json
    decoded_response = response.body['confirmation_token']
    return decoded_response
  end
  return false
end
create(length, width, height, weight) click to toggle source

Allows you to generate a token for the new shipment. Needs weight Needs Dimensions Receive a shipment id.

# File lib/iupick/shipment.rb, line 9
def self.create(length, width, height, weight)
  url = Iupick.get_base_url() + 'create-shipment-token/'
  headers = Iupick.generate_headers(auth = 'secret')
  payload = {
    'length': length.to_i,
    'width': width.to_i,
    'height': height.to_i,
    'weight': weight.to_i
  }

  response = Unirest.post url,
    headers: headers,
    parameters: payload.to_json
  decoded_response = response.body['shipment_token']
end
generate_waybill(confirmation_token) click to toggle source

Generates a waybill, once the information has been properly filled for the shipment.

# File lib/iupick/shipment.rb, line 67
def self.generate_waybill(confirmation_token)
  url = Iupick.get_base_url() + 'generate-waybill/' + confirmation_token + '/'
  headers = Iupick.generate_headers(auth = 'secret')

  response = Unirest.post url,
    headers: headers
  decoded_response = response.body.to_json
  return decoded_response
end
track(carrier, tracking_number) click to toggle source

Allows you to track the status of a shipment, with the tracking number and carrier.

# File lib/iupick/shipment.rb, line 79
def self.track(carrier, tracking_number)
  url = Iupick.get_base_url() + 'track-shipment/'
  payload = {
    'carrier': carrier,
    'tracking_number': tracking_number
  }
  headers = Iupick.generate_headers(auth = 'public')
  response = Unirest.get url,
    headers: headers,
    parameters: payload
  decoded_response = response.body['Message']
end