Class: Shippinglogic::UPS::Track::Details
- Inherits:
-
Object
- Object
- Shippinglogic::UPS::Track::Details
- Defined in:
- lib/shippinglogic/ups/track.rb
Defined Under Namespace
Classes: Event
Instance Attribute Summary collapse
-
#delivery_at ⇒ Object
Returns the value of attribute delivery_at.
-
#destination_city ⇒ Object
Returns the value of attribute destination_city.
-
#destination_country ⇒ Object
Returns the value of attribute destination_country.
-
#destination_state ⇒ Object
Returns the value of attribute destination_state.
-
#events ⇒ Object
Returns the value of attribute events.
-
#origin_city ⇒ Object
Returns the value of attribute origin_city.
-
#origin_country ⇒ Object
Returns the value of attribute origin_country.
-
#origin_state ⇒ Object
Returns the value of attribute origin_state.
-
#service_type ⇒ Object
Returns the value of attribute service_type.
-
#signature_name ⇒ Object
Returns the value of attribute signature_name.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(response) ⇒ Details
constructor
A new instance of Details.
Constructor Details
#initialize(response) ⇒ Details
Returns a new instance of Details.
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
#delivery_at ⇒ Object
Returns the value of attribute delivery_at.
45 46 47 |
# File 'lib/shippinglogic/ups/track.rb', line 45 def delivery_at @delivery_at end |
#destination_city ⇒ Object
Returns the value of attribute destination_city.
45 46 47 |
# File 'lib/shippinglogic/ups/track.rb', line 45 def destination_city @destination_city end |
#destination_country ⇒ Object
Returns the value of attribute destination_country.
45 46 47 |
# File 'lib/shippinglogic/ups/track.rb', line 45 def destination_country @destination_country end |
#destination_state ⇒ Object
Returns the value of attribute destination_state.
45 46 47 |
# File 'lib/shippinglogic/ups/track.rb', line 45 def destination_state @destination_state end |
#events ⇒ Object
Returns the value of attribute events.
45 46 47 |
# File 'lib/shippinglogic/ups/track.rb', line 45 def events @events end |
#origin_city ⇒ Object
Returns the value of attribute origin_city.
45 46 47 |
# File 'lib/shippinglogic/ups/track.rb', line 45 def origin_city @origin_city end |
#origin_country ⇒ Object
Returns the value of attribute origin_country.
45 46 47 |
# File 'lib/shippinglogic/ups/track.rb', line 45 def origin_country @origin_country end |
#origin_state ⇒ Object
Returns the value of attribute origin_state.
45 46 47 |
# File 'lib/shippinglogic/ups/track.rb', line 45 def origin_state @origin_state end |
#service_type ⇒ Object
Returns the value of attribute service_type.
45 46 47 |
# File 'lib/shippinglogic/ups/track.rb', line 45 def service_type @service_type end |
#signature_name ⇒ Object
Returns the value of attribute signature_name.
45 46 47 |
# File 'lib/shippinglogic/ups/track.rb', line 45 def signature_name @signature_name end |
#status ⇒ Object
Returns the value of attribute status.
45 46 47 |
# File 'lib/shippinglogic/ups/track.rb', line 45 def status @status end |