cargowise 0.10.2 → 1.0.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c54964f5b53064306aafb7282ced14bd5ff19944
4
- data.tar.gz: 07236921a7be196347a2a813b3ffd57fee952072
3
+ metadata.gz: 9817101a99e84ae1fdf68b2a1389e83a94298fb1
4
+ data.tar.gz: 0264a94a2cd8b1ed3d142d4829478343ed0ea37b
5
5
  SHA512:
6
- metadata.gz: 0c2216ba6c46414161f597227fb3afb2277feb3da5c34ccfce12743f8c1f4a52ee1778b7394c6f50775b35633a7d69180c93bd58a3e95bf5bb03b8dd01d6a191
7
- data.tar.gz: 9d192732f6b05ea510b7aaa1e60b30e57e78a3786201868f7ec14c27e9672c27ea12dededdf10051cb46324c677ce8655d8dd626c0bc5396262bb71ef65a6e46
6
+ metadata.gz: 6881b0677e349919f63fc6bcfaa96b451950b83c6a7930c6027d645078efa99f11d0193cb28e7817bfe22a4c022d0b14691eb14b97ae144ab16ca3690d559469
7
+ data.tar.gz: 79d5fe26d024a84cbcad27d6dccf0d06f403df8925c5edad34262879fdf2e244eb341f8ce50c47f8ab4dc6bfdbccaef6544316f66b639b84064e1157e5840ed6
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ v1.0.0.alpha - 21st July 2013
2
+ * new, simpler API
3
+
1
4
  v0.10.2 - 20th July 2013
2
5
  * increase the read timeout to allow for slow servers
3
6
 
@@ -27,21 +27,17 @@ either or both.
27
27
  Each company using the cargowise product hosts the server themselves, so you will
28
28
  need to register the URI and authentication details for the company you want to use.
29
29
 
30
- Cargowise::Order.register(:ijs, :uri => "http://visibility.ijsglobal.com/Tracker/WebService/OrderService.asmx",
31
- :code => "company_code",
32
- :user => "user@example.com",
33
- :password => "secret")
34
-
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")
30
+ client = Cargowise::Client.new(:order_uri => "http://visibility.ijsglobal.com/Tracker/WebService/OrderService.asmx",
31
+ :shipment_uri => "http://visibility.ijsglobal.com/Tracker/WebService/ShipmentService.asmx",
32
+ :company_code => "company_code",
33
+ :username => "user@example.com",
34
+ :password => "secret")
39
35
 
40
36
  In a rails app the registration should be done in a file like
41
37
  config/initializers/cargowise.rb.
42
38
 
43
- If you deal with multiple companies running cargowise you can register each using
44
- different identifiers.
39
+ If you deal with multiple companies running cargowise you should create a client
40
+ instance per company.
45
41
 
46
42
  See the Finding API Endpoints section below for tips on finding the correct URI
47
43
  to register.
@@ -55,11 +51,11 @@ the order.
55
51
 
56
52
  To find all orders with a certain order number:
57
53
 
58
- Cargowise::Order.via(:ijs).by_order_number("123456")
54
+ client.orders.by_order_number("123456")
59
55
 
60
56
  To find all incomplete orders:
61
57
 
62
- Cargowise::Order.via(:ijs).incomplete
58
+ client.orders.incomplete
63
59
 
64
60
  Cargowise::Shipment represents something being sent to you - like a carton,
65
61
  palet or truck load. It might be transported via air, sea, road or a combination.
@@ -67,15 +63,15 @@ palet or truck load. It might be transported via air, sea, road or a combination
67
63
  To find shipments by the shipment number (a reference number selected by your logistics
68
64
  company):
69
65
 
70
- Cargowise::Shipment.via(:ijs).by_shipment_number("123456")
66
+ client.shipments.by_shipment_number("123456")
71
67
 
72
68
  To find undelivered shipments:
73
69
 
74
- Cargowise::Shipment.via(:ijs).undelivered
70
+ client.shipments.undelivered
75
71
 
76
72
  To find shipments with activity in the past 14 days (or so):
77
73
 
78
- Cargowise::Shipment.via(:ijs).with_recent_activity
74
+ client.shipments.with_recent_activity
79
75
 
80
76
  All Order and Shipment objects are read only, there are no write capabale
81
77
  methods exposed via the API. If you see errors, contact your logistics company.
