active_shipping 0.12.6 → 1.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +2 -0
  3. data.tar.gz.sig +0 -0
  4. data/{CHANGELOG → CHANGELOG.md} +6 -2
  5. data/CONTRIBUTING.md +32 -0
  6. data/{README.markdown → README.md} +45 -61
  7. data/lib/active_shipping.rb +20 -28
  8. data/lib/active_shipping/carrier.rb +82 -0
  9. data/lib/active_shipping/carriers.rb +33 -0
  10. data/lib/active_shipping/carriers/benchmark_carrier.rb +31 -0
  11. data/lib/active_shipping/carriers/bogus_carrier.rb +12 -0
  12. data/lib/active_shipping/carriers/canada_post.rb +253 -0
  13. data/lib/active_shipping/carriers/canada_post_pws.rb +870 -0
  14. data/lib/active_shipping/carriers/fedex.rb +579 -0
  15. data/lib/active_shipping/carriers/kunaki.rb +164 -0
  16. data/lib/active_shipping/carriers/new_zealand_post.rb +262 -0
  17. data/lib/active_shipping/carriers/shipwire.rb +181 -0
  18. data/lib/active_shipping/carriers/stamps.rb +861 -0
  19. data/lib/active_shipping/carriers/ups.rb +648 -0
  20. data/lib/active_shipping/carriers/usps.rb +642 -0
  21. data/lib/active_shipping/errors.rb +7 -0
  22. data/lib/active_shipping/label_response.rb +23 -0
  23. data/lib/active_shipping/location.rb +149 -0
  24. data/lib/active_shipping/package.rb +241 -0
  25. data/lib/active_shipping/rate_estimate.rb +64 -0
  26. data/lib/active_shipping/rate_response.rb +13 -0
  27. data/lib/active_shipping/response.rb +41 -0
  28. data/lib/active_shipping/shipment_event.rb +17 -0
  29. data/lib/active_shipping/shipment_packer.rb +73 -0
  30. data/lib/active_shipping/shipping_response.rb +12 -0
  31. data/lib/active_shipping/tracking_response.rb +52 -0
  32. data/lib/active_shipping/version.rb +1 -1
  33. data/lib/vendor/quantified/test/length_test.rb +2 -2
  34. data/lib/vendor/xml_node/test/test_parsing.rb +1 -1
  35. metadata +58 -36
  36. metadata.gz.sig +0 -0
  37. data/lib/active_shipping/shipping/base.rb +0 -13
  38. data/lib/active_shipping/shipping/carrier.rb +0 -84
  39. data/lib/active_shipping/shipping/carriers.rb +0 -23
  40. data/lib/active_shipping/shipping/carriers/benchmark_carrier.rb +0 -33
  41. data/lib/active_shipping/shipping/carriers/bogus_carrier.rb +0 -14
  42. data/lib/active_shipping/shipping/carriers/canada_post.rb +0 -257
  43. data/lib/active_shipping/shipping/carriers/canada_post_pws.rb +0 -874
  44. data/lib/active_shipping/shipping/carriers/fedex.rb +0 -581
  45. data/lib/active_shipping/shipping/carriers/kunaki.rb +0 -166
  46. data/lib/active_shipping/shipping/carriers/new_zealand_post.rb +0 -262
  47. data/lib/active_shipping/shipping/carriers/shipwire.rb +0 -184
  48. data/lib/active_shipping/shipping/carriers/stamps.rb +0 -864
  49. data/lib/active_shipping/shipping/carriers/ups.rb +0 -650
  50. data/lib/active_shipping/shipping/carriers/usps.rb +0 -649
  51. data/lib/active_shipping/shipping/errors.rb +0 -9
  52. data/lib/active_shipping/shipping/label_response.rb +0 -25
  53. data/lib/active_shipping/shipping/location.rb +0 -152
  54. data/lib/active_shipping/shipping/package.rb +0 -243
  55. data/lib/active_shipping/shipping/rate_estimate.rb +0 -66
  56. data/lib/active_shipping/shipping/rate_response.rb +0 -15
  57. data/lib/active_shipping/shipping/response.rb +0 -43
  58. data/lib/active_shipping/shipping/shipment_event.rb +0 -19
  59. data/lib/active_shipping/shipping/shipment_packer.rb +0 -75
  60. data/lib/active_shipping/shipping/shipping_response.rb +0 -14
  61. data/lib/active_shipping/shipping/tracking_response.rb +0 -54
