cargowise 0.9.1 → 0.10.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e45da9312970fc9b5e9bc2064954fb8f73de8c40
4
+ data.tar.gz: a33f052ff5bf6b6d2269053664f15cf212b7c3c6
5
+ SHA512:
6
+ metadata.gz: c0b72d0a208f4f8471bc291e586c8de0f760a1cc415275e9fa99759a84242300f7cfaa3d9d238af68cb126c483834a7a63735f4e1c66e8caa9e1d046a208627b
7
+ data.tar.gz: 697ec43dfe011f03aec193099a6b2327d074ec1e63c634d67984b72d5b0ad6b361ef0470127999ee7f896ff6ac91fa333ada71240faa7acae54ff6aa04473bb1
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ v0.10.0 - 20th July 2013
2
+ * switch from handsoap to savon for SOAP calls
3
+ * gives me more flexibility to control the SOAP requests and HTTP request
4
+ parameters. Useful for dealing with IIS 7.5 and poor SSL configs on servers
5
+ * no external API changes to this gem
6
+
1
7
  v0.9.1 - 13th February 2012
2
8
  * typo
3
9
 
@@ -7,6 +7,7 @@ require "handsoap"
7
7
  # gems
8
8
  require 'mechanize'
9
9
  require 'andand'
10
+ require 'savon'
10
11
 
11
12
  module Cargowise
12
13
  DEFAULT_NS = "http://www.edi.com.au/EnterpriseService/"
@@ -28,3 +29,7 @@ require 'cargowise/endpoint'
28
29
  require 'cargowise/abstract_search'
29
30
  require 'cargowise/order_search'
30
31
  require 'cargowise/shipment_search'
32
+
33
+ # Make savon/httpi always use Net::HTTP for HTTP requests. It supports
34
+ # forcing the connection to TLSv1 (needed for OHL)
35
+ HTTPI.adapter = :net_http
@@ -7,44 +7,40 @@ module Cargowise
7
7
  #
8
8
  # Not much to see here, just common methods
9
9
  #
10
- class AbstractClient < Handsoap::Service # :nodoc:
11
- def on_create_document(doc)
12
- doc.alias 'tns', Cargowise::DEFAULT_NS
13
- end
14
-
15
- def on_response_document(doc)
16
- doc.add_namespace 'ns', Cargowise::DEFAULT_NS
17
- end
18
-
19
- # test authentication, returns a string with your company name
20
- # if successful
21
- #
22
- def hello(company_code, username, pass)
23
- soap_action = 'http://www.edi.com.au/EnterpriseService/Hello'
24
- soap_headers = headers(company_code, username, pass)
25
- response = invoke('tns:Hello', :soap_action => soap_action, :soap_header => soap_headers, :http_options => cw_http_options)
26
- response.document.xpath("//tns:HelloResponse/tns:HelloResult/text()", {"tns" => Cargowise::DEFAULT_NS}).to_s
27
- end
10
+ class AbstractClient
28
11
 
29
12
  private
30
13
 
