active_shipping 0.9.15 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +1 -1
- data/lib/active_shipping.rb +1 -0
- data/lib/active_shipping/shipping/carriers.rb +2 -1
- data/lib/active_shipping/shipping/carriers/canada_post.rb +5 -4
- data/lib/active_shipping/shipping/carriers/canada_post_pws.rb +837 -0
- data/lib/active_shipping/shipping/carriers/fedex.rb +33 -19
- data/lib/active_shipping/shipping/carriers/ups.rb +72 -69
- data/lib/active_shipping/shipping/carriers/ups.rb.orig +456 -0
- data/lib/active_shipping/shipping/carriers/usps.rb +185 -9
- data/lib/active_shipping/shipping/carriers/usps.rb.orig +616 -0
- data/lib/active_shipping/shipping/package.rb +109 -10
- data/lib/active_shipping/shipping/rate_estimate.rb +10 -6
- data/lib/active_shipping/shipping/shipping_response.rb +16 -0
- data/lib/active_shipping/shipping/tracking_response.rb +3 -1
- data/lib/active_shipping/version.rb +1 -1
- metadata +23 -3
@@ -1,5 +1,80 @@
|
|
1
1
|
module ActiveMerchant #:nodoc:
|
2
2
|
module Shipping #:nodoc:
|
3
|
+
# A package item is a unique item(s) that is physically in a package.
|
4
|
+
# A single package can have many items. This is only required
|
5
|
+
# for shipping methods (label creation) right now.
|
6
|
+
class PackageItem
|
7
|
+
include Quantified
|
8
|
+
|
9
|
+
attr_reader :sku, :hs_code, :value, :name, :weight, :quantity, :options
|
10
|
+
|
11
|
+
def initialize(name, grams_or_ounces, value, quantity, options = {})
|
12
|
+
@name = name
|
13
|
+
|
14
|
+
imperial = (options[:units] == :imperial) ||
|
15
|
+
(grams_or_ounces.respond_to?(:unit) && m.unit.to_sym == :imperial)
|
16
|
+
|
17
|
+
@unit_system = imperial ? :imperial : :metric
|
18
|
+
|
19
|
+
@weight = attribute_from_metric_or_imperial(grams_or_ounces, Mass, :grams, :ounces)
|
20
|
+
|
21
|
+
@value = Package.cents_from(value)
|
22
|
+
@quantity = quantity > 0 ? quantity : 1
|
23
|
+
|
24
|
+
@sku = options[:sku]
|
25
|
+
@hs_code = options[:hs_code]
|
26
|
+
@options = options
|
27
|
+
end
|
28
|
+
|
29
|
+
def weight(options = {})
|
30
|
+
case options[:type]
|
31
|
+
when nil, :actual
|
32
|
+
@weight
|
33
|
+
when :volumetric, :dimensional
|
34
|
+
@volumetric_weight ||= begin
|
35
|
+
m = Mass.new((centimetres(:box_volume) / 6.0), :grams)
|
36
|
+
@unit_system == :imperial ? m.in_ounces : m
|
37
|
+
end
|
38
|
+
when :billable
|
39
|
+
[ weight, weight(:type => :volumetric) ].max
|
40
|
+
end
|
41
|
+
end
|
42
|
+
alias_method :mass, :weight
|
43
|
+
|
44
|
+
def ounces(options={})
|
45
|
+
weight(options).in_ounces.amount
|
46
|
+
end
|
47
|
+
alias_method :oz, :ounces
|
48
|
+
|
49
|
+
def grams(options={})
|
50
|
+
weight(options).in_grams.amount
|
51
|
+
end
|
52
|
+
alias_method :g, :grams
|
53
|
+
|
54
|
+
def pounds(options={})
|
55
|
+
weight(options).in_pounds.amount
|
56
|
+
end
|
57
|
+
alias_method :lb, :pounds
|
58
|
+
alias_method :lbs, :pounds
|
59
|
+
|
60
|
+
def kilograms(options={})
|
61
|
+
weight(options).in_kilograms.amount
|
62
|
+
end
|
63
|
+
alias_method :kg, :kilograms
|
64
|
+
alias_method :kgs, :kilograms
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def attribute_from_metric_or_imperial(obj, klass, metric_unit, imperial_unit)
|
69
|
+
if obj.is_a?(klass)
|
70
|
+
return value
|
71
|
+
else
|
72
|
+
return klass.new(obj, (@unit_system == :imperial ? imperial_unit : metric_unit))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
3
78
|
class Package
|
4
79
|
include Quantified
|
5
80
|
|
@@ -15,16 +90,30 @@ module ActiveMerchant #:nodoc:
|
|
15
90
|
@options = options
|
16
91
|
|
17
92
|
@dimensions = [dimensions].flatten.reject {|d| d.nil?}
|
93
|
+
|
18
94
|
|
19
95
|
imperial = (options[:units] == :imperial) ||
|
20
|
-
|
96
|
+
([grams_or_ounces, *dimensions].all? {|m| m.respond_to?(:unit) && m.unit.to_sym == :imperial})
|
21
97
|
|
22
|
-
|
98
|
+
weight_imperial = dimensions_imperial = imperial if options.include?(:units)
|
99
|
+
|
100
|
+
if options.include?(:weight_units)
|
101
|
+
weight_imperial = (options[:weight_units] == :imperial) ||
|
102
|
+
(grams_or_ounces.respond_to?(:unit) && m.unit.to_sym == :imperial)
|
103
|
+
end
|
104
|
+
|
105
|
+
if options.include?(:dim_units)
|
106
|
+
dimensions_imperial = (options[:dim_units] == :imperial) ||
|
107
|
+
(dimensions && dimensions.all? {|m| m.respond_to?(:unit) && m.unit.to_sym == :imperial})
|
108
|
+
end
|
23
109
|
|
24
|
-
@
|
110
|
+
@weight_unit_system = weight_imperial ? :imperial : :metric
|
111
|
+
@dimensions_unit_system = dimensions_imperial ? :imperial : :metric
|
112
|
+
|
113
|
+
@weight = attribute_from_metric_or_imperial(grams_or_ounces, Mass, @weight_unit_system, :grams, :ounces)
|
25
114
|
|
26
115
|
if @dimensions.blank?
|
27
|
-
@dimensions = [Length.new(0, (
|
116
|
+
@dimensions = [Length.new(0, (dimensions_imperial ? :inches : :centimetres))] * 3
|
28
117
|
else
|
29
118
|
process_dimensions
|
30
119
|
end
|
@@ -33,8 +122,18 @@ module ActiveMerchant #:nodoc:
|
|
33
122
|
@currency = options[:currency] || (options[:value].currency if options[:value].respond_to?(:currency))
|
34
123
|
@cylinder = (options[:cylinder] || options[:tube]) ? true : false
|
35
124
|
@gift = options[:gift] ? true : false
|
125
|
+
@oversized = options[:oversized] ? true : false
|
126
|
+
@unpackaged = options[:unpackaged] ? true : false
|
36
127
|
end
|
37
128
|
|
129
|
+
def unpackaged?
|
130
|
+
@unpackaged
|
131
|
+
end
|
132
|
+
|
133
|
+
def oversized?
|
134
|
+
@oversized
|
135
|
+
end
|
136
|
+
|
38
137
|
def cylinder?
|
39
138
|
@cylinder
|
40
139
|
end
|
@@ -83,7 +182,7 @@ module ActiveMerchant #:nodoc:
|
|
83
182
|
when :volumetric, :dimensional
|
84
183
|
@volumetric_weight ||= begin
|
85
184
|
m = Mass.new((centimetres(:box_volume) / 6.0), :grams)
|
86
|
-
@
|
185
|
+
@weight_unit_system == :imperial ? m.in_ounces : m
|
87
186
|
end
|
88
187
|
when :billable
|
89
188
|
[ weight, weight(:type => :volumetric) ].max
|
@@ -108,12 +207,12 @@ module ActiveMerchant #:nodoc:
|
|
108
207
|
end
|
109
208
|
|
110
209
|
private
|
111
|
-
|
112
|
-
def attribute_from_metric_or_imperial(obj, klass, metric_unit, imperial_unit)
|
210
|
+
|
211
|
+
def attribute_from_metric_or_imperial(obj, klass, unit_system, metric_unit, imperial_unit)
|
113
212
|
if obj.is_a?(klass)
|
114
|
-
return
|
213
|
+
return obj
|
115
214
|
else
|
116
|
-
return klass.new(obj, (
|
215
|
+
return klass.new(obj, (unit_system == :imperial ? imperial_unit : metric_unit))
|
117
216
|
end
|
118
217
|
end
|
119
218
|
|
@@ -132,7 +231,7 @@ module ActiveMerchant #:nodoc:
|
|
132
231
|
|
133
232
|
def process_dimensions
|
134
233
|
@dimensions = @dimensions.map do |l|
|
135
|
-
attribute_from_metric_or_imperial(l, Length, :centimetres, :inches)
|
234
|
+
attribute_from_metric_or_imperial(l, Length, @dimensions_unit_system, :centimetres, :inches)
|
136
235
|
end.sort
|
137
236
|
# [1,2] => [1,1,2]
|
138
237
|
# [5] => [5,5,5]
|
@@ -1,18 +1,20 @@
|
|
1
1
|
module ActiveMerchant #:nodoc:
|
2
2
|
module Shipping #:nodoc:
|
3
|
-
|
3
|
+
|
4
4
|
class RateEstimate
|
5
5
|
attr_reader :origin # Location objects
|
6
|
-
attr_reader :destination
|
6
|
+
attr_reader :destination
|
7
7
|
attr_reader :package_rates # array of hashes in the form of {:package => <Package>, :rate => 500}
|
8
8
|
attr_reader :carrier # Carrier.name ('USPS', 'FedEx', etc.)
|
9
9
|
attr_reader :service_name # name of service ("First Class Ground", etc.)
|
10
10
|
attr_reader :service_code
|
11
11
|
attr_reader :currency # 'USD', 'CAD', etc.
|
12
12
|
# http://en.wikipedia.org/wiki/ISO_4217
|
13
|
+
attr_reader :shipping_date
|
13
14
|
attr_reader :delivery_date # Usually only available for express shipments
|
14
15
|
attr_reader :delivery_range # Min and max delivery estimate in days
|
15
|
-
|
16
|
+
attr_reader :negotiated_rate
|
17
|
+
|
16
18
|
def initialize(origin, destination, carrier, service_name, options={})
|
17
19
|
@origin, @destination, @carrier, @service_name = origin, destination, carrier, service_name
|
18
20
|
@service_code = options[:service_code]
|
@@ -22,8 +24,10 @@ module ActiveMerchant #:nodoc:
|
|
22
24
|
@package_rates = Array(options[:packages]).map {|p| {:package => p}}
|
23
25
|
end
|
24
26
|
@total_price = Package.cents_from(options[:total_price])
|
27
|
+
@negotiated_rate = options[:negotiated_rate] ? Package.cents_from(options[:negotiated_rate]) : nil
|
25
28
|
@currency = options[:currency]
|
26
29
|
@delivery_range = options[:delivery_range] ? options[:delivery_range].map { |date| date_for(date) }.compact : []
|
30
|
+
@shipping_date = date_for(options[:shipping_date])
|
27
31
|
@delivery_date = @delivery_range.last
|
28
32
|
end
|
29
33
|
|
@@ -35,18 +39,18 @@ module ActiveMerchant #:nodoc:
|
|
35
39
|
end
|
36
40
|
end
|
37
41
|
alias_method :price, :total_price
|
38
|
-
|
42
|
+
|
39
43
|
def add(package,rate=nil)
|
40
44
|
cents = Package.cents_from(rate)
|
41
45
|
raise ArgumentError.new("New packages must have valid rate information since this RateEstimate has no total_price set.") if cents.nil? and total_price.nil?
|
42
46
|
@package_rates << {:package => package, :rate => cents}
|
43
47
|
self
|
44
48
|
end
|
45
|
-
|
49
|
+
|
46
50
|
def packages
|
47
51
|
package_rates.map {|p| p[:package]}
|
48
52
|
end
|
49
|
-
|
53
|
+
|
50
54
|
def package_count
|
51
55
|
package_rates.length
|
52
56
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Shipping
|
3
|
+
|
4
|
+
class ShippingResponse < Response
|
5
|
+
attr_reader :shipping_id # string
|
6
|
+
attr_reader :tracking_number # string
|
7
|
+
|
8
|
+
def initialize(success, message, params = {}, options = {})
|
9
|
+
@shipping_id = options[:shipping_id]
|
10
|
+
@tracking_number = options[:tracking_number]
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -8,6 +8,7 @@ module ActiveMerchant #:nodoc:
|
|
8
8
|
attr_reader :status_code # string
|
9
9
|
attr_reader :status_description #string
|
10
10
|
attr_reader :scheduled_delivery_date # time
|
11
|
+
attr_reader :delivery_signature #string
|
11
12
|
attr_reader :tracking_number # string
|
12
13
|
attr_reader :shipment_events # array of ShipmentEvents in chronological order
|
13
14
|
attr_reader :origin, :destination
|
@@ -19,6 +20,7 @@ module ActiveMerchant #:nodoc:
|
|
19
20
|
@status_code = options[:status_code]
|
20
21
|
@status_description = options[:status_description]
|
21
22
|
@scheduled_delivery_date = options[:scheduled_delivery_date]
|
23
|
+
@delivery_signature = options[:delivery_signature]
|
22
24
|
@tracking_number = options[:tracking_number]
|
23
25
|
@shipment_events = Array(options[:shipment_events])
|
24
26
|
@origin, @destination = options[:origin], options[:destination]
|
@@ -44,4 +46,4 @@ module ActiveMerchant #:nodoc:
|
|
44
46
|
end
|
45
47
|
|
46
48
|
end
|
47
|
-
end
|
49
|
+
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: active_shipping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.10.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- James MacAulay
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2013-
|
15
|
+
date: 2013-07-23 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
prerelease: false
|
@@ -142,6 +142,22 @@ dependencies:
|
|
142
142
|
- !ruby/object:Gem::Version
|
143
143
|
version: '0'
|
144
144
|
none: false
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
prerelease: false
|
147
|
+
name: nokogiri
|
148
|
+
type: :development
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
none: false
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ! '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
none: false
|
145
161
|
description: Get rates and tracking info from various shipping carriers.
|
146
162
|
email:
|
147
163
|
- james@shopify.com
|
@@ -153,12 +169,15 @@ files:
|
|
153
169
|
- lib/active_shipping/shipping/carrier.rb
|
154
170
|
- lib/active_shipping/shipping/carriers/bogus_carrier.rb
|
155
171
|
- lib/active_shipping/shipping/carriers/canada_post.rb
|
172
|
+
- lib/active_shipping/shipping/carriers/canada_post_pws.rb
|
156
173
|
- lib/active_shipping/shipping/carriers/fedex.rb
|
157
174
|
- lib/active_shipping/shipping/carriers/kunaki.rb
|
158
175
|
- lib/active_shipping/shipping/carriers/new_zealand_post.rb
|
159
176
|
- lib/active_shipping/shipping/carriers/shipwire.rb
|
160
177
|
- lib/active_shipping/shipping/carriers/ups.rb
|
178
|
+
- lib/active_shipping/shipping/carriers/ups.rb.orig
|
161
179
|
- lib/active_shipping/shipping/carriers/usps.rb
|
180
|
+
- lib/active_shipping/shipping/carriers/usps.rb.orig
|
162
181
|
- lib/active_shipping/shipping/carriers.rb
|
163
182
|
- lib/active_shipping/shipping/location.rb
|
164
183
|
- lib/active_shipping/shipping/package.rb
|
@@ -167,6 +186,7 @@ files:
|
|
167
186
|
- lib/active_shipping/shipping/response.rb
|
168
187
|
- lib/active_shipping/shipping/shipment_event.rb
|
169
188
|
- lib/active_shipping/shipping/shipment_packer.rb
|
189
|
+
- lib/active_shipping/shipping/shipping_response.rb
|
170
190
|
- lib/active_shipping/shipping/tracking_response.rb
|
171
191
|
- lib/active_shipping/version.rb
|
172
192
|
- lib/active_shipping.rb
|
@@ -205,7 +225,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
205
225
|
- !ruby/object:Gem::Version
|
206
226
|
segments:
|
207
227
|
- 0
|
208
|
-
hash:
|
228
|
+
hash: -3915278247980377542
|
209
229
|
version: '0'
|
210
230
|
none: false
|
211
231
|
required_rubygems_version: !ruby/object:Gem::Requirement
|