Permalink
Browse files

Added the UPS shipment cancellation service.

  • Loading branch information...
1 parent 7a9fcfd commit d1f06e9738d668a40f6d8d2fbea5e2d8ca4282ae @laserlemon laserlemon committed with Jun 9, 2010
Showing with 60 additions and 2 deletions.
  1. +8 −2 lib/shippinglogic/ups.rb
  2. +52 −0 lib/shippinglogic/ups/cancel.rb
View
@@ -1,4 +1,6 @@
require "shippinglogic/ups/service"
+require "shippinglogic/ups/cancel"
+require "shippinglogic/ups/rate"
require "shippinglogic/ups/track"
module Shippinglogic
@@ -48,12 +50,16 @@ def url
options[:test] ? options[:test_url] : options[:production_url]
end
- def track(attributes = {})
- @track ||= Track.new(self, attributes)
+ def cancel(attributes = {})
+ @cancel ||= Cancel.new(self, attributes)
end
def rate(attributes = {})
@rate ||= Rate.new(self, attributes)
end
+
+ def track(attributes = {})
+ @track ||= Track.new(self, attributes)
+ end
end
end
@@ -0,0 +1,52 @@
+module Shippinglogic
+ class UPS
+ # An interface to the shipment canceling service provided by UPS. Allows you to cancel a shipment
+ #
+ # == Accessor methods / options
+ #
+ # * <tt>tracking_number</tt> - the tracking number
+ #
+ # === Simple Example
+ #
+ # ups = Shippinglogic::UPS.new(key, password, account)
+ # cancel = ups.cancel(:tracking_number => "my number")
+ # cancel.perform
+ # # => true
+ class Cancel < Service
+ def self.path
+ "/Void"
+ end
+
+ attribute :tracking_number, :string
+
+ # Our services are set up as a proxy. We need to access the underlying object, to trigger the request
+ # to UPS. So calling this method is a way to do that since there really is no underlying object
+ def perform
+ target && true
+ end
+
+ private
+ # The parent class Service requires that we define this method. This is our kicker. This method is only
+ # called when we need to deal with information from FedEx. Notice the caching into the @target variable.
+ def target
+ @target ||= request(build_request)
+ end
+
+ # Just building some XML to send off to FedEx. FedEx require this particualr format.
+ def build_request
+ b = builder
+ build_authentication(b)
+ b.instruct!
+
+ b.VoidShipmentRequest do
+ b.Request do
+ b.RequestAction "1"
+ end
+
+ #TODO Determine whether tracking numbers are valid shipment identification numbers.
+ b.ShipmentIdentificationNumber tracking_number
+ end
+ end
+ end
+ end
+end

0 comments on commit d1f06e9

Please sign in to comment.