@@ -2,12 +2,10 @@
2
2
 
3
3
  # stdlib
4
4
  require "bigdecimal"
5
- require "handsoap"
6
5
 
7
6
  # gems
8
7
  require 'mechanize'
9
8
  require 'andand'
10
- require 'savon'
11
9
 
12
10
  module Cargowise
13
11
  DEFAULT_NS = "http://www.edi.com.au/EnterpriseService/"
@@ -15,20 +13,7 @@ module Cargowise
15
13
  end
16
14
 
17
15
  # this lib
18
- require 'cargowise/abstract_client'
19
- require 'cargowise/orders_client'
20
- require 'cargowise/shipments_client'
21
- require 'cargowise/abstract_result'
22
- require 'cargowise/order'
23
- require 'cargowise/shipment'
24
- require 'cargowise/packing'
25
- require 'cargowise/consol'
26
- require 'cargowise/document'
27
- require 'cargowise/invoice'
28
- require 'cargowise/endpoint'
29
- require 'cargowise/abstract_search'
30
- require 'cargowise/order_search'
31
- require 'cargowise/shipment_search'
16
+ require 'cargowise/client'
32
17
 
33
18
  # Make savon/httpi always use Net::HTTP for HTTP requests. It supports
34
19
  # forcing the connection to TLSv1 (needed for OHL)
@@ -8,25 +8,6 @@ module Cargowise
8
8
  #
9
9
  class AbstractResult # :nodoc:
10
10
 
11
- def self.register(name, opts = {})
12
- @endpoints ||= {}
13
- @endpoints[name] = Endpoint.new(opts)
14
- end
15
-
16
- def self.endpoint(name)
17
- @endpoints ||= {}
18
- @endpoints[name]
19
- end
20
-
21
- def self.via(name)
22
- @endpoints ||= {}
23
- raise ArgumentError, "#{name} is not recognised, have you registered it?" if @endpoints[name].nil?
24
-
25
- klass_name = (self.name[/Cargowise::(.+)/,1] + "Search")
26
- search_klass = Cargowise.const_get(klass_name)
27
- search_klass.new(@endpoints[name])
28
- end
29
-
30
11
  def inspect
31
12
  str = "<#{self.class}: "
32
13
  str << inspectable_vars.map { |v| "#{v.to_s.tr('@','')}: #{instance_variable_get(v)}" }.join(" ")
