shipping-calc 0.1.1 → 0.1.2
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/History.txt +5 -0
- data/README.txt +1 -1
- data/examples/dhl_example.rb +1 -1
- data/examples/fq_example.rb +2 -2
- data/lib/shipping_calc.rb +1 -1
- data/lib/shipping_calc/freight_quote.rb +29 -18
- data/test/freight_quote/freight_quote_test.rb +8 -0
- metadata +2 -2
data/History.txt
CHANGED
data/README.txt
CHANGED
data/examples/dhl_example.rb
CHANGED
@@ -26,7 +26,7 @@ opts = {
|
|
26
26
|
:date => Time.now,
|
27
27
|
:service_code => "E", # check the docs to find out what this means
|
28
28
|
:shipment_code => "P", # check the docs to find out what this means
|
29
|
-
:weight =>
|
29
|
+
:weight => 1, # weight in lbs
|
30
30
|
:to_zip => 10001,
|
31
31
|
:to_state => "NY"
|
32
32
|
}
|
data/examples/fq_example.rb
CHANGED
data/lib/shipping_calc.rb
CHANGED
@@ -32,7 +32,7 @@ require 'shipping_calc/freight_quote'
|
|
32
32
|
module ShippingCalc
|
33
33
|
class ShippingCalcError < StandardError
|
34
34
|
end
|
35
|
-
VERSION = "0.1.
|
35
|
+
VERSION = "0.1.2"
|
36
36
|
|
37
37
|
US_STATES = ['AK', 'AL', 'AR', 'AZ', 'CA', 'CO', 'CT', 'DC',
|
38
38
|
'DE', 'FL', 'GA', 'HI', 'IA', 'ID', 'IL', 'IN',
|
@@ -49,14 +49,18 @@ module ShippingCalc
|
|
49
49
|
# :*from_zip*:: Sender's zip code.
|
50
50
|
# :*to_zip*:: Recipient's zip code.
|
51
51
|
# :*weight*:: Total weight of the order in lbs.
|
52
|
-
# :*dimensions*:: Length, width and height of the shipment, described as a string: "[Length]x[Width]x[Height]" (e.g. "23x32x15").
|
52
|
+
# :*dimensions*:: Optional - Length, width and height of the shipment, described as a string: "[Length]x[Width]x[Height]" (e.g. "23x32x15").
|
53
53
|
# :*description*:: Optional - Description of the stuff that's being shipped. Defaults to "NODESC".
|
54
|
+
# :*class*:: Optional - Freight quote class. Defaults to nil.
|
55
|
+
#
|
56
|
+
# *Note* Both dimensions or class are optional but one of them has to be there. If both parameters are filled then priority will be give to class.
|
54
57
|
def quote(params)
|
55
58
|
required_fields = [:api_email, :api_password, :to_zip, :from_zip,
|
56
|
-
:weight
|
59
|
+
:weight]
|
57
60
|
|
58
61
|
raise ShippingCalcError.new("Nil parameters for FreightQuote quote.") if params.nil?
|
59
|
-
raise ShippingCalcError.new("Invalid shipment dimensions") unless
|
62
|
+
raise ShippingCalcError.new("Invalid shipment dimensions") unless
|
63
|
+
((params[:dimensions] =~ /\d+x\d+x\d+/) || (!params[:class].nil?))
|
60
64
|
|
61
65
|
required_fields.each do |f|
|
62
66
|
if params.has_key?(f) && !params[f].nil? # Cover all the mandatory fields
|
@@ -99,7 +103,8 @@ module ShippingCalc
|
|
99
103
|
dest << dest_zip
|
100
104
|
root << dest
|
101
105
|
|
102
|
-
root << shipment_item(params[:weight], params[:dimensions],
|
106
|
+
root << shipment_item(params[:weight], params[:dimensions],
|
107
|
+
params[:description], params[:class])
|
103
108
|
@xml << root
|
104
109
|
end
|
105
110
|
|
@@ -127,7 +132,7 @@ module ShippingCalc
|
|
127
132
|
end
|
128
133
|
|
129
134
|
# Create a shipment item based on the weight, dimension and description.
|
130
|
-
def shipment_item(weight_, dim, desc)
|
135
|
+
def shipment_item(weight_, dim, desc, s_class = nil)
|
131
136
|
raise ShippingCalcError.new("Invalid weight") if !(weight_ > 0)
|
132
137
|
shipment = Element.new("SHIPMENT")
|
133
138
|
weight = Element.new("WEIGHT")
|
@@ -138,19 +143,25 @@ module ShippingCalc
|
|
138
143
|
description.text = desc
|
139
144
|
shipment << description
|
140
145
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
146
|
+
if s_class.nil?
|
147
|
+
dimensions = Element.new("DIMENSIONS")
|
148
|
+
d = dim.split("x")
|
149
|
+
l = Element.new("LENGTH")
|
150
|
+
w = Element.new("WIDTH")
|
151
|
+
h = Element.new("HEIGHT")
|
152
|
+
l.text = d[0]
|
153
|
+
w.text = d[1]
|
154
|
+
h.text = d[2]
|
155
|
+
|
156
|
+
dimensions << l
|
157
|
+
dimensions << w
|
158
|
+
dimensions << h
|
159
|
+
shipment << dimensions
|
160
|
+
else
|
161
|
+
ship_class = Element.new("CLASS")
|
162
|
+
ship_class.text = s_class.to_s
|
163
|
+
shipment << ship_class
|
164
|
+
end
|
154
165
|
|
155
166
|
pieces = Element.new("PIECES")
|
156
167
|
pieces.text= "1"
|
@@ -24,6 +24,14 @@ class FreightQuoteTest < Test::Unit::TestCase
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
def test_quote_with_class
|
28
|
+
@opts[:class] = 92.5
|
29
|
+
@opts[:dimensions] = nil
|
30
|
+
f = FreightQuote.new
|
31
|
+
q = f.quote(@opts)
|
32
|
+
assert q.size > 0
|
33
|
+
end
|
34
|
+
|
27
35
|
def test_invalid_dimension
|
28
36
|
@opts[:dimensions] = "12x3"
|
29
37
|
f = FreightQuote.new
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shipping-calc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Federico Builes
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-03-
|
12
|
+
date: 2008-03-16 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|