@@ -1,15 +0,0 @@
1
- module ActiveMerchant #:nodoc:
2
- module Shipping
3
- class RateResponse < Response
4
- attr_reader :rates
5
-
6
- def initialize(success, message, params = {}, options = {})
7
- @rates = Array(options[:estimates] || options[:rates] || options[:rate_estimates])
8
- super
9
- end
10
-
11
- alias_method :estimates, :rates
12
- alias_method :rate_estimates, :rates
13
- end
14
- end
15
- end
@@ -1,43 +0,0 @@
1
- module ActiveMerchant #:nodoc:
2
- module Shipping #:nodoc:
3
- class Error < ActiveMerchant::ActiveMerchantError
4
- end
5
-
6
- class ResponseError < Error
7
- attr_reader :response
8
-
9
- def initialize(response = nil)
10
- if response.is_a? Response
11
- super(response.message)
12
- @response = response
13
- else
14
- super(response)
15
- end
16
- end
17
- end
18
-
19
- class Response
20
- attr_reader :params
21
- attr_reader :message
22
- attr_reader :test
23
- attr_reader :xml
24
- attr_reader :request
25
-
26
- def initialize(success, message, params = {}, options = {})
27
- @success, @message, @params = success, message, params.stringify_keys
28
- @test = options[:test] || false
29
- @xml = options[:xml]
30
- @request = options[:request]
31
- raise ResponseError.new(self) unless success
32
- end
33
-
34
- def success?
35
- @success ? true : false
36
- end
37
-
38
- def test?
39
- @test ? true : false
40
- end
41
- end
42
- end
43
- end
@@ -1,19 +0,0 @@
1
- module ActiveMerchant #:nodoc:
2
- module Shipping
3
- class ShipmentEvent
4
- attr_reader :name, :time, :location, :message
5
-
6
- def initialize(name, time, location, message = nil)
7
- @name, @time, @location, @message = name, time, location, message
8
- end
9
-
10
- def delivered?
11
- status == :delivered
12
- end
13
-
14
- def status
15
- @status ||= name.downcase.gsub("\s", "_").to_sym
16
- end
17
- end
18
- end
19
- end
@@ -1,75 +0,0 @@
1
- module ActiveMerchant
2
- module Shipping
3
- class ShipmentPacker
4
- class OverweightItem < StandardError
5
- end
6
-
7
- EXCESS_PACKAGE_QUANTITY_THRESHOLD = 10_000
8
- class ExcessPackageQuantity < StandardError; end
9
-
10
- # items - array of hashes containing quantity, grams and price.
11
- # ex. [{:quantity => 2, :price => 1.0, :grams => 50}]
12
- # dimensions - [5.0, 15.0, 30.0]
13
- # maximum_weight - maximum weight in grams
14
- # currency - ISO currency code
15
- def self.pack(items, dimensions, maximum_weight, currency)
16
- return [] if items.empty?
17
- packages = []
18
-
19
- # Naive in that it assumes weight is equally distributed across all items
20
- # Should raise early enough in most cases
21
- total_weight = 0
22
- items.map!(&:symbolize_keys).each do |item|
23
- total_weight += item[:quantity].to_i * item[:grams].to_i
24
-
25
- if item[:grams].to_i > maximum_weight
26
- raise OverweightItem, "The item with weight of #{item[:grams]}g is heavier than the allowable package weight of #{maximum_weight}g"
27
- end
28
-
29
- if total_weight > maximum_weight * EXCESS_PACKAGE_QUANTITY_THRESHOLD
30
- raise ExcessPackageQuantity, "Unable to pack more than #{EXCESS_PACKAGE_QUANTITY_THRESHOLD} packages"
31
- end
32
- end
33
-
34
- items = items.deep_dup.sort_by! { |i| i[:grams].to_i }
35
-
36
- state = :package_empty
37
- while state != :packing_finished
38
- case state
39
- when :package_empty
40
- package_weight, package_value = 0, 0
41
- state = :filling_package
42
- when :filling_package
43
- items.each do |item|
44
- quantity = if item[:grams].to_i <= 0
45
- item[:quantity].to_i
46
- else
47
- # Grab the max amount of this item we can fit into this package
48
- # Or, if there are fewer than the max for this item, put
49
- # what is left into this package
50
- [(maximum_weight - package_weight) / item[:grams].to_i, item[:quantity].to_i].min
51
- end
52
-
53
- item_weight = quantity * item[:grams].to_i
54
- item_value = quantity * Package.cents_from(item[:price])
55
-
56
- package_weight += item_weight
57
- package_value += item_value
58
-
59
- item[:quantity] = item[:quantity].to_i - quantity
60
- end
61
-
62
- items.reject! { |i| i[:quantity].to_i == 0 }
63
-
64
- state = :package_full
65
- when :package_full
66
- packages << ActiveMerchant::Shipping::Package.new(package_weight, dimensions, :value => package_value, :currency => currency)
67
- state = items.any? ? :package_empty : :packing_finished
68
- end
69
- end
70
-
71
- packages
72
- end
73
- end
74
- end
75
- end
@@ -1,14 +0,0 @@
1
- module ActiveMerchant #:nodoc:
2
- module Shipping
3
- class ShippingResponse < Response
4
- attr_reader :shipping_id # string
5
- attr_reader :tracking_number # string
6
-
7
- def initialize(success, message, params = {}, options = {})
8
- @shipping_id = options[:shipping_id]
9
- @tracking_number = options[:tracking_number]
10
- super
11
- end
12
- end
13
- end
14
- end
@@ -1,54 +0,0 @@
1
- module ActiveMerchant #:nodoc:
2
- module Shipping
3
- class TrackingResponse < Response
4
- attr_reader :carrier # symbol
5
- attr_reader :carrier_name # string
6
- attr_reader :status # symbol
7
- attr_reader :status_code # string
8
- attr_reader :status_description # string
9
- attr_reader :ship_time # time
10
- attr_reader :scheduled_delivery_date # time
11
- attr_reader :actual_delivery_date # time
12
- attr_reader :delivery_signature # string
13
- attr_reader :tracking_number # string
14
- attr_reader :shipment_events # array of ShipmentEvents in chronological order
15
- attr_reader :shipper_address, :origin, :destination # Location objects
16
-
17
- def initialize(success, message, params = {}, options = {})
18
- @carrier = options[:carrier].parameterize.to_sym
19
- @carrier_name = options[:carrier]
20
- @status = options[:status]
21
- @status_code = options[:status_code]
22
- @status_description = options[:status_description]
23
- @ship_time = options[:ship_time]
24
- @scheduled_delivery_date = options[:scheduled_delivery_date]
25
- @actual_delivery_date = options[:actual_delivery_date]
26
- @delivery_signature = options[:delivery_signature]
27
- @tracking_number = options[:tracking_number]
28
- @shipment_events = Array(options[:shipment_events])
29
- @shipper_address = options[:shipper_address]
30
- @origin = options[:origin]
31
- @destination = options[:destination]
32
- super
33
- end
34
-
35
- def latest_event
36
- @shipment_events.last
37
- end
38
-
39
- def is_delivered?
40
- @status == :delivered
41
- end
42
-
43
- def has_exception?
44
- @status == :exception
45
- end
46
-
47
- alias_method(:exception_event, :latest_event)
48
- alias_method(:delivered?, :is_delivered?)
49
- alias_method(:exception?, :has_exception?)
50
- alias_method(:scheduled_delivery_time, :scheduled_delivery_date)
51
- alias_method(:actual_delivery_time, :actual_delivery_date)
52
- end
53
- end
54
- end