class ReactiveShipping::TrackingResponse

Represents the response to a {ReactiveShipping::Carrier#find_tracking_info} call.

@note Some carriers provide more information than others, so not all attributes

will be set, depending on what carrier you are using.

@!attribute carrier

@return [Symbol]

@!attribute carrier_name

@return [String]

@!attribute status

@return [Symbol]

@!attribute status_code

@return [string]

@!attribute status_description

@return [String]

@!attribute ship_time

@return [Date, Time]

@!attribute scheduled_delivery_date

@return [Date, Time]

@!attribute actual_delivery_date

@return [Date, Time]

@!attribute attempted_delivery_date

@return [Date, Time]

@!attribute delivery_signature

@return [String]

@!attribute tracking_number

@return [String]

@!attribute shipment_events

@return [Array<ReactiveShipping::ShipmentEvent>]

@!attribute shipper_address

@return [ReactiveShipping::Location]

@!attribute origin

@return [ReactiveShipping::Location]

@!attribute destination

@return [ReactiveShipping::Location]

Attributes

actual_delivery_date[R]
actual_delivery_time[R]
attempted_delivery_date[R]
attempted_delivery_time[R]
carrier[R]
carrier_name[R]
delivery_signature[R]
destination[R]
origin[R]
scheduled_delivery_date[R]
scheduled_delivery_time[R]
ship_time[R]
shipment_events[R]
shipper_address[R]
status[R]
status_code[R]
status_description[R]
tracking_number[R]

Public Class Methods

new(success, message, params = {}, options = {}) click to toggle source

@params (see ReactiveShipping::Response#initialize)

Calls superclass method ReactiveShipping::Response::new
# File lib/reactive_shipping/tracking_response.rb, line 60
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]
  @attempted_delivery_date = options[:attempted_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

Public Instance Methods

==(other) click to toggle source
# File lib/reactive_shipping/tracking_response.rb, line 105
def ==(other)
  attributes = %i(carrier carrier_name status status_code status_description ship_time scheduled_delivery_date
    actual_delivery_date attempted_delivery_date delivery_signature tracking_number shipper_address
    origin destination
  )

  attributes.all? { |attr| self.public_send(attr) == other.public_send(attr) } && compare_shipment_events(other)
end
delivered?()
Alias for: is_delivered?
exception?()
Alias for: has_exception?
exception_event()
Alias for: latest_event
has_exception?() click to toggle source

Returns `true` if something out of the ordinary has happened during the delivery of this package. @return [Boolean]

# File lib/reactive_shipping/tracking_response.rb, line 94
def has_exception?
  @status == :exception
end
Also aliased as: exception?
is_delivered?() click to toggle source

Returns `true` if the shipment has arrived at the destination. @return [Boolean]

# File lib/reactive_shipping/tracking_response.rb, line 87
def is_delivered?
  @status == :delivered
end
Also aliased as: delivered?
latest_event() click to toggle source

The latest tracking event for this shipment, i.e. the current status. @return [ReactiveShipping::ShipmentEvent]

# File lib/reactive_shipping/tracking_response.rb, line 81
def latest_event
  @shipment_events.last
end
Also aliased as: exception_event

Private Instance Methods

compare_shipment_events(other) click to toggle source

Ensure order doesn't matter when comparing shipment_events

# File lib/reactive_shipping/tracking_response.rb, line 116
def compare_shipment_events(other)
  shipment_events.sort_by(&:time) == other.shipment_events.sort_by(&:time)
end