Sha256: 59803427ea9e81282fdf58d6b106f0c4f4ffb19248a75d8297d4397a028b5171

Contents?: true

Size: 1.93 KB

Versions: 2

Compression:

Stored size: 1.93 KB

Contents

module ActiveMerchant #:nodoc:
  module Shipping
    class TrackingResponse < Response
      attr_reader :carrier # symbol
      attr_reader :carrier_name # string
      attr_reader :status # symbol
      attr_reader :status_code # string
      attr_reader :status_description # string
      attr_reader :ship_time # time
      attr_reader :scheduled_delivery_date # time
      attr_reader :actual_delivery_date # time
      attr_reader :delivery_signature # string
      attr_reader :tracking_number # string
      attr_reader :shipment_events # array of ShipmentEvents in chronological order
      attr_reader :shipper_address, :origin, :destination # Location objects

      def initialize(success, message, params = {}, options = {})
        @carrier = options[:carrier].parameterize.to_sym
        @carrier_name = options[:carrier]
        @status = options[:status]
        @status_code = options[:status_code]
        @status_description = options[:status_description]
        @ship_time = options[:ship_time]
        @scheduled_delivery_date = options[:scheduled_delivery_date]
        @actual_delivery_date = options[:actual_delivery_date]
        @delivery_signature = options[:delivery_signature]
        @tracking_number = options[:tracking_number]
        @shipment_events = Array(options[:shipment_events])
        @shipper_address = options[:shipper_address]
        @origin = options[:origin]
        @destination = options[:destination]
        super
      end

      def latest_event
        @shipment_events.last
      end

      def is_delivered?
        @status == :delivered
      end

      def has_exception?
        @status == :exception
      end

      alias_method(:exception_event, :latest_event)
      alias_method(:delivered?, :is_delivered?)
      alias_method(:exception?, :has_exception?)
      alias_method(:scheduled_delivery_time, :scheduled_delivery_date)
      alias_method(:actual_delivery_time, :actual_delivery_date)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_shipping-0.12.6 lib/active_shipping/shipping/tracking_response.rb
active_shipping-0.12.5 lib/active_shipping/shipping/tracking_response.rb