active_shipping 0.12.4 → 0.12.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/lib/active_shipping.rb +2 -1
  3. data/lib/active_shipping/shipping/base.rb +2 -2
  4. data/lib/active_shipping/shipping/carrier.rb +16 -13
  5. data/lib/active_shipping/shipping/carriers/benchmark_carrier.rb +3 -4
  6. data/lib/active_shipping/shipping/carriers/bogus_carrier.rb +1 -3
  7. data/lib/active_shipping/shipping/carriers/canada_post.rb +33 -44
  8. data/lib/active_shipping/shipping/carriers/canada_post_pws.rb +72 -81
  9. data/lib/active_shipping/shipping/carriers/fedex.rb +118 -109
  10. data/lib/active_shipping/shipping/carriers/kunaki.rb +33 -32
  11. data/lib/active_shipping/shipping/carriers/new_zealand_post.rb +9 -16
  12. data/lib/active_shipping/shipping/carriers/shipwire.rb +36 -35
  13. data/lib/active_shipping/shipping/carriers/stamps.rb +39 -51
  14. data/lib/active_shipping/shipping/carriers/ups.rb +280 -116
  15. data/lib/active_shipping/shipping/carriers/ups.rb.orig +456 -0
  16. data/lib/active_shipping/shipping/carriers/usps.rb +145 -100
  17. data/lib/active_shipping/shipping/carriers/usps.rb.orig +616 -0
  18. data/lib/active_shipping/shipping/errors.rb +1 -1
  19. data/lib/active_shipping/shipping/label_response.rb +25 -0
  20. data/lib/active_shipping/shipping/location.rb +18 -16
  21. data/lib/active_shipping/shipping/package.rb +51 -54
  22. data/lib/active_shipping/shipping/rate_estimate.rb +10 -12
  23. data/lib/active_shipping/shipping/rate_response.rb +3 -7
  24. data/lib/active_shipping/shipping/response.rb +6 -9
  25. data/lib/active_shipping/shipping/shipment_event.rb +2 -4
  26. data/lib/active_shipping/shipping/shipment_packer.rb +32 -17
  27. data/lib/active_shipping/shipping/shipping_response.rb +2 -4
  28. data/lib/active_shipping/shipping/tracking_response.rb +3 -5
  29. data/lib/active_shipping/version.rb +1 -1
  30. data/lib/vendor/quantified/lib/quantified/attribute.rb +79 -80
  31. data/lib/vendor/quantified/lib/quantified/length.rb +5 -5
  32. data/lib/vendor/quantified/lib/quantified/mass.rb +4 -4
  33. data/lib/vendor/quantified/test/length_test.rb +19 -15
  34. data/lib/vendor/quantified/test/mass_test.rb +14 -14
  35. data/lib/vendor/quantified/test/test_helper.rb +1 -2
  36. data/lib/vendor/test_helper.rb +0 -1
  37. data/lib/vendor/xml_node/benchmark/bench_generation.rb +2 -4
  38. data/lib/vendor/xml_node/lib/xml_node.rb +54 -55
  39. data/lib/vendor/xml_node/test/test_generating.rb +23 -28
  40. data/lib/vendor/xml_node/test/test_parsing.rb +5 -8
  41. metadata +6 -25
  42. checksums.yaml.gz.sig +0 -1
  43. data.tar.gz.sig +0 -0
  44. metadata.gz.sig +0 -0
@@ -2,19 +2,19 @@ module Quantified
2
2
  class Length < Attribute
3
3
  system :metric do
4
4
  primitive :metre
5
-
5
+
6
6
  one :centimetre, :is => Length.new(0.01, :metres)
7
7
  one :millimetre, :is => Length.new(0.1, :centimetres)
8
8
  one :kilometre, :is => Length.new(1000, :metres)
9
9
  end
10
-
10
+
11
11
  system :imperial do
12
12
  primitive :inch
13
- one :inch, :is => Length.new(2.540, :centimetres)
14
-
13
+ one :inch, :is => Length.new(0.0254, :metres)
14
+
15
15
  one :foot, :plural => :feet, :is => Length.new(12, :inches)
16
16
  one :yard, :is => Length.new(3, :feet)
17
17
  one :mile, :is => Length.new(5280, :feet)
