cargowise 0.6 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ v0.7 - 31st August 2010
2
+ * new attribute Shipment#consols
3
+ * new method Shipment#transport_mode
4
+ * new method Shipment#orders
5
+ * new attribute Order#invoice_number
6
+ * new Order search method - Order.via(blah).by_shipment_number
7
+
1
8
  v0.6 - 31st August 2010
2
9
  * new methods Order#to_xml and Shipment#to_xml
3
10
  * new attribute Shipment#invoices
@@ -32,10 +32,10 @@ need to register the URI and authentication details for the company you want to
32
32
  :user => "user@example.com",
33
33
  :password => "secret")
34
34
 
35
- Cargowise::Order.register(:ijs, :uri => "http://visibility.ijsglobal.com/Tracker/WebService/ShipmentService.asmx",
36
- :code => "company_code",
37
- :user => "user@example.com",
38
- :password => "secret")
35
+ Cargowise::Shipment.register(:ijs, :uri => "http://visibility.ijsglobal.com/Tracker/WebService/ShipmentService.asmx",
36
+ :code => "company_code",
37
+ :user => "user@example.com",
38
+ :password => "secret")
39
39
 
40
40
  In a rails app the registration should be done in a file like
41
41
  config/initializers/cargowise.rb.
@@ -15,6 +15,7 @@ require 'cargowise/shipments_client'
15
15
  require 'cargowise/abstract_result'
16
16
  require 'cargowise/order'
17
17
  require 'cargowise/shipment'
18
+ require 'cargowise/consol'
18
19
  require 'cargowise/document'
19
20
  require 'cargowise/invoice'
20
21
  require 'cargowise/endpoint'
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+
3
+ module Cargowise
4
+
5
+ # Extra shipping detail associated with a Shipment. Not built
6
+ # directly, but available via the consols() attribute
7
+ # of the Shipment model.
8
+ #
9
+ class Consol < AbstractResult
10
+
11
+ attr_reader :master_bill, :console_mode, :transport_mode
12
+ attr_reader :vessel_name, :voyage_flight
13
+ attr_reader :load_port, :discharge_port
14
+
15
+ def initialize(node)
16
+ @node = node
17
+
18
+ @master = text_value("./MasterBill")
19
+ @console_mode = text_value("./ConsolMode")
20
+ @transport_mode = text_value("./TransportMode")
21
+ @vessel_name = text_value("./VesselName")
22
+ @voyage_flight = text_value("./VoyageFlight")
23
+ @load_port = text_value("./LoadPort")
24
+ @discharge_port = text_value("./DischargePort")
25
+ end
26
+ end
27
+ end
@@ -23,6 +23,7 @@ module Cargowise
23
23
 
24
24
  attr_reader :order_number, :order_status, :description, :datetime
25
25
  attr_reader :order_total, :transport_mode, :container_mode
26
+ attr_reader :invoice_number
26
27
 
27
28
  attr_reader :buyer_name
28
29
 
@@ -34,6 +35,7 @@ module Cargowise
34
35
  @node = node
35
36
 
36
37
  @order_number = text_value("./OrderIdentifier/OrderNumber")
38
+ @invoice_number = text_value("./OrderDetail/InvoiceNumber")
37
39
  @order_status = text_value("./OrderDetail/OrderStatus")
38
40
  @description = text_value("./OrderDetail/Description")
39
41
  @datetime = time_value("./OrderDetail/OrderDateTime")
@@ -19,6 +19,21 @@ module Cargowise
19
19
  OrdersClient.get_order_list(ep.code, ep.user, ep.password, filter_hash)
20
20
  end
21
21
 
22
+ # find all orders with a ShipmentNumber that matches ref
23
+ #
24
+ def by_shipment_number(ref)
25
+ filter_hash = {
26
+ "tns:Filter" => {
27
+ "tns:Number" => {
28
+ "tns:NumberSearchField" => "ShipmentNumber",
29
+ "tns:NumberValue" => ref
30
+ }
31
+ }
32
+ }
33
+ OrdersClient.endpoint(endpoint_hash) # probably not threadsafe. oops.
34
+ OrdersClient.get_order_list(ep.code, ep.user, ep.password, filter_hash)
35
+ end
36
+
22
37
  # find all orders still marked as incomplete.
23
38
  #
24
39
  def incomplete
@@ -28,7 +28,7 @@ module Cargowise
28
28
 
29
29
  attr_reader :consignee_name
30
30
 
31
- attr_reader :documents, :invoices
31
+ attr_reader :consols, :documents, :invoices
32
32
 
33
33
  def initialize(node)
34
34
  @node = node
@@ -47,6 +47,10 @@ module Cargowise
47
47
 
48
48
  @consignee_name = text_value("./Consignee/OrganisationDetails/Name")
49
49
 
50
+ @consols = node_array("./Consols/Consol").map { |node|
51
+ Consol.new(node)
52
+ }
53
+
50
54
  @documents = node_array("./DocumentLinks/DocumentLink").map { |node|
51
55
  Document.new(node)
52
56
  }.sort_by { |doc|
@@ -60,9 +64,26 @@ module Cargowise
60
64
  }
61
65
  end
62
66
 
67
+ # returns the raw XML string this shipment is based on
68
+ #
63
69
  def to_xml
64
70
  @node.to_xml
65
71
  end
66
72
 
73
+ # returns a space separated string with all transport modes being used
74
+ # to move this shipment
75
+ #
76
+ def transport_mode
77
+ @consols.map { |con| con.transport_mode }.uniq.sort.join(" ")
78
+ end
79
+
80
+ # lookup full Cargowise::Order objects for each order on this shipment.
81
+ #
82
+ # 'via' is a symbol indicating which API endpoint to lookup.
83
+ #
84
+ def orders(via)
85
+ @orders ||= Cargowise::Order.via(via).by_shipment_number(self.number)
86
+ end
87
+
67
88
  end
68
89
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cargowise
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 6
9
- version: "0.6"
8
+ - 7
9
+ version: "0.7"
10
10
  platform: ruby
11
11
  authors:
12
12
  - James Healy
@@ -60,6 +60,7 @@ extra_rdoc_files: []
60
60
  files:
61
61
  - lib/cargowise/shipment.rb
62
62
  - lib/cargowise/shipments_client.rb
63
+ - lib/cargowise/consol.rb
63
64
  - lib/cargowise/invoice.rb
64
65
  - lib/cargowise/abstract_client.rb
65
66
  - lib/cargowise/abstract_search.rb