31
- def cw_http_options
32
- if File.file?(Cargowise::CA_CERT_FILE)
33
- {:trust_ca_file => Cargowise::CA_CERT_FILE}
34
- else
35
- {}
36
- end
37
- end
38
-
39
- def headers(company_code, username, pass)
40
- {
41
- "tns:WebTrackerSOAPHeader" => {
42
- "tns:CompanyCode" => company_code,
43
- "tns:UserName" => username,
44
- "tns:Password" => pass
14
+ def build_client(wsdl_path, endpoint_uri, company_code, username, password)
15
+ Savon.client(
16
+ wsdl: wsdl_path,
17
+ endpoint: endpoint_uri,
18
+
19
+ # Cargowise servers can be super slow to respond, this gives them time
20
+ # to have a smoko before responding to our queries.
21
+ read_timeout: 120,
22
+
23
+ # OHL uses cargowise and has a load balancer that freaks out if we use
24
+ # the OpenSSL 1.0.1 default of TLS1.1.
25
+ ssl_version: :TLSv1,
26
+
27
+ # savon 2.2.0 ignores the above ssl_version unless this is set to
28
+ # false. Annoying.
29
+ ssl_verify_mode: :none,
30
+
31
+ # turn off logging to keep me sane. Change this to true when developing
32
+ log: false,
33
+
34
+ # the cargowsie API requires auth details in the SOAP header of every
35
+ # request
36
+ soap_header: {
37
+ "tns:WebTrackerSOAPHeader" => {
38
+ "tns:CompanyCode" => company_code,
39
+ "tns:UserName" => username,
40
+ "tns:Password" => password
41
+ }
45
42
  }
46
- }
43
+ )
47
44
  end
48
-
49
45
  end
50
46
  end
@@ -29,7 +29,7 @@ module Cargowise
29
29
 
30
30
  def inspect
31
31
  str = "<#{self.class}: "
32
- str << inspectable_vars.map { |v| "#{v.tr('@','')}: #{instance_variable_get(v)}" }.join(" ")
32
+ str << inspectable_vars.map { |v| "#{v.to_s.tr('@','')}: #{instance_variable_get(v)}" }.join(" ")
33
33
  str << ">"
34
34
  str
35
35
  end
@@ -41,7 +41,7 @@ module Cargowise
41
41
  end
42
42
 
43
43
  def inspectable_vars
44
- instance_variables.select { |var| var != "@node"}
44
+ instance_variables.select { |var| var.to_s != "@node"}
45
45
  end
46
46
 
47
47
  def node_array(path)
@@ -62,6 +62,8 @@ module Cargowise
62
62
  def time_value(path)
63
63
  val = text_value(path)
64
64
  val.nil? ? nil : DateTime.parse(val)
65
+ rescue ArgumentError
66
+ return nil
65
67
  end
66
68
 
67
69
  def decimal_value(path)
@@ -15,8 +15,7 @@ module Cargowise
15
15
  }
16
16
  }
17
17
  }
18
- OrdersClient.endpoint(endpoint_hash) # probably not threadsafe. oops.
19
- OrdersClient.get_order_list(ep.code, ep.user, ep.password, filter_hash)
18
+ OrdersClient.new.get_order_list(ep.uri, ep.code, ep.user, ep.password, filter_hash)
20
19
  end
21
20
 
22
21
  # find all orders with a ShipmentNumber that matches ref
@@ -30,8 +29,7 @@ module Cargowise
30
29
  }
31
30
  }
32
31
  }
33
- OrdersClient.endpoint(endpoint_hash) # probably not threadsafe. oops.
34
- OrdersClient.get_order_list(ep.code, ep.user, ep.password, filter_hash)
32
+ OrdersClient.new.get_order_list(ep.uri, ep.code, ep.user, ep.password, filter_hash)
35
33
  end
36
34
 
37
35
  # find all orders still marked as incomplete.
@@ -40,8 +38,7 @@ module Cargowise
40
38
  filter_hash = {
41
39
  "tns:Filter" => { "tns:OrderStatus" => "INC" }
42
40
  }
43
- OrdersClient.endpoint(endpoint_hash) # probably not threadsafe. oops.
44
- OrdersClient.get_order_list(ep.code, ep.user, ep.password, filter_hash)
41
+ OrdersClient.new.get_order_list(ep.uri, ep.code, ep.user, ep.password, filter_hash)
45
42
  end
46
43
 
47
44
  end
@@ -5,7 +5,7 @@ module Cargowise
5
5
  # SOAP client for retreiving order data. Not much to
6
6
  # see here, used by the Order resource class.
7
7
  #
8
- class OrdersClient < AbstractClient # :nodoc:
8
+ class OrdersClient < AbstractClient
9
9
 