18
18
  end
19
19
  end
20
- end
20
+ end
@@ -2,18 +2,18 @@ module Quantified
2
2
  class Mass < Attribute
3
3
  system :metric do
4
4
  primitive :gram
5
-
5
+
6
6
  one :milligram, :is => Mass.new(0.001, :grams)
7
7
  one :kilogram, :is => Mass.new(1000, :grams)
8
8
  end
9
-
9
+
10
10
  system :imperial do
11
11
  primitive :ounce
12
12
  one :ounce, :is => Mass.new(28.349523125, :grams)
13
-
13
+
14
14
  one :pound, :is => Mass.new(16, :ounces)
15
15
  one :stone, :is => Mass.new(14, :pounds)
16
16
  one :short_ton, :is => Mass.new(2000, :pounds)
17
17
  end
18
18
  end
19
- end
19
+ end
@@ -4,7 +4,7 @@ require 'quantified/length'
4
4
  class LengthTest < Test::Unit::TestCase
5
5
  include Quantified
6
6
  Length.numeric_methods :metres, :centimetres, :inches, :feet
7
-
7
+
8
8
  def setup
9
9
  @length = Length.new(5, :feet)
10
10
  end
@@ -16,11 +16,11 @@ class LengthTest < Test::Unit::TestCase
16
16
  def test_to_s
17
17
  assert_equal "5 feet", @length.to_s
18
18
  end
19
-
19
+
20
20
  def test_initialize_from_numeric
21
21
  assert_equal "5 feet", 5.feet.to_s
22
22
  end
23
-
23
+
24
24
  def test_equalities
25
25
  assert_equal 1.feet, (1.0).feet
26
26
  # == based on value
@@ -30,46 +30,50 @@ class LengthTest < Test::Unit::TestCase
30
30
  # equal? based on object identity
31
31
  assert !2.feet.equal?(2.feet)
32
32
  end
33
-
33
+
34
+ def test_convert_mm_to_inches
35
+ assert_equal 12, Length.new(304.8, :millimetres).to_inches
36
+ end
37
+
34
38
  def test_convert_yards_to_feet
35
39
  assert 6.feet.eql?(Length.new(2, :yards).to_feet)
36
40
  end
37
-
41
+
38
42
  def test_convert_feet_to_yards
39
43
  assert Length.new(2, :yards).eql?(6.feet.to_yards)
40
44
  end
41
-
45
+
42
46
  def test_convert_yards_to_millimetres
43
47
  assert_in_epsilon Length.new(914.4, :millimetres).to_f, Length.new(1, :yards).to_millimetres.to_f
44
48
  end
45
-
49
+
46
50
  def test_convert_millimetres_to_yards
47
51
  assert_in_epsilon Length.new(1, :yards).to_f, Length.new(914.4, :millimetres).to_yards.to_f
48
52
  end
49
-
53
+
50
54
  def test_convert_metres_to_inches
51
55
  assert_in_epsilon 1.inches.to_f, (0.0254).metres.to_inches.to_f
52
56
  end
53
-
57
+
54
58
  def test_comparison_with_numeric
55
59
  assert 2.feet > 1
56
60
  assert 2.feet == 2
57
61
  assert 2.feet <= 2
58
62
  assert 2.feet < 3
59
63
  end
60
-
64
+
61
65
  def test_method_missing_to_i
62
66
  assert_equal 2, (2.4).feet.to_i
63
67
  end
64
-
68
+
65
69
  def test_method_missing_to_f
66
70
  assert_equal 2.4, (2.4).feet.to_f
67
71
  end
68
-
72
+
69
73
  def test_method_missing_minus
70
74
  assert_equal 2.feet, 5.feet - 3.feet
71
75
  end
72
-
76
+
73
77
  def test_numeric_methods_not_added_for_some_units
74
78
  assert_raises NoMethodError do
75
79
  2.yards
@@ -78,12 +82,12 @@ class LengthTest < Test::Unit::TestCase
78
82
  2.millimetres
79
83
  end
80
84
  end
81
-
85
+
82
86
  def test_systems
83
87
  assert_equal [:metric, :imperial], Length.systems
84
88
  assert_equal [:metres, :centimetres, :millimetres, :kilometres], Length.units(:metric)
85
89
  assert_equal [:inches, :feet, :yards, :miles], Length.units(:imperial)
86
-
90
+
87
91
  assert_equal :metric, 2.centimetres.system
88
92
  assert_equal :imperial, 2.feet.system
89
93
  end
@@ -4,7 +4,7 @@ require 'quantified/mass'
4
4
  class MassTest < Test::Unit::TestCase
5
5
  include Quantified
6
6
  Mass.numeric_methods :grams, :kilograms, :ounces, :pounds
7
-
7
+
8
8
  def setup
9
9
  @mass = Mass.new(5, :pounds)
10
10
  end
@@ -16,11 +16,11 @@ class MassTest < Test::Unit::TestCase
16
16
  def test_to_s
17
17
  assert_equal "5 pounds", @mass.to_s
18
18
  end
19
-
19
+
20
20
  def test_initialize_from_numeric
21
21
  assert_equal "5 pounds", 5.pounds.to_s
22
22
  end
23
-
23
+
24
24
  def test_equalities
25
25
  assert_equal 1.pounds, (1.0).pounds
26
26
  # == based on value
@@ -30,47 +30,47 @@ class MassTest < Test::Unit::TestCase
30
30
  # equal? based on object identity
31
31
  assert !2.pounds.equal?(2.pounds)
32
32
  end
33
-
33
+
34
34
  def test_convert_short_tons_to_pounds
35
35
  assert 4000.pounds.eql?(Mass.new(2, :short_tons).to_pounds)
36
36
  end
37
-
37
+
38
38
  def test_convert_pounds_to_short_tons
39
39
  assert Mass.new(2, :short_tons).eql?(4000.pounds.to_short_tons)
40
40
  end
41
-
41
+
42
42
  def test_convert_short_tons_to_milligrams
43
43
  assert Mass.new(907_184_740, :milligrams).eql?(Mass.new(1, :short_tons).to_milligrams)
44
44
  end
45
-
45
+
46
46
  def test_convert_milligrams_to_short_tons
47
47
  assert Mass.new(1, :short_tons).eql?(Mass.new(907_184_740, :milligrams).to_short_tons)
48
48
  end
49
-
49
+
50
50
  def test_convert_grams_to_ounces
51
51
  assert 1.ounces.eql?((28.349523125).grams.to_ounces)
52
52
  assert 1.ounces.eql?((28.349523125).grams.in_ounces)
53
53
  end
54
-
54
+
55
55
  def test_comparison_with_numeric
56
56
  assert 2.pounds > 1
57
57
  assert 2.pounds == 2
58
58
  assert 2.pounds <= 2
59
59
  assert 2.pounds < 3
60
60
  end
61
-
61
+
62
62
  def test_method_missing_to_i
63
63
  assert_equal 2, (2.4).pounds.to_i
64
64
  end
65
-
65
+
66
66
  def test_method_missing_to_f
67
67
  assert_equal 2.4, (2.4).pounds.to_f
68
68
  end
69
-
69
+
70
70
  def test_method_missing_minus
71
71
  assert_equal 2.pounds, 5.pounds - 3.pounds
72
72
  end
73
-
73
+
74
74
  def test_numeric_methods_not_added_for_some_units
75
75
  assert_raises NoMethodError do
76
76
  2.short_tons
@@ -79,7 +79,7 @@ class MassTest < Test::Unit::TestCase
79
79
  2.milligrams
80
80
  end
81
81
  end
82
-
82
+
83
83
  def test_systems
84
84
  assert_equal [:metric, :imperial], Mass.systems
85
85
  assert_equal [:grams, :milligrams, :kilograms], Mass.units(:metric)
@@ -2,7 +2,7 @@ require 'test/unit'
2
2
 
3
3
  begin
4
4
  require 'active_support/inflector'
5
- rescue LoadError => e
5
+ rescue LoadError
6
6
  require 'rubygems'
7
7
  gem "activesupport", ">= 2.3.5"
8
8
  require 'active_support/inflector'
@@ -10,7 +10,6 @@ end
10
10
 
11
11
  require File.dirname(__FILE__) + '/../lib/quantified'
12
12
 
13
-
14
13
  class Test::Unit::TestCase
15
14
  EPSILON = 0.00001
16
15
 
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  $:.unshift(File.dirname(__FILE__) + '/../lib')
3
3
 
4
-
5
4
  require 'test/unit'
6
5
  require 'active_shipping'
7
6
  require 'mocha'
@@ -2,14 +2,13 @@ require "benchmark"
2
2
  require File.dirname(__FILE__) + "/../lib/xml_node"
3
3
 
4
4
  class XmlNode
5
-
6
5
  def to_xml_as_array
7
6
  xml = []
8
7
  document = REXML::Document.new
9
8
  document << REXML::XMLDecl.new('1.0')
10
9
  document << @element
11
10
  document.write( xml, 0)
12
- xml.to_s
11
+ xml.to_s
13
12
  end
14
13
 
15
14
  def to_xml_no_format
@@ -18,9 +17,8 @@ class XmlNode
18
17
  document << REXML::XMLDecl.new('1.0')
19
18
  document << @element
20
19
  document.write( xml)
21
- xml
20
+ xml
22
21
  end
23
-
24
22
  end
25
23
 
26
24
  TESTS = 10000
@@ -16,29 +16,29 @@ class TrueClass
16
16
  def to_xml_value
17
17
  to_s
18
18
  end
19
- end
19
+ end
20
20
 
21
21
  class FalseClass
22
22
  def to_xml_value
23
23
  to_s
24
24
  end
25
- end
25
+ end
26
26
 
27
27
  class Time
28
28
  def to_xml_value
29
- self.xmlschema
29
+ xmlschema
30
30
  end
31
31
  end
32
32
 
33
33
  class DateTime
34
34
  def to_xml_value
35
- self.xmlschema
35
+ xmlschema
36
36
  end
37
37
  end
38
38
 
39
39
  class Date
40
40
  def to_xml_value
41
- self.to_time.xmlschema
41
+ to_time.xmlschema
42
42
  end
43
43
  end
44
44
 
@@ -50,11 +50,11 @@ end
50
50
 
51
51
  class XmlNode
52
52
  attr_accessor :child_nodes
53
- attr_reader :element
54
-
53
+ attr_reader :element
54
+
55
55
  class List
56
56
  include Enumerable
57
-
57
+
58
58
  def initialize(parent)
59
59
  @parent = parent
60
60
  @children = {}
@@ -63,151 +63,151 @@ class XmlNode
63
63
  def [](value)
64
64
  node_for @parent.element.elements[value]
65
65
  end
66
-
66
+
67
67
  def []=(value, key)
68
68
  @parent.element.elements[value.to_s] = key.to_xml_element
69
69
  end
70
-
70
+
71
71
  def each(&block)
72
72
  @parent.element.each_element { |e| yield node_for(e) }
73
73
  end
74
-
74
+
75
75
  private
76
-
76
+
77
77
  def node_for(element)
78
78
  @parent.child_nodes[element] ||= XmlNode.new(element)
79
79
  end
80
80
  end
81
-
81
+
82
82
  # Allows for very pretty xml generation akin to xml builder.
83
83
  #
84
84
  # Example:
85
- #
85
+ #
86
86
  # # Create an atom like document
87
- # doc = Document.new
87
+ # doc = Document.new
88
88
  # doc.root = XmlNode.new 'feed' do |feed|
89
- #
89
+ #
90
90
  # feed << XmlNode.new('id', 'tag:atom.com,2007:1')
91
91
  # feed << XmlNode.new('title', 'Atom test feed')
92
92
  # feed << XmlNode.new('author') do |author|
93
93
  # author << XmlNode.new("name", "tobi")
94
94
  # author << XmlNode.new("email", "tobi@gmail.com")
95
95
  # end
96
- #
96
+ #
97
97
  # feed << XmlNode.new('entry') do |entry|
98
98
  # entry << XmlNode.new('title', 'First post')
99
99
  # entry << XmlNode.new('summary', 'Lorem ipsum', :type => 'xhtml')
100
100
  # entry << XmlNode.new('created_at', Time.now)
101
101
  # end
102
- #
102
+ #
103
103
  # feed << XmlNode.new('dc:published', Time.now)
104
104
  # end
105
105
  #
106
106
  def initialize(node, *args)
107
107
  @element = if node.is_a?(REXML::Element)
108
108
  node
109
- else
110
- REXML::Element.new(node)
109
+ else
110
+ REXML::Element.new(node)
111
111
  end
112
-
112
+
113
113
  @child_nodes = {}
114
-
114
+
115
115
  if attributes = args.last.is_a?(Hash) ? args.pop : nil
116
- attributes.each { |k,v| @element.add_attribute(k.to_s, v.to_xml_value) }
116
+ attributes.each { |k, v| @element.add_attribute(k.to_s, v.to_xml_value) }
117
117
  end
118
-
119
- if !args[0].nil?
118
+
119
+ unless args[0].nil?
120
120
  @element.text = args[0].to_xml_value
121
121
  end
122
122
 
123
- if block_given?
124
- yield self
123
+ if block_given?
124
+ yield self
125
125
  end
126
126
  end
127
127
 
128
128
  def self.parse(xml)
129
- self.new(REXML::Document.new(xml).root)
129
+ new(REXML::Document.new(xml).root)
130
130
  end
131
-
131
+
132
132
  def children
133
133
  XmlNode::List.new(self)
134
134
  end
135
-
135
+
136
136
  def []=(key, value)
137
137
  @element.attributes[key.to_s] = value.to_xml_value
138
138
  end
139
-
139
+
140
140
  def [](key)
141
141
  @element.attributes[key]
142
142
  end
143
-
143
+
144
144
  # Add a namespace to the node
145
145
  # Example
146
146
  #
147
147
  # node.namespace 'http://www.w3.org/2005/Atom'
148
148
  # node.namespace :opensearch, 'http://a9.com/-/spec/opensearch/1.1/'
149
149
  #
150
- def namespace(*args)
150
+ def namespace(*args)
151
151
  args[0] = args[0].to_s if args[0].is_a?(Symbol)
152
152
  @element.add_namespace(*args)
153
153
  end
154
-
154
+
155
155
  def cdata=(value)
156
156
  new_cdata = REXML::CData.new( value )
157
157
  @element.children.each do |c|
158
158
  if c.is_a?(REXML::CData)
159
- return @element.replace_child(c,new_cdata)
159
+ return @element.replace_child(c, new_cdata)
160
160
  end
161
- end
161
+ end
162
162
  @element << new_cdata
163
- rescue RuntimeError => e
163
+ rescue RuntimeError => e
164
164
  @element << REXML::Text.new(e.message)
165
165
  end
166
-
166
+
167
167
  def cdata
168
168
  @element.cdatas.first.to_s
169
169
  end
170
-
170
+
171
171
  def name
172
172
  @element.name
173
173
  end
174
-
174
+
175
175
  def text=(value)
176
- @element.text = REXML::Text.new( value )
176
+ @element.text = REXML::Text.new( value )
177
177
  end
178
-
178
+
179
179
  def text
180
180
  @element.text
181
181
  end
182
-
183
- def find(scope, xpath)
184
- case scope
182
+
183
+ def find(scope, xpath)
184
+ case scope
185
185
  when :first
186
186
  elem = @element.elements[xpath]
187
187
  elem.nil? ? nil : child_nodes[elem] ||= XmlNode.new(elem)
188
- when :all
189
- @element.elements.to_a(xpath).collect { |e| child_nodes[e] ||= XmlNode.new(e) }
188
+ when :all
189
+ @element.elements.to_a(xpath).collect { |e| child_nodes[e] ||= XmlNode.new(e) }
190
190
  end
191
191
  end
192
-
193
- def <<(elem)
192
+
193
+ def <<(elem)
194
194
  case elem
195
195
  when nil then return
196
- when Array
196
+ when Array
197
197
  elem.each { |e| @element << e.to_xml_element }
198
198
  else
199
199
  @element << elem.to_xml_element
200
200
  end
201
201
  end
202
-
202
+
203
203
  def to_xml_element
204
204
  @element
205
205
  end
206
-
206
+
207
207
  def to_s
208
208
  @element.to_s
209
209
  end
210
-
210
+
211
211
  # Use to get pretty formatted xml including DECL
212
212
  # instructions
213
213
  def to_xml
@@ -218,5 +218,4 @@ class XmlNode
218
218
  document.write( xml, 0)
219
219
  xml.join
220
220
  end
221
-
222
- end
221
+ end