@@ -0,0 +1,113 @@
1
+ # coding: utf-8
2
+
3
+ require 'savon'
4
+ require 'cargowise/order_search'
5
+ require 'cargowise/shipment_search'
6
+
7
+ module Cargowise
8
+
9
+ # The starting point for accessing data from your logistics provider. See
10
+ # the README for usage tips.
11
+ #
12
+ # You should create a new Client instance for each company API you plan
13
+ # to query.
14
+ #
15
+ class Client
16
+
17
+ def initialize(opts = {})
18
+ @order_uri = opts[:order_uri]
19
+ @shipment_uri = opts[:shipment_uri]
20
+ @code = opts[:company_code]
21
+ @username = opts[:username]
22
+ @password = opts[:password]
23
+ end
24
+
25
+ # begin an order search. See the docs for Cargowise::OrderSearch for info
26
+ # on what you can do with the object returned from this method.
27
+ def orders
28
+ OrderSearch.new(orders_client)
29
+ end
30
+
31
+ # begin a shipment search. See the docs for Cargowise::ShipmentSearch for
32
+ # info on what you can do with the object returned from this method.
33
+ def shipments
34
+ ShipmentSearch.new(shipments_client)
35
+ end
36
+
37
+ def orders_hello
38
+ response = orders_client.call(:hello)
39
+ response.xpath("//tns:HelloResponse/tns:HelloResult/text()", {"tns" => Cargowise::DEFAULT_NS}).to_s
40
+ end
41
+
42
+ def shipments_hello
43
+ response = shipments_client.call(:hello)
44
+ response.xpath("//tns:HelloResponse/tns:HelloResult/text()", {"tns" => Cargowise::DEFAULT_NS}).to_s
45
+ end
46
+
47
+ # Find the base URI for the web interface at this client
48
+ #
49
+ def base_uri
50
+ uri = @shipment_uri || @order_uri || ""
51
+ uri.to_s[/(.+)\/WebService.+/,1]
52
+ end
53
+
54
+ private
55
+
56
+ def orders_client
57
+ build_client(order_wsdl_path, @order_uri)
58
+ end
59
+
60
+ def order_wsdl_path
61
+ File.join(
62
+ File.dirname(__FILE__),
63
+ "order_wsdl.xml"
64
+ )
65
+ end
66
+
67
+ def shipments_client
68
+ build_client(shipment_wsdl_path, @shipment_uri)
69
+ end
70
+
71
+ def shipment_wsdl_path
72
+ File.join(
73
+ File.dirname(__FILE__),
74
+ "shipment_wsdl.xml"
75
+ )
76
+ end
77
+
78
+ # TODO: make some of these configurable via the initialize to Cargowise::Client. Will enable
79
+ # providers that need special treatment to work (like OHL) to be configured differently
80
+ # by the calling code
81
+ def build_client(wsdl_path, endpoint_uri)
82
+ Savon.client(
83
+ wsdl: wsdl_path,
84
+ endpoint: endpoint_uri,
85
+
86
+ # Cargowise servers can be super slow to respond, this gives them time
87
+ # to have a smoko before responding to our queries.
88
+ read_timeout: 240,
89
+
90
+ # OHL uses cargowise and has a load balancer that freaks out if we use
91
+ # the OpenSSL 1.0.1 default of TLS1.1.
92
+ ssl_version: :TLSv1,
93
+
94
+ # savon 2.2.0 ignores the above ssl_version unless this is set to
95
+ # false. Annoying.
96
+ ssl_verify_mode: :none,
97
+
98
+ # turn off logging to keep me sane. Change this to true when developing
99
+ log: false,
100
+
101
+ # the cargowsie API requires auth details in the SOAP header of every
102
+ # request
103
+ soap_header: {
104
+ "tns:WebTrackerSOAPHeader" => {
105
+ "tns:CompanyCode" => @code,
106
+ "tns:UserName" => @username,
107
+ "tns:Password" => @password
108
+ }
109
+ }
110
+ )
111
+ end
112
+ end
113
+ end
@@ -1,5 +1,7 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'cargowise/abstract_result'
4
+
3
5
  module Cargowise
4
6
 
5
7
  # Extra shipping detail associated with a Shipment. Not built
@@ -1,5 +1,7 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'cargowise/abstract_result'
4
+
3
5
  module Cargowise
4
6
 
5
7
  # A document that is associated with a Shipment. Not built
@@ -1,5 +1,7 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'cargowise/abstract_result'
4
+
3
5
  module Cargowise
4
6
 
5
7
  # An invoice that is associated with a Shipment. Not built
@@ -1,5 +1,8 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'cargowise/abstract_result'
4
+ require 'cargowise/shipment'
5
+
3
6
  module Cargowise
4
7
 
5
8
  # A purchase order that is being shipped to from a supplier to
@@ -1,8 +1,14 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'cargowise/order'
4
+
3
5
  module Cargowise
4
6
 
5
- class OrderSearch < AbstractSearch
7
+ class OrderSearch
8
+
9
+ def initialize(savon_client)
10
+ @savon_client = savon_client
11
+ end
6
12
 
7
13
  # find all orders with an OrderNumber that matches ref
8
14
  #
@@ -15,7 +21,7 @@ module Cargowise
15
21
  }
16
22
  }
17
23
  }
18
- OrdersClient.new.get_order_list(ep.uri, ep.code, ep.user, ep.password, filter_hash)
24
+ get_order_list(filter_hash)
19
25
  end
20
26
 
21
27
  # find all orders with a ShipmentNumber that matches ref
@@ -29,7 +35,7 @@ module Cargowise
29
35
  }
30
36
  }
31
37
  }
32
- OrdersClient.new.get_order_list(ep.uri, ep.code, ep.user, ep.password, filter_hash)
38
+ get_order_list(filter_hash)
33
39
  end
34
40
 
35
41
  # find all orders still marked as incomplete.
@@ -38,7 +44,22 @@ module Cargowise
38
44
  filter_hash = {
39
45
  "tns:Filter" => { "tns:OrderStatus" => "INC" }
40
46
  }