10
10
  # return an array of orders. Each order *should* correspond to a buyer PO.
11
11
  #
@@ -13,13 +13,31 @@ module Cargowise
13
13
  # XML fragment specifying the search criteria. See the WSDL documentation
14
14
  # for samples
15
15
  #
16
- def get_order_list(company_code, username, pass, filter_hash)
17
- soap_action = 'http://www.edi.com.au/EnterpriseService/GetOrderList'
18
- soap_headers = headers(company_code, username, pass)
19
- response = invoke('tns:GetOrderList', :soap_action => soap_action, :soap_header => soap_headers, :soap_body => filter_hash, :http_options => cw_http_options)
20
- response.document.xpath("//tns:GetOrderListResult/tns:WebOrder", {"tns" => Cargowise::DEFAULT_NS}).map do |node|
16
+ def get_order_list(endpoint_uri, company_code, username, pass, filter_hash)
17
+ client = build_client(order_wsdl_path, endpoint_uri, company_code, username, pass)
18
+ response = client.call(:get_order_list, message: filter_hash)
19
+ response.xpath("//tns:GetOrderListResult/tns:WebOrder", {"tns" => Cargowise::DEFAULT_NS}).map do |node|
21
20
  Cargowise::Order.new(node)
22
21
  end
23
22
  end
23
+
24
+ # test authentication, returns a string with your company name
25
+ # if successful
26
+ #
27
+ def hello(endpoint_uri, company_code, username, pass)
28
+ client = build_client(order_wsdl_path, endpoint_uri, company_code, username, pass)
29
+ response = client.call(:hello)
30
+ response.xpath("//tns:HelloResponse/tns:HelloResult/text()", {"tns" => Cargowise::DEFAULT_NS}).to_s
31
+ end
32
+
33
+ private
34
+
35
+ def order_wsdl_path
36
+ File.join(
37
+ File.dirname(__FILE__),
38
+ "order_wsdl.xml"
39
+ )
40
+ end
41
+
24
42
  end
25
43
  end
@@ -134,6 +134,7 @@ module Cargowise
134
134
  base_uri = tracker_login_uri(via)
135
135
  login_uri = base_uri + "/Login/Login.aspx"
136
136
  agent = Mechanize.new
137
+ agent.agent.http.ssl_version = :TLSv1
137
138
  if File.file?(Cargowise::CA_CERT_FILE)
138
139
  agent.agent.http.ca_file = CA_CERT_FILE
139
140
  end
@@ -26,8 +26,7 @@ module Cargowise
26
26
  filter_hash = {
27
27
  "tns:Filter" => { "tns:Status" => "Undelivered" }
28
28
  }
29
- ShipmentsClient.endpoint(endpoint_hash) # probably not threadsafe. oops.
30
- ShipmentsClient.get_shipments_list(ep.code, ep.user, ep.password, filter_hash)
29
+ ShipmentsClient.new.get_shipments_list(ep.uri, ep.code, ep.user, ep.password, filter_hash)
31
30
  end
32
31
 
33
32
  # find all shipments that had some activity in the past fourteen days. This could
@@ -43,8 +42,7 @@ module Cargowise
43
42
  }
44
43
  }
45
44
  }
46
- ShipmentsClient.endpoint(endpoint_hash) # probably not threadsafe. oops.
47
- ShipmentsClient.get_shipments_list(ep.code, ep.user, ep.password, filter_hash)
45
+ ShipmentsClient.new.get_shipments_list(ep.uri, ep.code, ep.user, ep.password, filter_hash)
48
46
  end
49
47
 
50
48
  # find all shipments that had were shipped in the past 14 days or will ship in
@@ -60,8 +58,7 @@ module Cargowise
60
58
  }
61
59
  }
62
60
  }
