ontrac-web-services 0.9.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +56 -36
- data/lib/ontrac/version.rb +1 -1
- data/lib/ontrac/web_services/definitions.rb +92 -21
- data/lib/ontrac/web_services/service.rb +86 -84
- data/ontrac-web-services.gemspec +2 -2
- metadata +14 -40
- data/lib/ontrac/web_services/definitions/base.rb +0 -43
- data/lib/ontrac/web_services/definitions/delivery_data.rb +0 -32
- data/lib/ontrac/web_services/definitions/package.rb +0 -9
- data/lib/ontrac/web_services/definitions/package_data.rb +0 -16
- data/lib/ontrac/web_services/definitions/package_detail.rb +0 -29
- data/lib/ontrac/web_services/definitions/shipment_request.rb +0 -16
- data/lib/ontrac/web_services/definitions/shipper_data.rb +0 -16
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 24a06b1c019fcaf0f2cbef819a1e49a08ae3816c
|
4
|
+
data.tar.gz: 171990d6bf720583f218d2a98357d08f783ee04a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5628443f315087ab0867490564a284581288fcaacad9322341643addd542356341aad80d2cb561b3336c8e0756a109e0539ca208adb35d3298c0749d9d967f40
|
7
|
+
data.tar.gz: 817be89a68a55a9cea04402c06b6849b1894020c181df5ff45460dedcca9ba8a9ab3bb1f2d13b23443765bf743e75062bb57c9eb0870cd9d464059e7003978cc
|
data/README.md
CHANGED
@@ -1,48 +1,68 @@
|
|
1
1
|
# ontrac-web-services
|
2
2
|
## Description
|
3
|
-
This gem provides an interface to the OnTrac web services API. It interfaces with its HTTP/POST API to generate labels
|
3
|
+
This gem provides an interface to the OnTrac web services API. It interfaces with its HTTP/POST API to generate labels.
|
4
4
|
|
5
5
|
## Examples
|
6
6
|
### Creating a shipment with multiple packages
|
7
7
|
|
8
8
|
```ruby
|
9
|
-
|
9
|
+
require 'logger'
|
10
|
+
require 'ontrac'
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
include ::Ontrac::WebServices
|
13
|
+
include ::Ontrac::WebServices::Definitions
|
13
14
|
|
14
|
-
|
15
|
-
|
15
|
+
logger = Logger.new($stderr)
|
16
|
+
credentials = Service::Credentials.new("37", "testpass", "test")
|
17
|
+
service = Service.new(credentials, StringIO.new(debug_output = ""))
|
16
18
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
requests = [ 10.1, 22, 15 ].map do |package_weight|
|
20
|
+
ShipmentRequest.new.tap do |request|
|
21
|
+
request.shipper = Shipper.new.tap do |shipper|
|
22
|
+
shipper.Name = "Fulfillment Circle"
|
23
|
+
shipper.Addr1 = "343 Third Street\nSuite 17"
|
24
|
+
shipper.City = "sparks"
|
25
|
+
shipper.State = "NV"
|
26
|
+
shipper.Zip = "89434"
|
27
|
+
shipper.Contact = "John D."
|
28
|
+
shipper.Phone = "(415) 350-2608"
|
29
|
+
end
|
30
|
+
request.consignee = Consignee.new.tap do |consignee|
|
31
|
+
consignee.Name = "Joe Shmoe"
|
32
|
+
consignee.Addr1 = "123 4th St"
|
33
|
+
consignee.Addr2 = "Suite 315"
|
34
|
+
consignee.City = "San Luis Obispo"
|
35
|
+
consignee.State = "CA"
|
36
|
+
consignee.Zip = "93401"
|
37
|
+
consignee.Phone = "(805) 555-1234"
|
38
|
+
end
|
39
|
+
request.Service = SERVICE_TYPE_GROUND
|
40
|
+
request.SignatureRequired = false
|
41
|
+
request.Residential = true
|
42
|
+
request.SaturdayDel = false
|
43
|
+
request.Declared = 0
|
44
|
+
request.Weight = package_weight
|
45
|
+
request.LabelType = LABEL_TYPE_PDF
|
46
|
+
request.ShipDate = Time.new.strftime("%Y-%m-%d")
|
47
|
+
end
|
48
|
+
end
|
25
49
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
puts "charge: #{charge.to_f}"
|
45
|
-
File.open("#{tracking_number}.pdf", "w") { |f| f << label }
|
46
|
-
tracking_number
|
47
|
-
end
|
50
|
+
begin
|
51
|
+
service.post_shipments(requests).each do |(tracking_number, label, charge)|
|
52
|
+
File.open("#{tracking_number}.pdf", "w") { |f| f << label }
|
53
|
+
logger.info("label: ./#{tracking_number}.pdf, charge: #{charge}")
|
54
|
+
end
|
55
|
+
rescue ServiceException => err
|
56
|
+
logger.error("OnTrac Service Exception: #{err.message}")
|
57
|
+
logger.error("Root Error: #{err.root_error}") if (err.root_error && !err.root_error.empty?)
|
58
|
+
err.sub_errors.each do |uid, sub_error|
|
59
|
+
logger.error("Sub Error (#{uid}): #{sub_error}")
|
60
|
+
end
|
61
|
+
raise
|
62
|
+
ensure
|
63
|
+
if ($! && !debug_output.empty?)
|
64
|
+
logger.debug("OnTrac HTTP debug output")
|
65
|
+
debug_output.each_line.map(&:strip).each(&logger.method(:debug))
|
66
|
+
end
|
67
|
+
end
|
48
68
|
```
|
data/lib/ontrac/version.rb
CHANGED
@@ -1,24 +1,95 @@
|
|
1
|
-
module Ontrac
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module Ontrac
|
2
|
+
module WebServices
|
3
|
+
module Definitions
|
4
|
+
class DefinitionBase < Struct
|
5
|
+
def initialize(*)
|
6
|
+
super
|
7
|
+
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
def to_xml(root_name = nil)
|
10
|
+
xml_builder = Nokogiri::XML::Builder.new
|
11
|
+
root_name ||= self.class.name.split("::").last
|
12
|
+
|
13
|
+
xml_builder.send(root_name) do |xml|
|
14
|
+
members.each do |field|
|
15
|
+
value = send(field)
|
16
|
+
if (DefinitionBase === value)
|
17
|
+
xml.doc.root << value.to_xml(field)
|
18
|
+
else
|
19
|
+
xml.send(field, value) unless (value.nil?)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
xml_builder.doc.root
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Shipper = DefinitionBase.new(
|
29
|
+
:Name,
|
30
|
+
:Addr1,
|
31
|
+
:City,
|
32
|
+
:State,
|
33
|
+
:Zip,
|
34
|
+
:Contact,
|
35
|
+
:Phone
|
36
|
+
)
|
37
|
+
Consignee = DefinitionBase.new(
|
38
|
+
:Name,
|
39
|
+
:Addr1,
|
40
|
+
:Addr2,
|
41
|
+
:Addr3,
|
42
|
+
:City,
|
43
|
+
:State,
|
44
|
+
:Zip,
|
45
|
+
:Contact,
|
46
|
+
:Phone
|
47
|
+
)
|
48
|
+
Dim = DefinitionBase.new(
|
49
|
+
:Length,
|
50
|
+
:Width,
|
51
|
+
:Height
|
52
|
+
)
|
53
|
+
ShipmentRequest = DefinitionBase.new(
|
54
|
+
:UID,
|
55
|
+
:shipper,
|
56
|
+
:consignee,
|
57
|
+
:Service,
|
58
|
+
:SignatureRequired,
|
59
|
+
:Residential,
|
60
|
+
:SaturdayDel,
|
61
|
+
:Declared,
|
62
|
+
:COD,
|
63
|
+
:CODType,
|
64
|
+
:Weight,
|
65
|
+
:Letter,
|
66
|
+
:BillTo,
|
67
|
+
:Instructions,
|
68
|
+
:Reference,
|
69
|
+
:Reference2,
|
70
|
+
:Reference3,
|
71
|
+
:Tracking,
|
72
|
+
:DIM,
|
73
|
+
:LabelType,
|
74
|
+
:ShipEmail,
|
75
|
+
:DelEmail,
|
76
|
+
:ShipDate,
|
77
|
+
:CargoType
|
78
|
+
)
|
79
|
+
|
80
|
+
SERVICE_TYPE_GROUND = "C"
|
81
|
+
SERVICE_TYPE_SUNRISE = "S"
|
82
|
+
SERVICE_TYPE_SUNRISE_GOLD = "G"
|
83
|
+
SERVICE_TYPE_PALLETIZED_FREIGHT = "H"
|
84
|
+
|
85
|
+
LABEL_TYPE_NONE = 0
|
86
|
+
LABEL_TYPE_PDF = 1
|
87
|
+
LABEL_TYPE_EPL_4_X_5 = 6
|
88
|
+
LABEL_TYPE_ZPL_4_X_5 = 7
|
89
|
+
|
90
|
+
COD_TYPE_NONE = "NONE"
|
91
|
+
COD_TYPE_UNSECURED = "UNSECURED "
|
92
|
+
COD_TYPE_SECURED = "SECURED"
|
93
|
+
end
|
15
94
|
end
|
16
95
|
end
|
17
|
-
|
18
|
-
require 'ontrac/web_services/definitions/base'
|
19
|
-
require 'ontrac/web_services/definitions/delivery_data'
|
20
|
-
require 'ontrac/web_services/definitions/package'
|
21
|
-
require 'ontrac/web_services/definitions/package_data'
|
22
|
-
require 'ontrac/web_services/definitions/package_detail'
|
23
|
-
require 'ontrac/web_services/definitions/shipment_request'
|
24
|
-
require 'ontrac/web_services/definitions/shipper_data'
|
@@ -1,121 +1,123 @@
|
|
1
1
|
require 'net/https'
|
2
2
|
require 'nokogiri'
|
3
3
|
require 'base64'
|
4
|
+
require 'cgi'
|
5
|
+
require 'securerandom'
|
4
6
|
|
5
7
|
module Ontrac::WebServices
|
6
|
-
class ServiceException <
|
7
|
-
attr_accessor :
|
8
|
+
class ServiceException < Exception
|
9
|
+
attr_accessor :root_error, :sub_errors
|
8
10
|
end
|
9
11
|
|
10
12
|
class Service
|
11
|
-
Credentials
|
13
|
+
class Credentials
|
14
|
+
attr_reader :account, :password, :environment
|
15
|
+
|
16
|
+
def initialize(account, password, environment)
|
17
|
+
@account = account or
|
18
|
+
raise ArgumentError.new("Missing OnTrac credential: account")
|
19
|
+
@password = password or
|
20
|
+
raise ArgumentError.new("Missing OnTrac credential: account")
|
21
|
+
@environment = environment or
|
22
|
+
raise ArgumentError.new("Missing OnTrac credential: environment")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
attr_accessor :debug_output
|
12
27
|
|
13
|
-
def initialize(credentials)
|
28
|
+
def initialize(credentials, debug_output = nil)
|
14
29
|
@credentials = credentials
|
30
|
+
self.debug_output = debug_output
|
15
31
|
end
|
16
32
|
|
17
|
-
def service_url(
|
18
|
-
(@credentials.environment.to_sym == :production) ?
|
19
|
-
"https://www.shipontrac.net/
|
20
|
-
"https://www.shipontrac.net/
|
21
|
-
end
|
33
|
+
def service_url(service_name)
|
34
|
+
url_base = (@credentials.environment.to_sym == :production) ?
|
35
|
+
"https://www.shipontrac.net/OnTracWebServices/OnTracServices.svc/V2" :
|
36
|
+
"https://www.shipontrac.net/OnTracTestWebServices/OnTracServices.svc/V2"
|
22
37
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
label_type != Definitions::LABEL_TYPE_EPL_4X3 &&
|
28
|
-
label_type != Definitions::LABEL_TYPE_EPL_4X5
|
29
|
-
|
30
|
-
request = Definitions::ShipmentRequest.new
|
31
|
-
request.account = @credentials.account
|
32
|
-
request.password = @credentials.password
|
33
|
-
|
34
|
-
request.packages = package_weights.map.with_index do |weight, ndx|
|
35
|
-
Definitions::Package.new.tap do |package|
|
36
|
-
package.package_data = Definitions::PackageData.new.tap do |data|
|
37
|
-
data.shipper_data = shipper_data
|
38
|
-
data.delivery_data = delivery_data
|
39
|
-
|
40
|
-
data.package_detail = Definitions::PackageDetail.new.tap do |detail|
|
41
|
-
detail.service = service
|
42
|
-
detail.weight = weight
|
43
|
-
detail.ship_email = ""
|
44
|
-
detail.del_email = ""
|
45
|
-
detail.label_type = label_type
|
46
|
-
end
|
47
|
-
end
|
38
|
+
"%s/%s/%s?pw=%s" % [
|
39
|
+
url_base, @credentials.account, service_name, CGI.escape(@credentials.password)
|
40
|
+
]
|
41
|
+
end
|
48
42
|
|
49
|
-
|
50
|
-
|
43
|
+
def post_shipments(shipment_requests)
|
44
|
+
shipment_requests.map do |shipment_request|
|
45
|
+
shipment_request.shipper.Contact ||= ""
|
46
|
+
shipment_request.shipper.Phone ||= ""
|
47
|
+
|
48
|
+
shipment_request.consignee.Addr2 ||= ""
|
49
|
+
shipment_request.consignee.Addr3 ||= ""
|
50
|
+
shipment_request.consignee.Contact ||= ""
|
51
|
+
shipment_request.consignee.Phone ||= ""
|
52
|
+
|
53
|
+
shipment_request.UID = SecureRandom.hex(16)
|
54
|
+
shipment_request.COD ||= 0
|
55
|
+
shipment_request.CODType ||= Definitions::COD_TYPE_NONE
|
56
|
+
shipment_request.BillTo ||= 0
|
57
|
+
shipment_request.Instructions ||= ""
|
58
|
+
shipment_request.Reference ||= ""
|
59
|
+
shipment_request.Reference2 ||= ""
|
60
|
+
shipment_request.Reference3 ||= ""
|
61
|
+
shipment_request.Tracking ||= ""
|
62
|
+
shipment_request.DIM ||= Definitions::Dim.new(0, 0, 0)
|
63
|
+
shipment_request.ShipEmail ||= ""
|
64
|
+
shipment_request.DelEmail ||= ""
|
51
65
|
end
|
52
66
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
issue_request("ShipmentRequest", request_xml) do |response_xml|
|
60
|
-
%w(Label Tracking Charges/TotalCharge).each do |node_name|
|
61
|
-
count = response_xml.xpath("count(#{package_data_path}/#{node_name})")
|
62
|
-
if (response_xml.xpath("count(#{package_data_path}/#{node_name})") != num_packages)
|
63
|
-
raise "Expected #{num_packages} #{node_name} response(s), received #{count}"
|
67
|
+
xml_builder = Nokogiri::XML::Builder.new
|
68
|
+
xml_builder.OnTracShipmentRequest do |xml|
|
69
|
+
xml.Shipments do |xml|
|
70
|
+
shipment_requests.each do |shipment_request|
|
71
|
+
xml.parent << shipment_request.to_xml("Shipment")
|
64
72
|
end
|
65
73
|
end
|
74
|
+
end
|
66
75
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
[
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
76
|
+
response_xml = issue_request('shipments', xml_builder.doc)
|
77
|
+
shipment_requests.map do |request|
|
78
|
+
uid = request.UID
|
79
|
+
shipment_response = response_xml.xpath(
|
80
|
+
"/OnTracShipmentResponse/Shipments/Shipment[./UID = '#{uid}']"
|
81
|
+
).first or raise ServiceException.new("Missing package response for #{uid}")
|
82
|
+
|
83
|
+
label = shipment_response.xpath("Label").text
|
84
|
+
label = Base64.decode64(label) if (request.LabelType == Definitions::LABEL_TYPE_PDF)
|
85
|
+
[
|
86
|
+
shipment_response.xpath("Tracking").text,
|
87
|
+
label,
|
88
|
+
Float(shipment_response.xpath("TotalChrg").text)
|
89
|
+
]
|
78
90
|
end
|
79
91
|
end
|
80
92
|
|
81
93
|
private
|
82
|
-
def issue_request(
|
83
|
-
uri = URI.parse(service_url(
|
94
|
+
def issue_request(service_name, request_xml)
|
95
|
+
uri = URI.parse(service_url(service_name))
|
84
96
|
http = Net::HTTP.new(uri.host, uri.port)
|
97
|
+
http.set_debug_output(debug_output) if (debug_output)
|
85
98
|
http.use_ssl = true
|
86
99
|
|
87
100
|
response = http.request_post(uri.request_uri, request_xml.to_s)
|
88
101
|
response_xml = Nokogiri::XML(response.body)
|
89
102
|
|
90
103
|
check_response(response_xml)
|
91
|
-
|
92
|
-
rescue Timeout::Error, SocketError => root_exception
|
93
|
-
err = ServiceException.new("Network communication error")
|
94
|
-
err.set_backtrace([ "#{__FILE__}:#{__LINE__ + 1}", *root_exception.backtrace ])
|
95
|
-
raise err
|
96
|
-
rescue Exception => root_exception
|
97
|
-
err = ServiceException.new(root_exception.message)
|
98
|
-
err.details = { request: request_xml.to_s, response: response.body }
|
99
|
-
err.set_backtrace([ "#{__FILE__}:#{__LINE__ + 1}", *root_exception.backtrace ])
|
100
|
-
raise err
|
104
|
+
response_xml
|
101
105
|
end
|
102
106
|
|
103
107
|
def check_response(response_xml)
|
104
|
-
|
105
|
-
|
106
|
-
package_messages = response_xml.xpath("//PackageData/Message")
|
107
|
-
|
108
|
-
if (status.empty? || status != "1" || response_xml.xpath("//PackageData/Status != 1"))
|
109
|
-
if (status.empty? && message.empty?)
|
110
|
-
msg = "OnTrac's label system returned an invalid response"
|
111
|
-
else
|
112
|
-
msg = "No status information was returned for the request" if (status.empty?)
|
113
|
-
msg = message || "The request returned a status of #{status}" if (status != "1")
|
114
|
-
msg << " -- " + [ *package_messages.to_a ] * " ; " if (!package_messages.empty?)
|
115
|
-
end
|
108
|
+
root_error = response_xml.xpath("/OnTracShipmentResponse/Error").text
|
109
|
+
erred_shipments = response_xml.xpath("//Shipment[./Error != '']")
|
116
110
|
|
117
|
-
|
118
|
-
|
111
|
+
return if (root_error.empty? && erred_shipments.empty?)
|
112
|
+
|
113
|
+
err = ServiceException.new("OnTrac responded with an error")
|
114
|
+
err.root_error = root_error
|
115
|
+
err.sub_errors = Hash[
|
116
|
+
erred_shipments.map do |shipment_response|
|
117
|
+
[ shipment_response.xpath("./UID").text, shipment_response.xpath("./Error").text ]
|
118
|
+
end
|
119
|
+
]
|
120
|
+
raise err
|
119
121
|
end
|
120
122
|
end
|
121
123
|
end
|
data/ontrac-web-services.gemspec
CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.description = %q{Provides an interface to the OnTrac web services API}
|
8
8
|
gem.summary = %q{Interfaces with the OnTrac web services API to look up shipping rates, generate labels, and track shipments}
|
9
9
|
gem.homepage = "https://github.com/brewski/ontrac-web-services"
|
10
|
+
gem.license = "MIT"
|
10
11
|
|
11
12
|
gem.files = `git ls-files`.split($\)
|
12
13
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -16,6 +17,5 @@ Gem::Specification.new do |gem|
|
|
16
17
|
gem.version = Ontrac::VERSION
|
17
18
|
|
18
19
|
gem.required_ruby_version = '>= 1.9.0'
|
19
|
-
gem.add_dependency("
|
20
|
-
gem.add_dependency("nokogiri")
|
20
|
+
gem.add_dependency("nokogiri", "~> 1.0")
|
21
21
|
end
|
metadata
CHANGED
@@ -1,48 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ontrac-web-services
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Brian Abreu
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2015-08-15 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: activesupport
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ! '>='
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: '0'
|
22
|
-
type: :runtime
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ! '>='
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '0'
|
30
13
|
- !ruby/object:Gem::Dependency
|
31
14
|
name: nokogiri
|
32
15
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
16
|
requirements:
|
35
|
-
- -
|
17
|
+
- - "~>"
|
36
18
|
- !ruby/object:Gem::Version
|
37
|
-
version: '0'
|
19
|
+
version: '1.0'
|
38
20
|
type: :runtime
|
39
21
|
prerelease: false
|
40
22
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
23
|
requirements:
|
43
|
-
- -
|
24
|
+
- - "~>"
|
44
25
|
- !ruby/object:Gem::Version
|
45
|
-
version: '0'
|
26
|
+
version: '1.0'
|
46
27
|
description: Provides an interface to the OnTrac web services API
|
47
28
|
email:
|
48
29
|
- brian@nuts.com
|
@@ -50,7 +31,7 @@ executables: []
|
|
50
31
|
extensions: []
|
51
32
|
extra_rdoc_files: []
|
52
33
|
files:
|
53
|
-
- .gitignore
|
34
|
+
- ".gitignore"
|
54
35
|
- Gemfile
|
55
36
|
- LICENSE
|
56
37
|
- README.md
|
@@ -59,38 +40,31 @@ files:
|
|
59
40
|
- lib/ontrac/version.rb
|
60
41
|
- lib/ontrac/web_services.rb
|
61
42
|
- lib/ontrac/web_services/definitions.rb
|
62
|
-
- lib/ontrac/web_services/definitions/base.rb
|
63
|
-
- lib/ontrac/web_services/definitions/delivery_data.rb
|
64
|
-
- lib/ontrac/web_services/definitions/package.rb
|
65
|
-
- lib/ontrac/web_services/definitions/package_data.rb
|
66
|
-
- lib/ontrac/web_services/definitions/package_detail.rb
|
67
|
-
- lib/ontrac/web_services/definitions/shipment_request.rb
|
68
|
-
- lib/ontrac/web_services/definitions/shipper_data.rb
|
69
43
|
- lib/ontrac/web_services/service.rb
|
70
44
|
- ontrac-web-services.gemspec
|
71
45
|
homepage: https://github.com/brewski/ontrac-web-services
|
72
|
-
licenses:
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata: {}
|
73
49
|
post_install_message:
|
74
50
|
rdoc_options: []
|
75
51
|
require_paths:
|
76
52
|
- lib
|
77
53
|
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
-
none: false
|
79
54
|
requirements:
|
80
|
-
- -
|
55
|
+
- - ">="
|
81
56
|
- !ruby/object:Gem::Version
|
82
57
|
version: 1.9.0
|
83
58
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
59
|
requirements:
|
86
|
-
- -
|
60
|
+
- - ">="
|
87
61
|
- !ruby/object:Gem::Version
|
88
62
|
version: '0'
|
89
63
|
requirements: []
|
90
64
|
rubyforge_project:
|
91
|
-
rubygems_version:
|
65
|
+
rubygems_version: 2.2.3
|
92
66
|
signing_key:
|
93
|
-
specification_version:
|
67
|
+
specification_version: 4
|
94
68
|
summary: Interfaces with the OnTrac web services API to look up shipping rates, generate
|
95
69
|
labels, and track shipments
|
96
70
|
test_files: []
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
require 'nokogiri'
|
3
|
-
|
4
|
-
module Ontrac::WebServices::Definitions
|
5
|
-
class Base
|
6
|
-
include Nokogiri
|
7
|
-
|
8
|
-
def self.attr_accessor(*args)
|
9
|
-
(@attributes ||= []).concat(args)
|
10
|
-
super
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.attributes
|
14
|
-
return (@attributes ||= [])
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.basename
|
18
|
-
ActiveSupport::Inflector.camelize(self.name.gsub(/^.*::/, ''))
|
19
|
-
end
|
20
|
-
|
21
|
-
def to_xml
|
22
|
-
xml_builder = Nokogiri::XML::Builder.new
|
23
|
-
|
24
|
-
xml_builder.send(self.class.basename) do |xml|
|
25
|
-
self.class.attributes.each do |attribute_name|
|
26
|
-
(values = *self.send(attribute_name)).each do |attribute_value|
|
27
|
-
xml_attr_name = respond_to?("#{attribute_name}_to_xml_name") ?
|
28
|
-
send("#{attribute_name}_to_xml_name") :
|
29
|
-
ActiveSupport::Inflector.camelize(attribute_name, false)
|
30
|
-
|
31
|
-
if (attribute_value.is_a?(Base))
|
32
|
-
xml.doc.root << attribute_value.to_xml
|
33
|
-
else
|
34
|
-
xml.send(xml_attr_name, attribute_value)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
xml_builder.doc.root
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module Ontrac
|
2
|
-
module WebServices
|
3
|
-
module Definitions
|
4
|
-
class DeliveryData < Base
|
5
|
-
attr_accessor :name
|
6
|
-
attr_accessor :address
|
7
|
-
attr_accessor :address2
|
8
|
-
attr_accessor :address3
|
9
|
-
attr_accessor :city
|
10
|
-
attr_accessor :state
|
11
|
-
attr_accessor :zip
|
12
|
-
attr_accessor :phone
|
13
|
-
attr_accessor :contact
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# [ DeliveryData, Package, PackageData, PackageDetail, ShipmentRequest, ShipperData ].map do |cls|
|
20
|
-
# accessors = cls.attributes.map { |a| " attr_accessor :#{a.to_s.underscore}" }
|
21
|
-
# <<-CLSDEF
|
22
|
-
# module Ontrac
|
23
|
-
# module WebServices
|
24
|
-
# module Definitions
|
25
|
-
# class #{cls.name.split("::").last} < Base
|
26
|
-
# #{accessors * "\n"}
|
27
|
-
# end
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
# end
|
31
|
-
# CLSDEF
|
32
|
-
# end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Ontrac
|
2
|
-
module WebServices
|
3
|
-
module Definitions
|
4
|
-
class PackageData < Base
|
5
|
-
attr_accessor :uid
|
6
|
-
attr_accessor :shipper_data
|
7
|
-
attr_accessor :delivery_data
|
8
|
-
attr_accessor :package_detail
|
9
|
-
|
10
|
-
def uid_to_xml_name
|
11
|
-
"UID"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module Ontrac
|
2
|
-
module WebServices
|
3
|
-
module Definitions
|
4
|
-
class PackageDetail < Base
|
5
|
-
attr_accessor :ship_date
|
6
|
-
attr_accessor :reference
|
7
|
-
attr_accessor :tracking
|
8
|
-
attr_accessor :service
|
9
|
-
attr_accessor :declared
|
10
|
-
attr_accessor :cod
|
11
|
-
attr_accessor :cod_type
|
12
|
-
attr_accessor :saturday_delivery
|
13
|
-
attr_accessor :signature_rqd
|
14
|
-
attr_accessor :type
|
15
|
-
attr_accessor :weight
|
16
|
-
attr_accessor :bill_to
|
17
|
-
attr_accessor :instructions
|
18
|
-
attr_accessor :ship_email
|
19
|
-
attr_accessor :del_email
|
20
|
-
attr_accessor :label_type
|
21
|
-
attr_accessor :residential
|
22
|
-
|
23
|
-
def cod_type_to_xml_name
|
24
|
-
"cod_Type"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Ontrac
|
2
|
-
module WebServices
|
3
|
-
module Definitions
|
4
|
-
class ShipmentRequest < Base
|
5
|
-
attr_accessor :account
|
6
|
-
attr_accessor :password
|
7
|
-
attr_accessor :request_reference
|
8
|
-
attr_accessor :packages
|
9
|
-
|
10
|
-
def self.basename
|
11
|
-
"OntracShipmentRequest"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Ontrac
|
2
|
-
module WebServices
|
3
|
-
module Definitions
|
4
|
-
class ShipperData < Base
|
5
|
-
attr_accessor :name
|
6
|
-
attr_accessor :address
|
7
|
-
attr_accessor :suite
|
8
|
-
attr_accessor :city
|
9
|
-
attr_accessor :state
|
10
|
-
attr_accessor :zip
|
11
|
-
attr_accessor :phone
|
12
|
-
attr_accessor :contact
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|