41
- OrdersClient.new.get_order_list(ep.uri, ep.code, ep.user, ep.password, filter_hash)
47
+ get_order_list(filter_hash)
48
+ end
49
+
50
+ private
51
+
52
+ # return an array of orders. Each order *should* correspond to a buyer PO.
53
+ #
54
+ # filter_hash should be a hash that will be serialised into an
55
+ # XML fragment specifying the search criteria. See the WSDL documentation
56
+ # for samples
57
+ #
58
+ def get_order_list(filter_hash)
59
+ response = @savon_client.call(:get_order_list, message: filter_hash)
60
+ response.xpath("//tns:GetOrderListResult/tns:WebOrder", {"tns" => Cargowise::DEFAULT_NS}).map do |node|
61
+ Cargowise::Order.new(node)
62
+ end
42
63
  end
43
64
 
44
65
  end
@@ -1,5 +1,7 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'cargowise/abstract_result'
4
+
3
5
  module Cargowise
4
6
 
5
7
  # Extra packing detail associated with a Shipment. Not built
@@ -1,5 +1,11 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'cargowise/abstract_result'
4
+ require 'cargowise/packing'
5
+ require 'cargowise/consol'
6
+ require 'cargowise/document'
7
+ require 'cargowise/invoice'
8
+
3
9
  module Cargowise
4
10
 
5
11
  # A shipment that is currently on its way to you. Could take on a
@@ -88,23 +94,23 @@ module Cargowise
88
94
 
89
95
  # lookup full Cargowise::Order objects for each order on this shipment.
90
96
  #
91
- # 'via' is a symbol indicating which API endpoint to lookup.
97
+ # client is a Cargowise::Client instance to look for the related shipments on
92
98
  #
93
- def orders(via)
94
- @orders ||= Cargowise::Order.via(via).by_shipment_number(self.number)
99
+ def orders(client)
100
+ @orders ||= client.orders.by_shipment_number(self.number)
95
101
  end
96
102
 
97
103
  # lookup related Cargowise::Shipment objects. These are usually "child" shipments
98
104
  # grouped under a parent. Think a consolidated pallet (the parent) with cartons from
99
105
  # multiple suppliers (the children).
100
106
  #
101
- # 'via' is a symbol indicating which API endpoint to lookup.
107
+ # client is a Cargowise::Client instance to look for the related shipments on
102
108
  #
103
- def related_shipments(via)
109
+ def related_shipments(client)
104
110
  @related ||= @consols.map { |consol|
105
111
  consol.master_bill
106
112
  }.compact.map { |master_bill|
107
- Cargowise::Shipment.via(via).by_masterbill_number(master_bill)
113
+ client.shipments.by_masterbill_number(master_bill)
108
114
  }.flatten.select { |shipment|
109
115
  shipment.number != self.number
110
116
  }.compact
@@ -115,9 +121,11 @@ module Cargowise
115
121
  # This data isn't available via the API, so we need to screen scrape the
116
122
  # website to get it.
117
123
  #
118
- def order_ref(via)
119
- if tracker_login_uri(via)
120
- @order_ref ||= html_page(via).search(".//span[@id='Ztextlabel1']/text()").to_s.strip || ""
124
+ # client is a Cargowise::Client instance to look for the related shipments on
125
+ #
126
+ def order_ref(client)
127
+ if client.base_uri
128
+ @order_ref ||= html_page(client).search(".//span[@id='Ztextlabel1']/text()").to_s.strip || ""
121
129
  else
122
130
  nil
123
131
  end
@@ -127,12 +135,11 @@ module Cargowise
127
135
 
128
136
  # retrieve a Mechanize::Page object that containts info on this shipment
129
137
  #
130
- def html_page(via)
131
- return nil unless tracker_login_uri(via)
138
+ def html_page(client)
139
+ return nil unless client.base_uri
132
140
 
133
141
  @html_page ||= begin
134
- base_uri = tracker_login_uri(via)
135
- login_uri = base_uri + "/Login/Login.aspx"
142
+ login_uri = client.base_uri + "/Login/Login.aspx"
136
143
  agent = Mechanize.new
137
144
  agent.agent.http.ssl_version = :TLSv1
138
145
  if File.file?(Cargowise::CA_CERT_FILE)
@@ -147,11 +154,5 @@ module Cargowise
147
154
  end
148
155
  end
149
156
 