63
- ShipmentsClient.endpoint(endpoint_hash) # probably not threadsafe. oops.
64
- ShipmentsClient.get_shipments_list(ep.code, ep.user, ep.password, filter_hash)
61
+ ShipmentsClient.new.get_shipments_list(ep.uri, ep.code, ep.user, ep.password, filter_hash)
65
62
  end
66
63
 
67
64
  private
@@ -75,8 +72,7 @@ module Cargowise
75
72
  }
76
73
  }
77
74
  }
78
- ShipmentsClient.endpoint(endpoint_hash) # probably not threadsafe. oops.
79
- ShipmentsClient.get_shipments_list(ep.code, ep.user, ep.password, filter_hash)
75
+ ShipmentsClient.new.get_shipments_list(ep.uri, ep.code, ep.user, ep.password, filter_hash)
80
76
  end
81
77
 
82
78
  end
@@ -5,7 +5,7 @@ module Cargowise
5
5
  # SOAP client for retreiving shipment data. Not much to
6
6
  # see here, used by the Shipment resource class.
7
7
  #
8
- class ShipmentsClient < AbstractClient # :nodoc:
8
+ class ShipmentsClient < AbstractClient
9
9
 
10
10
  # return an array of shipments. Each shipment should correspond to
11
11
  # a consolidated shipment from the freight company.
@@ -14,14 +14,31 @@ module Cargowise
14
14
  # XML fragment specifying the search criteria. See the WSDL documentation
15
15
  # for samples
16
16
  #
17
- def get_shipments_list(company_code, username, pass, filter_hash)
18
- soap_action = 'http://www.edi.com.au/EnterpriseService/GetShipmentsList'
19
- soap_headers = headers(company_code, username, pass)
20
- response = invoke('tns:GetShipmentsList', :soap_action => soap_action, :soap_header => soap_headers, :soap_body => filter_hash, :http_options => cw_http_options)
21
- response.document.xpath("//tns:GetShipmentsListResult/tns:WebShipment", {"tns" => Cargowise::DEFAULT_NS}).map do |node|
17
+ def get_shipments_list(endpoint_uri, company_code, username, pass, filter_hash)
18
+ client = build_client(shipment_wsdl_path, endpoint_uri, company_code, username, pass)
19
+ response = client.call(:get_shipments_list, message: filter_hash)
20
+ response.xpath("//tns:GetShipmentsListResult/tns:WebShipment", {"tns" => Cargowise::DEFAULT_NS}).map do |node|
22
21
  Cargowise::Shipment.new(node)
23
22
  end
24
23
  end
25
24
 
25
+ # test authentication, returns a string with your company name
26
+ # if successful
27
+ #
28
+ def hello(endpoint_uri, company_code, username, pass)
29
+ client = build_client(shipment_wsdl_path, endpoint_uri, company_code, username, pass)
30
+ response = client.call(:hello)
31
+ response.xpath("//tns:HelloResponse/tns:HelloResult/text()", {"tns" => Cargowise::DEFAULT_NS}).to_s
32
+ end
33
+
34
+ private
35
+
36
+ def shipment_wsdl_path
37
+ File.join(
38
+ File.dirname(__FILE__),
39
+ "shipment_wsdl.xml"
40
+ )
41
+ end
42
+
26
43
  end
27
44
  end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cargowise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
5
- prerelease:
4
+ version: 0.10.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - James Healy
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-02-13 00:00:00.000000000 Z
11
+ date: 2013-07-20 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
- name: curb
16
- requirement: &21137820 !ruby/object:Gem::Requirement
17
- none: false
14
+ name: andand
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *21137820
25
- - !ruby/object:Gem::Dependency
26
- name: andand
27
- requirement: &21137380 !ruby/object:Gem::Requirement
28
- none: false
22
+ version_requirements: !ruby/object:Gem::Requirement
29
23
  requirements:
30
- - - ! '>='
24
+ - - '>='
31
25
  - !ruby/object:Gem::Version
32
26
  version: '0'
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: *21137380
36
27
  - !ruby/object:Gem::Dependency
