cargowise 0.7.2 → 0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ v0.8 - 9th September 2010
2
+ * new Shipment method - Shipment#order_ref
3
+ * new Shipment attribute - Shipment#client_reference
4
+
5
+ v0.7.2 - 7th September 2010
6
+ * new Shipment search method - Shipment.via(blah).by_masterbill_number
7
+ * new Shipment method - Shipment#related_shipments
8
+
1
9
  v0.7.1 - 1st September 2010
2
10
  * new Shipment search method - Shipment.via(blah).recently_shipped
3
11
 
data/lib/cargowise.rb CHANGED
@@ -4,6 +4,10 @@
4
4
  require "bigdecimal"
5
5
  require "handsoap"
6
6
 
7
+ # gems
8
+ require 'mechanize'
9
+ require 'andand'
10
+
7
11
  module Cargowise
8
12
  DEFAULT_NS = "http://www.edi.com.au/EnterpriseService/"
9
13
  end
@@ -13,6 +13,11 @@ module Cargowise
13
13
  @endpoints[name] = Endpoint.new(opts)
14
14
  end
15
15
 
16
+ def self.endpoint(name)
17
+ @endpoints ||= {}
18
+ @endpoints[name]
19
+ end
20
+
16
21
  def self.via(name)
17
22
  @endpoints ||= {}
18
23
  raise ArgumentError, "#{name} is not recognised, have you registered it?" if @endpoints[name].nil?
@@ -22,6 +22,7 @@ module Cargowise
22
22
  class Shipment < AbstractResult
23
23
 
24
24
  attr_reader :number, :housebill, :goods_description, :service_level
25
+ attr_reader :client_reference
25
26
  attr_reader :origin, :destination, :etd, :eta, :delivered_date
26
27
 
27
28
  attr_reader :shipper_name
@@ -37,6 +38,7 @@ module Cargowise
37
38
  @housebill = text_value("./HouseBill")
38
39
  @goods_description = text_value("./GoodsDescription")
39
40
  @service_level = text_value("./ServiceLevel")
41
+ @client_reference = text_value("./ClientReference")
40
42
  @origin = text_value("./Origin")
41
43
  @destination = text_value("./Destination")
42
44
  @etd = time_value("./ETD")
@@ -101,5 +103,44 @@ module Cargowise
101
103
  }.compact
102
104
  end
103
105
 
106
+ # if this shipment has an order ref associated with it, find it.
107
+ #
108
+ # This data isn't available via the API, so we need to screen scrape the
109
+ # website to get it.
110
+ #
111
+ def order_ref(via)
112
+ if tracker_login_uri(via)
113
+ @order_ref ||= html_page(via).search(".//span[@id='Ztextlabel1']/text()").to_s.strip || ""
114
+ else
115
+ nil
116
+ end
117
+ end
118
+
119
+ private
120
+
121
+ # retrieve a Mechanize::Page object that containts info on this shipment
122
+ #
123
+ def html_page(via)
124
+ return nil unless tracker_login_uri(via)
125
+
126
+ @html_page ||= begin
127
+ base_uri = tracker_login_uri(via)
128
+ login_uri = base_uri + "/Login/Login.aspx"
129
+ agent = Mechanize.new
130
+ page = agent.get(login_uri)
131
+ form = page.forms.first
132
+ input_name = form.fields.detect { |field| field.name.to_s.downcase.include?("number")}.andand.name
133
+ form.__send__("#{input_name}=", self.number) if input_name
134
+ form.add_field!("ViewShipmentBtn","View Shipment")
135
+ agent.submit(form)
136
+ end
137
+ end
138
+
139
+ # Find a shipment with documents attached so we can discover the
140
+ # web interface uri
141
+ #
142
+ def tracker_login_uri(via)
143
+ Shipment.endpoint(via).uri.to_s[/(.+)\/WebService.+/,1]
144
+ end
104
145
  end
105
146
  end
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cargowise
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 7
9
- - 2
10
- version: 0.7.2
8
+ - 8
9
+ version: "0.8"
11
10
  platform: ruby
12
11
  authors:
13
12
  - James Healy
@@ -15,7 +14,7 @@ autorequire:
15
14
  bindir: bin
16
15
  cert_chain: []
17
16
 
18
- date: 2010-09-07 00:00:00 +10:00
17
+ date: 2010-09-09 00:00:00 +10:00
19
18
  default_executable:
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
@@ -50,6 +49,21 @@ dependencies:
50
49
  version: 1.4.0
51
50
  type: :runtime
52
51
  version_requirements: *id002
52
+ - !ruby/object:Gem::Dependency
53
+ name: mechanize
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 15
61
+ segments:
62
+ - 1
63
+ - 0
64
+ version: "1.0"
65
+ type: :runtime
66
+ version_requirements: *id003
53
67
  description: Retrieve tracking and status information on your shipments from entpriseEDI
54
68
  email: james@yob.id.au
55
69
  executables: []