150
- # Find a shipment with documents attached so we can discover the
151
- # web interface uri
152
- #
153
- def tracker_login_uri(via)
154
- Shipment.endpoint(via).uri.to_s[/(.+)\/WebService.+/,1]
155
- end
156
157
  end
157
158
  end
@@ -1,8 +1,14 @@
1
1
  # coding: utf-8
2
2
 
3
+ require 'cargowise/shipment'
4
+
3
5
  module Cargowise
4
6
 
5
- class ShipmentSearch < AbstractSearch
7
+ class ShipmentSearch
8
+
9
+ def initialize(savon_client)
10
+ @savon_client = savon_client
11
+ end
6
12
 
7
13
  # find all shipments with a MasterBillNumber that matches ref
8
14
  #
@@ -26,7 +32,7 @@ module Cargowise
26
32
  filter_hash = {
27
33
  "tns:Filter" => { "tns:Status" => "Undelivered" }
28
34
  }
29
- ShipmentsClient.new.get_shipments_list(ep.uri, ep.code, ep.user, ep.password, filter_hash)
35
+ get_shipments_list(filter_hash)
30
36
  end
31
37
 
32
38
  # find all shipments that had some activity in the past fourteen days. This could
@@ -42,7 +48,7 @@ module Cargowise
42
48
  }
43
49
  }
44
50
  }
45
- ShipmentsClient.new.get_shipments_list(ep.uri, ep.code, ep.user, ep.password, filter_hash)
51
+ get_shipments_list(filter_hash)
46
52
  end
47
53
 
48
54
  # find all shipments that had were shipped in the past 14 days or will ship in
@@ -58,7 +64,7 @@ module Cargowise
58
64
  }
59
65
  }
60
66
  }
61
- ShipmentsClient.new.get_shipments_list(ep.uri, ep.code, ep.user, ep.password, filter_hash)
67
+ get_shipments_list(filter_hash)
62
68
  end
63
69
 
64
70
  private
@@ -72,7 +78,21 @@ module Cargowise
72
78
  }
73
79
  }
74
80
  }
75
- ShipmentsClient.new.get_shipments_list(ep.uri, ep.code, ep.user, ep.password, filter_hash)
81
+ get_shipments_list(filter_hash)
82
+ end
83
+
84
+ # return an array of shipments. Each shipment should correspond to
85
+ # a consolidated shipment from the freight company.
86
+ #
87
+ # filter_hash should be a hash that will be serialised into an
88
+ # XML fragment specifying the search criteria. See the WSDL documentation
89
+ # for samples
90
+ #
91
+ def get_shipments_list(filter_hash)
92
+ response = @savon_client.call(:get_shipments_list, message: filter_hash)
93
+ response.xpath("//tns:GetShipmentsListResult/tns:WebShipment", {"tns" => Cargowise::DEFAULT_NS}).map do |node|
94
+ Cargowise::Shipment.new(node)
95
+ end
76
96
  end
77
97
 
78
98
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cargowise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.2
4
+ version: 1.0.0.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Healy
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - ~>
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.0'
69
- description: Retrieve tracking and status information on your shipments from entpriseEDI
69
+ description: Retrieve tracking and status information on your shipments from ediEnterprise
70
70
  email:
71
71
  - james@yob.id.au
72
72
  executables: []
@@ -77,16 +77,12 @@ files:
77
77
  - lib/cargowise/order_search.rb
78
78
  - lib/cargowise/consol.rb
79
79
  - lib/cargowise/invoice.rb
80
+ - lib/cargowise/client.rb
80
81
  - lib/cargowise/order.rb
81
82
  - lib/cargowise/document.rb
82
- - lib/cargowise/orders_client.rb
83
- - lib/cargowise/abstract_client.rb
84
83
  - lib/cargowise/shipment.rb
85
- - lib/cargowise/shipments_client.rb
86
84
  - lib/cargowise/packing.rb
87
- - lib/cargowise/abstract_search.rb
88
85
  - lib/cargowise/abstract_result.rb
89
- - lib/cargowise/endpoint.rb
90
86
  - lib/cargowise/shipment_search.rb
91
87
  - lib/cargowise/order_wsdl.xml
92
88
  - lib/cargowise/shipment_wsdl.xml
@@ -99,7 +95,18 @@ homepage: http://github.com/yob/cargowise
99
95
  licenses:
100
96
  - mit
101
97
  metadata: {}