37
- name: handsoap
38
- requirement: &21136840 !ruby/object:Gem::Requirement
39
- none: false
28
+ name: savon
29
+ requirement: !ruby/object:Gem::Requirement
40
30
  requirements:
41
31
  - - ~>
42
32
  - !ruby/object:Gem::Version
43
- version: 1.1.7
33
+ version: 2.2.0
44
34
  type: :runtime
45
35
  prerelease: false
46
- version_requirements: *21136840
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 2.2.0
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: nokogiri
49
- requirement: &21136320 !ruby/object:Gem::Requirement
50
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
51
44
  requirements:
52
45
  - - ~>
53
46
  - !ruby/object:Gem::Version
54
47
  version: '1.4'
55
48
  type: :runtime
56
49
  prerelease: false
57
- version_requirements: *21136320
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.4'
58
55
  - !ruby/object:Gem::Dependency
59
56
  name: mechanize
60
- requirement: &21135840 !ruby/object:Gem::Requirement
61
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
62
58
  requirements:
63
59
  - - ~>
64
60
  - !ruby/object:Gem::Version
65
61
  version: '2.0'
66
62
  type: :runtime
67
63
  prerelease: false
68
- version_requirements: *21135840
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
69
  description: Retrieve tracking and status information on your shipments from entpriseEDI
70
70
  email:
71
71
  - james@yob.id.au
@@ -73,21 +73,21 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - lib/cargowise.rb
77
+ - lib/cargowise/order_search.rb
78
+ - lib/cargowise/consol.rb
76
79
  - lib/cargowise/invoice.rb
80
+ - lib/cargowise/order.rb
81
+ - lib/cargowise/document.rb
77
82
  - lib/cargowise/orders_client.rb
83
+ - lib/cargowise/abstract_client.rb
78
84
  - lib/cargowise/shipment.rb
79
- - lib/cargowise/order.rb
80
85
  - lib/cargowise/shipments_client.rb
81
- - lib/cargowise/shipment_search.rb
82
- - lib/cargowise/abstract_search.rb
83
- - lib/cargowise/abstract_client.rb
84
- - lib/cargowise/endpoint.rb
85
- - lib/cargowise/order_search.rb
86
86
  - lib/cargowise/packing.rb
87
- - lib/cargowise/document.rb
87
+ - lib/cargowise/abstract_search.rb
88
88
  - lib/cargowise/abstract_result.rb
89
- - lib/cargowise/consol.rb
90
- - lib/cargowise.rb
89
+ - lib/cargowise/endpoint.rb
90
+ - lib/cargowise/shipment_search.rb
91
91
  - README.markdown
92
92
  - CHANGELOG
93
93
  - TODO
@@ -96,6 +96,7 @@ files:
96
96
  homepage: http://github.com/yob/cargowise
97
97
  licenses:
98
98
  - mit
99
+ metadata: {}
99
100
  post_install_message:
100
101
  rdoc_options:
101
102
  - --title
@@ -104,21 +105,19 @@ rdoc_options:
104
105
  require_paths:
105
106
  - lib
106
107
  required_ruby_version: !ruby/object:Gem::Requirement
107
- none: false
108
108
  requirements:
109
- - - ! '>='
109
+ - - '>='
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0'
112
112
  required_rubygems_version: !ruby/object:Gem::Requirement
113
- none: false
114
113
  requirements:
115
- - - ! '>='
114
+ - - '>='
116
115
  - !ruby/object:Gem::Version
117
116
  version: '0'
118
117
  requirements: []
119
118
  rubyforge_project:
120
- rubygems_version: 1.8.11
119
+ rubygems_version: 2.0.3
121
120
  signing_key:
122
- specification_version: 3
121
+ specification_version: 4
123
122
  summary: Wrapper around entpriseEDI SOAP API by cargowise
124
123
  test_files: []