Class: Cargowise::Shipment

Inherits:
AbstractResult show all
Defined in:
lib/cargowise/shipment.rb

Overview

A shipment that is currently on its way to you. Could take on a variety of forms - carton, palet, truck? Could be travelling via air, sea, road, rail, donkey?

Typcially you will lookup the status of a shipment you’re aware of using the shipment number:

Shipment.find_by_shipment_number(...)

If you want all recent shipments (delivered and undelivered) to ensure you know what’s coming:

Shipment.find_with_recent_activity(...)

All shipment objects are read-only, see the object attributes to see what information is available.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractResult

endpoint, #inspect, register, via

Constructor Details

#initialize(node) ⇒ Shipment

Returns a new instance of Shipment.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/cargowise/shipment.rb', line 35

def initialize(node)
  @node = node

  @number    = text_value("./Number")
  @housebill = text_value("./HouseBill")
  @goods_description = text_value("./GoodsDescription")
  @service_level = text_value("./ServiceLevel")
  @client_reference = text_value("./ClientReference")
  @origin        = text_value("./Origin")
  @destination   = text_value("./Destination")
  @etd           = time_value("./ETD")
  @eta           = time_value("./ETA")
  @delivered_date = time_value("./DeliveredDate")
  @kg            = kg_value("./Weight")
  @cubic_meters  = cubic_value("./Size")

  @shipper_name = text_value("./Shipper/OrganisationDetails/Name")

  @consignee_name = text_value("./Consignee/OrganisationDetails/Name")

  @consols = node_array("./Consols/Consol").map { |node|
    Consol.new(node)
  }

  @packings = node_array("./Packings/Packing").map { |node|
    Packing.new(node)
  }

  @documents = node_array("./DocumentLinks/DocumentLink").map { |node|
    Document.new(node)
  }.sort_by { |doc|
    doc.date
  }

  @invoices = node_array("./RelatedInvoiceLinks/InvoiceLink").map { |node|
    Invoice.new(node)
  }.sort_by { |inv|
    inv.due_date
  }
end

Instance Attribute Details

#client_referenceObject (readonly)

Returns the value of attribute client_reference.



25
26
27
# File 'lib/cargowise/shipment.rb', line 25

def client_reference
  @client_reference
end

#consignee_nameObject (readonly)

Returns the value of attribute consignee_name.



31
32
33
# File 'lib/cargowise/shipment.rb', line 31

def consignee_name
  @consignee_name
end

#consolsObject (readonly)

Returns the value of attribute consols.



33
34
35
# File 'lib/cargowise/shipment.rb', line 33

def consols
  @consols
end

#cubic_metersObject (readonly)

Returns the value of attribute cubic_meters.



27
28
29
# File 'lib/cargowise/shipment.rb', line 27

def cubic_meters
  @cubic_meters
end

#delivered_dateObject (readonly)

Returns the value of attribute delivered_date.



26
27
28
# File 'lib/cargowise/shipment.rb', line 26

def delivered_date
  @delivered_date
end

#destinationObject (readonly)

Returns the value of attribute destination.



26
27
28
# File 'lib/cargowise/shipment.rb', line 26

def destination
  @destination
end

#documentsObject (readonly)

Returns the value of attribute documents.



33
34
35
# File 'lib/cargowise/shipment.rb', line 33

def documents
  @documents
end

#etaObject (readonly)

Returns the value of attribute eta.



26
27
28
# File 'lib/cargowise/shipment.rb', line 26

def eta
  @eta
end

#etdObject (readonly)

Returns the value of attribute etd.



26
27
28
# File 'lib/cargowise/shipment.rb', line 26

def etd
  @etd
end

#goods_descriptionObject (readonly)

Returns the value of attribute goods_description.



24
25
26
# File 'lib/cargowise/shipment.rb', line 24

def goods_description
  @goods_description
end

#housebillObject (readonly)

Returns the value of attribute housebill.



24
25
26
# File 'lib/cargowise/shipment.rb', line 24

def housebill
  @housebill
end

#invoicesObject (readonly)

Returns the value of attribute invoices.



33
34
35
# File 'lib/cargowise/shipment.rb', line 33

def invoices
  @invoices
end

#kgObject (readonly)

Returns the value of attribute kg.



27
28
29
# File 'lib/cargowise/shipment.rb', line 27

def kg
  @kg
end

#numberObject (readonly)

Returns the value of attribute number.



24
25
26
# File 'lib/cargowise/shipment.rb', line 24

def number
  @number
end

#originObject (readonly)

Returns the value of attribute origin.



26
27
28
# File 'lib/cargowise/shipment.rb', line 26

def origin
  @origin
end

#packingsObject (readonly)

Returns the value of attribute packings.



33
34
35
# File 'lib/cargowise/shipment.rb', line 33

def packings
  @packings
end

#service_levelObject (readonly)

Returns the value of attribute service_level.



24
25
26
# File 'lib/cargowise/shipment.rb', line 24

def service_level
  @service_level
end

#shipper_nameObject (readonly)

Returns the value of attribute shipper_name.



29
30
31
# File 'lib/cargowise/shipment.rb', line 29

def shipper_name
  @shipper_name
end

Instance Method Details

#order_ref(via) ⇒ Object

if this shipment has an order ref associated with it, find it.

This data isn’t available via the API, so we need to screen scrape the website to get it.



118
119
120
121
122
123
124
# File 'lib/cargowise/shipment.rb', line 118

def order_ref(via)
  if (via)
    @order_ref ||= html_page(via).search(".//span[@id='Ztextlabel1']/text()").to_s.strip || ""
  else
    nil
  end
end

#orders(via) ⇒ Object

lookup full Cargowise::Order objects for each order on this shipment.

‘via’ is a symbol indicating which API endpoint to lookup.



93
94
95
# File 'lib/cargowise/shipment.rb', line 93

def orders(via)
  @orders ||= Cargowise::Order.via(via).by_shipment_number(self.number)
end

lookup related Cargowise::Shipment objects. These are usually “child” shipments grouped under a parent. Think a consolidated pallet (the parent) with cartons from multiple suppliers (the children).

‘via’ is a symbol indicating which API endpoint to lookup.



103
104
105
106
107
108
109
110
111
# File 'lib/cargowise/shipment.rb', line 103

def related_shipments(via)
  @related ||= @consols.map { |consol|
    consol.master_bill
  }.compact.map { |master_bill|
    Cargowise::Shipment.via(via).by_masterbill_number(master_bill)
  }.flatten.select { |shipment|
    shipment.number != self.number
  }.compact
end

#to_xmlObject

returns the raw XML string this shipment is based on



78
79
80
# File 'lib/cargowise/shipment.rb', line 78

def to_xml
  @node.to_xml
end

#transport_modeObject

returns a space separated string with all transport modes being used to move this shipment



85
86
87
# File 'lib/cargowise/shipment.rb', line 85

def transport_mode
  @consols.map { |con| con.transport_mode }.uniq.sort.join(" ")
end