Class: Shippinglogic::UPS::Track::Details

Inherits:
Object
  • Object
show all
Defined in:
lib/shippinglogic/ups/track.rb

Defined Under Namespace

Classes: Event

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Details) initialize(response)



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/shippinglogic/ups/track.rb', line 50

def initialize(response)
  details = response[:shipment]
  
  if origin = details.fetch(:shipper, {})[:address]
    self.origin_city    = origin[:city]
    self.origin_state   = origin[:state_province_code]
    self.origin_country = origin[:country_code]
  end
  
  if destination = details.fetch(:ship_to, {})[:address]
    self.destination_city     = destination[:city]
    self.destination_state    = destination[:state_province_code]
    self.destination_country  = destination[:country_code]
  end
  
  package     = details[:package]
  events      = package[:activity].is_a?(Array) ? package[:activity] : [package[:activitiy]].compact
  last_event  = events.first
  delivery    = events.detect{|e| e[:status][:status_type][:code] == "D" }
  
  self.signature_name = last_event && last_event[:signed_for_by_name]
  self.service_type   = details[:service][:description]
  self.status         = last_event && last_event[:status][:status_type][:description]
  self.delivery_at    = delivery && Time.parse(delivery[:date] + delivery[:time])
  
  self.events = events.collect do |details|
    event             = Event.new
    status            = details[:status][:status_type]
    event.name        = status[:description]
    event.type        = status[:code]
    #FIXME The proper spelling is "occurred", not "occured."
    event.occured_at  = Time.parse(details[:date] + details[:time])
    location          = details[:activity_location][:address]
    event.city        = location[:city]
    event.state       = location[:state_province_code]
    event.postal_code = location[:postal_code]
    event.country     = location[:country_code]
    event
  end
end

Instance Attribute Details

- (Object) delivery_at

Returns the value of attribute delivery_at



45
46
47
# File 'lib/shippinglogic/ups/track.rb', line 45

def delivery_at
  @delivery_at
end

- (Object) destination_city

Returns the value of attribute destination_city



45
46
47
# File 'lib/shippinglogic/ups/track.rb', line 45

def destination_city
  @destination_city
end

- (Object) destination_country

Returns the value of attribute destination_country



45
46
47
# File 'lib/shippinglogic/ups/track.rb', line 45

def destination_country
  @destination_country
end

- (Object) destination_state

Returns the value of attribute destination_state



45
46
47
# File 'lib/shippinglogic/ups/track.rb', line 45

def destination_state
  @destination_state
end

- (Object) events

Returns the value of attribute events



45
46
47
# File 'lib/shippinglogic/ups/track.rb', line 45

def events
  @events
end

- (Object) origin_city

Returns the value of attribute origin_city



45
46
47
# File 'lib/shippinglogic/ups/track.rb', line 45

def origin_city
  @origin_city
end

- (Object) origin_country

Returns the value of attribute origin_country



45
46
47
# File 'lib/shippinglogic/ups/track.rb', line 45

def origin_country
  @origin_country
end

- (Object) origin_state

Returns the value of attribute origin_state



45
46
47
# File 'lib/shippinglogic/ups/track.rb', line 45

def origin_state
  @origin_state
end

- (Object) service_type

Returns the value of attribute service_type



45
46
47
# File 'lib/shippinglogic/ups/track.rb', line 45

def service_type
  @service_type
end

- (Object) signature_name

Returns the value of attribute signature_name



45
46
47
# File 'lib/shippinglogic/ups/track.rb', line 45

def signature_name
  @signature_name
end

- (Object) status

Returns the value of attribute status



45
46
47
# File 'lib/shippinglogic/ups/track.rb', line 45

def status
  @status
end