shipping-calc 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.1.2
2
+
3
+ * Freight quote now supports FQ's classes. With this the shipment's
4
+ dimensions are optional
5
+
1
6
  === 0.1.1
2
7
  * Usage examples for DHL and FreightQuote in the /examples directory.
3
8
 
data/README.txt CHANGED
@@ -47,7 +47,7 @@ A simple DHL example:
47
47
 
48
48
  == INSTALL:
49
49
 
50
- * sudo gem install shipping_calc
50
+ * sudo gem install shipping-calc
51
51
 
52
52
  == TEST
53
53
 
@@ -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 => 34, # weight in lbs
29
+ :weight => 1, # weight in lbs
30
30
  :to_zip => 10001,
31
31
  :to_state => "NY"
32
32
  }
@@ -8,8 +8,8 @@ opts = {
8
8
  :api_password => "XML",
9
9
  :from_zip => 75042,
10
10
  :to_zip => 33166,
11
- :weight => 150,
12
- :dimensions => "12x23x12"
11
+ :weight => 5,
12
+ :dimensions => "1x1x1"
13
13
  }
14
14
 
15
15
  f = FreightQuote.new
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.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, :dimensions]
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 (params[:dimensions] =~ /\d+x\d+x\d+/)
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], params[:description])
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
- dimensions = Element.new("DIMENSIONS")
142
- d = dim.split("x")
143
- l = Element.new("LENGTH")
144
- w = Element.new("WIDTH")
145
- h = Element.new("HEIGHT")
146
- l.text = d[0]
147
- w.text = d[1]
148
- h.text = d[2]
149
-
150
- dimensions << l
151
- dimensions << w
152
- dimensions << h
153
- shipment << dimensions
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.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-15 00:00:00 -05:00
12
+ date: 2008-03-16 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency