benhutton-active_shipping 0.9.13

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.
Files changed (54) hide show
  1. data/CHANGELOG +38 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.markdown +142 -0
  4. data/lib/active_merchant/common.rb +14 -0
  5. data/lib/active_merchant/common/connection.rb +177 -0
  6. data/lib/active_merchant/common/country.rb +328 -0
  7. data/lib/active_merchant/common/error.rb +26 -0
  8. data/lib/active_merchant/common/post_data.rb +24 -0
  9. data/lib/active_merchant/common/posts_data.rb +63 -0
  10. data/lib/active_merchant/common/requires_parameters.rb +16 -0
  11. data/lib/active_merchant/common/utils.rb +22 -0
  12. data/lib/active_merchant/common/validateable.rb +76 -0
  13. data/lib/active_shipping.rb +49 -0
  14. data/lib/active_shipping/shipping/base.rb +13 -0
  15. data/lib/active_shipping/shipping/carrier.rb +70 -0
  16. data/lib/active_shipping/shipping/carriers.rb +20 -0
  17. data/lib/active_shipping/shipping/carriers/bogus_carrier.rb +16 -0
  18. data/lib/active_shipping/shipping/carriers/canada_post.rb +268 -0
  19. data/lib/active_shipping/shipping/carriers/fedex.rb +331 -0
  20. data/lib/active_shipping/shipping/carriers/kunaki.rb +165 -0
  21. data/lib/active_shipping/shipping/carriers/new_zealand_post.rb +139 -0
  22. data/lib/active_shipping/shipping/carriers/shipwire.rb +172 -0
  23. data/lib/active_shipping/shipping/carriers/ups.rb +390 -0
  24. data/lib/active_shipping/shipping/carriers/usps.rb +441 -0
  25. data/lib/active_shipping/shipping/location.rb +109 -0
  26. data/lib/active_shipping/shipping/package.rb +147 -0
  27. data/lib/active_shipping/shipping/rate_estimate.rb +54 -0
  28. data/lib/active_shipping/shipping/rate_response.rb +19 -0
  29. data/lib/active_shipping/shipping/response.rb +46 -0
  30. data/lib/active_shipping/shipping/shipment_event.rb +14 -0
  31. data/lib/active_shipping/shipping/tracking_response.rb +22 -0
  32. data/lib/active_shipping/version.rb +3 -0
  33. data/lib/certs/cacert.pem +7815 -0
  34. data/lib/certs/eParcel.dtd +111 -0
  35. data/lib/vendor/quantified/MIT-LICENSE +22 -0
  36. data/lib/vendor/quantified/README.markdown +49 -0
  37. data/lib/vendor/quantified/Rakefile +21 -0
  38. data/lib/vendor/quantified/init.rb +0 -0
  39. data/lib/vendor/quantified/lib/quantified.rb +8 -0
  40. data/lib/vendor/quantified/lib/quantified/attribute.rb +208 -0
  41. data/lib/vendor/quantified/lib/quantified/length.rb +20 -0
  42. data/lib/vendor/quantified/lib/quantified/mass.rb +19 -0
  43. data/lib/vendor/quantified/test/length_test.rb +92 -0
  44. data/lib/vendor/quantified/test/mass_test.rb +88 -0
  45. data/lib/vendor/quantified/test/test_helper.rb +2 -0
  46. data/lib/vendor/test_helper.rb +13 -0
  47. data/lib/vendor/xml_node/README +36 -0
  48. data/lib/vendor/xml_node/Rakefile +21 -0
  49. data/lib/vendor/xml_node/benchmark/bench_generation.rb +32 -0
  50. data/lib/vendor/xml_node/init.rb +1 -0
  51. data/lib/vendor/xml_node/lib/xml_node.rb +222 -0
  52. data/lib/vendor/xml_node/test/test_generating.rb +94 -0
  53. data/lib/vendor/xml_node/test/test_parsing.rb +43 -0
  54. metadata +125 -0
@@ -0,0 +1,111 @@
1
+ <!-- EVERY REQUEST CONTAIN THE eparcel TAG -->
2
+ <!ELEMENT eparcel (language?,
3
+ ( ratesAndServicesRequest |
4
+ ratesAndServicesResponse |
5
+ error
6
+ )+)>
7
+
8
+ <!ELEMENT language (#PCDATA)>
9
+ <!ELEMENT comment (#PCDATA)>
10
+
11
+
12
+ <!-- Standard request to ask for rates and services -->
13
+ <!ELEMENT ratesAndServicesRequest ( merchantCPCID,
14
+ fromPostalCode?,
15
+ turnAroundTime?,
16
+ itemsPrice?,
17
+ lineItems,
18
+ city?,
19
+ provOrState,
20
+ country,
21
+ postalCode)>
22
+ <!ELEMENT merchantID (#PCDATA)>
23
+ <!ELEMENT fromPostalCode (#PCDATA)>
24
+ <!ELEMENT turnAroundTime (#PCDATA)>
25
+ <!ELEMENT itemsPrice (#PCDATA)>
26
+ <!ELEMENT merchantCPCID (#PCDATA)>
27
+ <!ELEMENT lineItems (item)+>
28
+ <!ELEMENT item (quantity, weight, length, width, height, description, imageURL?, readyToShip)>
29
+ <!ELEMENT quantity (#PCDATA)>
30
+ <!ELEMENT weight (#PCDATA)>
31
+ <!ELEMENT length (#PCDATA)>
32
+ <!ELEMENT width (#PCDATA)>
33
+ <!ELEMENT height (#PCDATA)>
34
+ <!ELEMENT description (#PCDATA)>
35
+ <!ELEMENT imageURL (#PCDATA)>
36
+ <!ELEMENT readyToShip (#PCDATA)>
37
+ <!ELEMENT city (#PCDATA)>
38
+ <!ELEMENT provOrState (#PCDATA)>
39
+ <!ELEMENT country (#PCDATA)>
40
+ <!ELEMENT postalCode (#PCDATA)>
41
+
42
+ <!-- Standard response for request for rates and services -->
43
+ <!ELEMENT ratesAndServicesResponse (statusCode,
44
+ statusMessage+,
45
+ requestID,
46
+ handling,
47
+ language,
48
+ product+,
49
+ packing*,
50
+ emptySpace*,
51
+ shippingOptions,
52
+ comment,
53
+ nearestPostalOutlet*)>
54
+
55
+ <!ELEMENT statusCode (#PCDATA)>
56
+ <!ELEMENT statusMessage (#PCDATA)>
57
+ <!ELEMENT requestID (#PCDATA)>
58
+ <!ELEMENT handling (#PCDATA)>
59
+
60
+ <!ELEMENT product (name, rate, shippingDate, deliveryDate, deliveryDayOfWeek, nextDayAM?, packingID)>
61
+ <!ATTLIST product id CDATA #REQUIRED>
62
+ <!ATTLIST product sequence CDATA #REQUIRED>
63
+ <!ELEMENT name (#PCDATA)>
64
+ <!ELEMENT rate (#PCDATA)>
65
+ <!ELEMENT shippingDate (#PCDATA)>
66
+ <!ELEMENT deliveryDate (#PCDATA)>
67
+ <!ELEMENT deliveryDayOfWeek (#PCDATA)>
68
+ <!ELEMENT nextDayAM (#PCDATA)>
69
+ <!ELEMENT packingID (#PCDATA)>
70
+
71
+ <!ELEMENT packing (packingID, box+)>
72
+ <!ELEMENT box (name, weight, expediterWeight, length, width, height, packedItem+)>
73
+ <!ELEMENT expediterWeight (#PCDATA)>
74
+ <!ELEMENT packedItem (quantity, description)>
75
+
76
+ <!ELEMENT emptySpace (length, width, height, weight)>
77
+
78
+ <!ELEMENT shippingOptions (insurance, deliveryConfirmation, signature)>
79
+ <!ELEMENT insurance (#PCDATA)>
80
+ <!ELEMENT deliveryConfirmation (#PCDATA)>
81
+ <!ELEMENT signature (#PCDATA)>
82
+
83
+
84
+ <!-- ********************************************************* -->
85
+ <!-- * 'nearestPostalOutlet' is optional and is returned * -->
86
+ <!-- * only if the merchant profile has this option enabled * -->
87
+ <!-- ********************************************************* -->
88
+ <!ELEMENT nearestPostalOutlet (postalOutletSequenceNo,
89
+ distance,
90
+ outletName,
91
+ businessName ,
92
+ postalAddress,
93
+ phoneNumber,
94
+ businessHours+)>
95
+ <!ELEMENT postalOutletSequenceNo (#PCDATA)>
96
+ <!ELEMENT distance (#PCDATA)>
97
+ <!ELEMENT outletName (#PCDATA)>
98
+ <!ELEMENT businessName (#PCDATA)>
99
+ <!ELEMENT postalAddress (addressLine+, postalCode , municipality)>
100
+ <!ELEMENT addressLine (#PCDATA)>
101
+ <!ELEMENT municipality (#PCDATA)>
102
+ <!ELEMENT phoneNumber (#PCDATA)>
103
+ <!ELEMENT businessHours (dayId, dayOfWeek, time)>
104
+ <!ELEMENT dayId (#PCDATA)>
105
+ <!ELEMENT dayOfWeek (#PCDATA)>
106
+ <!ELEMENT time (#PCDATA)>
107
+
108
+
109
+ <!-- Standard error format returned -->
110
+ <!ELEMENT error (statusCode,statusMessage*)>
111
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2009 James MacAulay
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ Quantified
2
+ ==========
3
+
4
+ Pretty quantifiable measurements which feel like ActiveSupport::Duration.
5
+
6
+ Access whichever included attributes you want like so:
7
+
8
+ require 'quantified/mass'
9
+ require 'quantified/length'
10
+
11
+ Add methods to Numeric (only plural, must correspond with plural unit names):
12
+
13
+ Mass.numeric_methods :grams, :kilograms, :ounces, :pounds
14
+ Length.numeric_methods :metres, :centimetres, :inches, :feet
15
+
16
+ Then you can do things like this:
17
+
18
+ 1.feet == 12.inches
19
+ # => true
20
+
21
+ 18.inches.to_feet
22
+ # => #<Quantified::Length: 1.5 feet>
23
+
24
+ (2.5).feet.in_millimetres.to_s
25
+ # => "762.0 millimetres"
26
+
27
+
28
+ You can easily define new attributes. Here's length.rb:
29
+
30
+ module Quantified
31
+ class Length < Attribute
32
+ system :metric do
33
+ primitive :metre
34
+
35
+ one :centimetre, :is => Length.new(0.01, :metres)
36
+ one :millimetre, :is => Length.new(0.1, :centimetres)
37
+ one :kilometre, :is => Length.new(1000, :metres)
38
+ end
39
+
40
+ system :imperial do
41
+ primitive :inch
42
+ one :inch, :is => Length.new(2.540, :centimetres)
43
+
44
+ one :foot, :plural => :feet, :is => Length.new(12, :inches)
45
+ one :yard, :is => Length.new(3, :feet)
46
+ one :mile, :is => Length.new(5280, :feet)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,21 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.pattern = 'test/**/*_test.rb'
12
+ t.verbose = true
13
+ end
14
+
15
+ desc 'Generate documentation for the calculations plugin.'
16
+ Rake::RDocTask.new(:rdoc) do |rdoc|
17
+ rdoc.rdoc_dir = 'rdoc'
18
+ rdoc.title = 'Quantified'
19
+ rdoc.options << '--line-numbers --inline-source'
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
File without changes
@@ -0,0 +1,8 @@
1
+ $: << File.dirname(__FILE__)
2
+
3
+ require 'active_support/all'
4
+ require 'bigdecimal'
5
+
6
+ require 'quantified/attribute'
7
+ require 'quantified/mass'
8
+ require 'quantified/length'
@@ -0,0 +1,208 @@
1
+ module Quantified
2
+ class Attribute
3
+ include Comparable
4
+
5
+ attr_reader :amount, :unit
6
+
7
+ def initialize(amount, unit)
8
+ raise ArgumentError, "amount must be a Numeric" unless amount.is_a?(Numeric)
9
+ @amount, @unit = amount, unit.to_sym
10
+ end
11
+
12
+ def to_s
13
+ "#{amount} #{unit}"
14
+ end
15
+
16
+ def inspect
17
+ "#<#{self.class.name}: #{amount} #{unit}>"
18
+ end
19
+
20
+ def ==(other)
21
+ (BigDecimal.new(self.amount.to_s) == BigDecimal.new(other.amount.to_s) && self.unit == other.unit) || BigDecimal.new(self.class.convert(self.amount, self.unit, other.unit).to_s) == BigDecimal.new(other.amount.to_s)
22
+ rescue NoMethodError
23
+ self.amount == other
24
+ end
25
+
26
+ def eql?(other)
27
+ self.class == other.class && BigDecimal.new(self.amount.to_s) == BigDecimal.new(other.amount.to_s) && self.unit == other.unit
28
+ end
29
+
30
+ def <=>(other)
31
+ if self.class == other.class
32
+ self.class.convert(self.amount, self.unit, other.unit) <=> other.amount
33
+ else
34
+ self.amount <=> other
35
+ end
36
+ end
37
+
38
+ def system
39
+ self.class.units_to_systems[unit]
40
+ end
41
+
42
+ def method_missing(meth, *args)
43
+ if args.size == 1 && self.class == (other = args.first).class
44
+ other_amount_in_self_units = self.class.convert(other.amount, other.unit, self.unit)
45
+ self.class.new(amount.send(meth, other_amount_in_self_units), self.unit)
46
+ else
47
+ amount.send(meth, *args)
48
+ end
49
+ end
50
+
51
+ def self.conversion_rate(from, to)
52
+ return nil unless self.conversions[from] and self.conversions[to]
53
+ return self.conversions[from][to] ||=
54
+ (1.0 / self.conversions[to][from] if self.conversions[to][from]) || begin
55
+ shared_conversions = self.conversions[from].keys & self.conversions[to].keys
56
+ if shared_conversions.any?
57
+ primitive = shared_conversions.first
58
+ self.conversions[from][primitive] * (1.0 / self.conversions[to][primitive])
59
+ else
60
+ self.conversions[from].each do |conversion_unit, multiple|
61
+ if self.conversions[to].include?(conversion_unit)
62
+ return multiple * conversion_rate(conversion) * (1.0 / self.conversions[to][conversion_unit])
63
+ end
64
+ end
65
+ from_primitive = (self.conversions[from].keys & self.primitives).first
66
+ to_primitive = (self.conversions[to].keys & self.primitives).first
67
+ if from_primitive_to_primitive_multiple = conversion_rate(from_primitive, to_primitive)
68
+ return self.conversions[from][from_primitive] * from_primitive_to_primitive_multiple * (1.0 / self.conversions[to][to_primitive])
69
+ end
70
+ raise StandardError, "No conversion path from #{from} to #{to}"
71
+ end
72
+ end
73
+ end
74
+
75
+ def self.units(system=nil)
76
+ if system
77
+ self.systems_to_units[system.to_sym].dup
78
+ else
79
+ read_inheritable_attribute(:primitives) | self.conversions.keys
80
+ end
81
+ end
82
+
83
+ def self.primitives
84
+ read_inheritable_attribute(:primitives).dup
85
+ end
86
+
87
+ def self.non_primitives
88
+ self.conversions.keys
89
+ end
90
+
91
+ def self.systems
92
+ self.systems_to_units.keys
93
+ end
94
+
95
+ def self.add_numeric_methods?
96
+ self.add_numeric_methods
97
+ end
98
+
99
+ def self.numeric_methods(*args)
100
+ args.each do |arg|
101
+ add_numeric_method_for(arg.to_sym)
102
+ end
103
+ end
104
+
105
+ protected
106
+
107
+ class_inheritable_accessor :add_numeric_methods, :primitives, :conversions, :current_system, :systems_to_units, :units_to_systems
108
+ self.add_numeric_methods = false
109
+ self.primitives = []
110
+ self.conversions = {}
111
+ self.current_system = nil
112
+ self.systems_to_units = {}
113
+ self.units_to_systems = {}
114
+
115
+ def self.system(system_name, &block)
116
+ old_system = self.current_system
117
+ self.current_system = system_name.to_sym
118
+ yield
119
+ self.current_system = old_system
120
+ end
121
+
122
+ def self.primitive(sym, options={})
123
+ unit_sym = (options[:plural] || sym.to_s.pluralize).to_sym
124
+ self.primitives << unit_sym
125
+ add_to_system(unit_sym)
126
+ add_methods_for(unit_sym, options)
127
+ end
128
+
129
+ def self.add_to_system(unit_sym)
130
+ if self.current_system
131
+ self.units_to_systems[unit_sym] ||= begin
132
+ sys_ary = self.systems_to_units[self.current_system] ||= []
133
+ sys_ary << unit_sym
134
+ self.current_system
135
+ end
136
+ end
137
+ end
138
+
139
+ def self.one(sym, options={})
140
+ unit_sym = (options[:plural] || sym.to_s.pluralize).to_sym
141
+ add_to_system(unit_sym)
142
+ register_unit(unit_sym, options[:is].unit, options[:is].amount)
143
+ add_methods_for(unit_sym, options)
144
+ end
145
+
146
+ def self.register_unit(multiple_unit, other_unit, multiple)
147
+ multiple_unit, other_unit = multiple_unit.to_sym, other_unit.to_sym
148
+ self.conversions[multiple_unit] ||= {}
149
+ self.conversions[other_unit] ||= {}
150
+
151
+ if self.primitives.include?(multiple_unit) || self.primitives.include?(other_unit)
152
+ add_conversion(multiple_unit, other_unit, multiple)
153
+ else
154
+ [multiple_unit, other_unit].each do |this_unit|
155
+ self.conversions[this_unit].each do |this_other_unit, this_multiple|
156
+ if self.primitives.include?(this_other_unit)
157
+ add_conversion(multiple_unit, this_other_unit, multiple * this_multiple)
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
163
+
164
+ def self.add_conversion(multiple_unit, other_unit, multiple)
165
+ self.conversions[multiple_unit] ||={}
166
+ self.conversions[multiple_unit][other_unit] = multiple
167
+ self.conversions[other_unit] ||= {}
168
+ self.conversions[other_unit][multiple_unit] = (1.0 / multiple)
169
+ end
170
+
171
+ def self.convert(amount, from, to)
172
+ from, to = from.to_sym, to.to_sym
173
+ amount * conversion_rate(from, to)
174
+ end
175
+
176
+ def self.add_methods_for(sym, options={})
177
+ add_conversion_method_for(sym, options)
178
+ add_numeric_method = if options.has_key?(:add_numeric_methods)
179
+ options[:add_numeric_methods]
180
+ else
181
+ self.add_numeric_methods
182
+ end
183
+ add_numeric_method_for(sym.to_s, options) if add_numeric_method
184
+ end
185
+
186
+ def self.add_conversion_method_for(sym, options={})
187
+ unit_name = sym.to_s
188
+ class_eval do
189
+ define_method("to_#{unit_name}") do
190
+ return self if unit_name == self.unit.to_s
191
+ self.class.new(self.class.convert(self.amount, self.unit, unit_name), unit_name)
192
+ end
193
+ alias_method("in_#{unit_name}","to_#{unit_name}")
194
+ end
195
+ end
196
+
197
+ def self.add_numeric_method_for(unit_name, options={})
198
+ unit_name = unit_name.to_sym
199
+ raise ArgumentError, "#{unit_name.inspect} is not a unit in #{self.name}" unless units.include?(unit_name)
200
+ klass = self
201
+ Numeric.class_eval do
202
+ define_method(unit_name) do
203
+ klass.new(self, unit_name.to_sym)
204
+ end
205
+ end
206
+ end
207
+ end
208
+ end
@@ -0,0 +1,20 @@
1
+ module Quantified
2
+ class Length < Attribute
3
+ system :metric do
4
+ primitive :metre
5
+
6
+ one :centimetre, :is => Length.new(0.01, :metres)
7
+ one :millimetre, :is => Length.new(0.1, :centimetres)
8
+ one :kilometre, :is => Length.new(1000, :metres)
9
+ end
10
+
11
+ system :imperial do
12
+ primitive :inch
13
+ one :inch, :is => Length.new(2.540, :centimetres)
14
+
15
+ one :foot, :plural => :feet, :is => Length.new(12, :inches)
16
+ one :yard, :is => Length.new(3, :feet)
17
+ one :mile, :is => Length.new(5280, :feet)
18
+ end
19
+ end
20
+ end