102
- post_install_message:
98
+ post_install_message: |2+
99
+
100
+ ********************************************
101
+
102
+ v1.0.0 of cargowise introduced a new API. There are extensive
103
+ examples showing how to use it in the README and examples directory.
104
+
105
+ The old API has been removed, so you will need to update your code
106
+ before it will work with cargowise 1.0.0 or higher.
107
+
108
+ ********************************************
109
+
103
110
  rdoc_options:
104
111
  - --title
105
112
  - Cargowise
@@ -113,13 +120,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
120
  version: '0'
114
121
  required_rubygems_version: !ruby/object:Gem::Requirement
115
122
  requirements:
116
- - - '>='
123
+ - - '>'
117
124
  - !ruby/object:Gem::Version
118
- version: '0'
125
+ version: 1.3.1
119
126
  requirements: []
120
127
  rubyforge_project:
121
128
  rubygems_version: 2.0.3
122
129
  signing_key:
123
130
  specification_version: 4
124
- summary: Wrapper around entpriseEDI SOAP API by cargowise
131
+ summary: client library for the ediEnterprise SOAP API by cargowise
125
132
  test_files: []
@@ -1,46 +0,0 @@
1
- # coding: utf-8
2
-
3
- module Cargowise
4
-
5
- # Superclass of all clients, currently we have clients for
6
- # orders and Shipments.
7
- #
8
- # Not much to see here, just common methods
9
- #
10
- class AbstractClient
11
-
12
- private
13
-
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: 240,
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
- }
42
- }
43
- )
44
- end
45
- end
46
- end
@@ -1,25 +0,0 @@
1
- # coding: utf-8
2
-
3
- module Cargowise
4
-
5
- class AbstractSearch
6
-
7
- def initialize(endpoint)
8
- @endpoint = endpoint
9
- end
10
-
11
- private
12
-
13
- def ep
14
- @endpoint
15
- end
16
-
17
- def endpoint_hash
18
- {
19
- :uri => ep.uri,
20
- :version => 2
21
- }
22
- end
23
-
24
- end
25
- end
@@ -1,27 +0,0 @@
1
- # coding: utf-8
2
-
3
- module Cargowise
4
-
5
- # Stores the details for connecting to a single logistics company.
6
- #
7
- # Generally created using the register() method on the Order and
8
- # Shipment classes.
9
- #
10
- class Endpoint
11
-
12
- attr_reader :uri
13
- attr_reader :code, :user, :password
14
-
15
- # create a new endpoint. All 4 options are compulsory.
16
- #
17
- def initialize(opts = {})
18
- raise ArgumentError, "option :uri must be provided" if opts[:uri].nil?
19
- raise ArgumentError, "option :code must be provided" if opts[:code].nil?
20
- raise ArgumentError, "option :user must be provided" if opts[:user].nil?
21
- raise ArgumentError, "option :password must be provided" if opts[:password].nil?
22
-
23
- @uri = opts[:uri]
24
- @code, @user, @password = opts[:code], opts[:user], opts[:password]
25
- end
26
- end
27
- end
@@ -1,43 +0,0 @@
1
- # coding: utf-8
2
-
3
- module Cargowise
4
-
5
- # SOAP client for retreiving order data. Not much to
6
- # see here, used by the Order resource class.
7
- #
8
- class OrdersClient < AbstractClient
9
-
10
- # return an array of orders. Each order *should* correspond to a buyer PO.
11
- #
12
- # filter_hash should be a hash that will be serialised into an
13
- # XML fragment specifying the search criteria. See the WSDL documentation
14
- # for samples
15
- #
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|
20
- Cargowise::Order.new(node)
21
- end
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
-
42
- end
43
- end
@@ -1,44 +0,0 @@
1
- # coding: utf-8
2
-
3
- module Cargowise
4
-
5
- # SOAP client for retreiving shipment data. Not much to
6
- # see here, used by the Shipment resource class.
7
- #
8
- class ShipmentsClient < AbstractClient
9
-
10
- # return an array of shipments. Each shipment should correspond to
11
- # a consolidated shipment from the freight company.
12
- #
13
- # filter_hash should be a hash that will be serialised into an
14
- # XML fragment specifying the search criteria. See the WSDL documentation
15
- # for samples
16
- #
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|
21
- Cargowise::Shipment.new(node)
22
- end
23
- end
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
-
43
- end
44
- end