Class: UspsApi::ShipmentTrackingEvent

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/usps_api/models/shipment_tracking_event.rb

Overview

Details about a shipment tracking event, including location, status, and facility information.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(external_load_number:, appointment_id:, appointment_date:, trailer_id:, scheduler_crid:, location:, current_location:, current_event:, positional_info:, eta: SKIP, eta_status: SKIP, resource_info: SKIP) ⇒ ShipmentTrackingEvent

Returns a new instance of ShipmentTrackingEvent.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 100

def initialize(external_load_number:, appointment_id:, appointment_date:,
               trailer_id:, scheduler_crid:, location:, current_location:,
               current_event:, positional_info:, eta: SKIP,
               eta_status: SKIP, resource_info: SKIP)
  @external_load_number = external_load_number
  @appointment_id = appointment_id
  @appointment_date = appointment_date
  @trailer_id = trailer_id
  @scheduler_crid = scheduler_crid
  @eta = eta unless eta == SKIP
  @eta_status = eta_status unless eta_status == SKIP
  @location = location
  @current_location = current_location
  @current_event = current_event
  @positional_info = positional_info
  @resource_info = resource_info unless resource_info == SKIP
end

Instance Attribute Details

#appointment_dateDateTime

Date and time of the appointment (ISO 8601).

Returns:

  • (DateTime)


24
25
26
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 24

def appointment_date
  @appointment_date
end

#appointment_idString

Appointment ID assigned from FAST.

Returns:

  • (String)


20
21
22
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 20

def appointment_id
  @appointment_id
end

#current_eventTrackingCurrentEvent

The current event type for the shipment.



55
56
57
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 55

def current_event
  @current_event
end

#current_locationTrackingCurrentLocation

Current location details for the tracking event.



51
52
53
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 51

def current_location
  @current_location
end

#etaDateTime

Estimated time of arrival (ISO 8601). Required unless currentEvent.eventType is FACILITY_ARRIVE or FACILITY_DEPART.

Returns:

  • (DateTime)


37
38
39
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 37

def eta
  @eta
end

#eta_statusEtaStatus

The ETA status of the current destination and not the appointment. Required unless currentEvent.eventType is FACILITY_ARRIVE or FACILITY_DEPART.

Returns:



43
44
45
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 43

def eta_status
  @eta_status
end

#external_load_numberString

Unique identifier for the shipment load.

Returns:

  • (String)


16
17
18
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 16

def external_load_number
  @external_load_number
end

#locationTrackingLocation

Location details for the tracking event.

Returns:



47
48
49
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 47

def location
  @location
end

#positional_infoTrackingPositionalInfo

Positional information for the shipment.



59
60
61
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 59

def positional_info
  @positional_info
end

#resource_infoTrackingResourceInfo

Information about the resource sending the information.



63
64
65
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 63

def resource_info
  @resource_info
end

#scheduler_cridString

Scheduler’s unique identifier.

Returns:

  • (String)


32
33
34
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 32

def scheduler_crid
  @scheduler_crid
end

#trailer_idString

Unique identifier for the trailer.

Returns:

  • (String)


28
29
30
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 28

def trailer_id
  @trailer_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 119

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  external_load_number =
    hash.key?('externalLoadNumber') ? hash['externalLoadNumber'] : nil
  appointment_id = hash.key?('appointmentID') ? hash['appointmentID'] : nil
  appointment_date = if hash.key?('appointmentDate')
                       (DateTimeHelper.from_rfc3339(hash['appointmentDate']) if hash['appointmentDate'])
                     end
  trailer_id = hash.key?('trailerID') ? hash['trailerID'] : nil
  scheduler_crid = hash.key?('schedulerCRID') ? hash['schedulerCRID'] : nil
  location = TrackingLocation.from_hash(hash['location']) if hash['location']
  current_location = TrackingCurrentLocation.from_hash(hash['currentLocation']) if
    hash['currentLocation']
  current_event = TrackingCurrentEvent.from_hash(hash['currentEvent']) if hash['currentEvent']
  positional_info = TrackingPositionalInfo.from_hash(hash['positionalInfo']) if
    hash['positionalInfo']
  eta = if hash.key?('ETA')
          (DateTimeHelper.from_rfc3339(hash['ETA']) if hash['ETA'])
        else
          SKIP
        end
  eta_status = hash.key?('ETAStatus') ? hash['ETAStatus'] : SKIP
  resource_info = TrackingResourceInfo.from_hash(hash['resourceInfo']) if hash['resourceInfo']

  # Create object from extracted values.
  ShipmentTrackingEvent.new(external_load_number: external_load_number,
                            appointment_id: appointment_id,
                            appointment_date: appointment_date,
                            trailer_id: trailer_id,
                            scheduler_crid: scheduler_crid,
                            location: location,
                            current_location: current_location,
                            current_event: current_event,
                            positional_info: positional_info,
                            eta: eta,
                            eta_status: eta_status,
                            resource_info: resource_info)
end

.namesObject

A mapping from model property names to API property names.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 66

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['external_load_number'] = 'externalLoadNumber'
  @_hash['appointment_id'] = 'appointmentID'
  @_hash['appointment_date'] = 'appointmentDate'
  @_hash['trailer_id'] = 'trailerID'
  @_hash['scheduler_crid'] = 'schedulerCRID'
  @_hash['eta'] = 'ETA'
  @_hash['eta_status'] = 'ETAStatus'
  @_hash['location'] = 'location'
  @_hash['current_location'] = 'currentLocation'
  @_hash['current_event'] = 'currentEvent'
  @_hash['positional_info'] = 'positionalInfo'
  @_hash['resource_info'] = 'resourceInfo'
  @_hash
end

.nullablesObject

An array for nullable fields



93
94
95
96
97
98
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 93

def self.nullables
  %w[
    eta
    eta_status
  ]
end

.optionalsObject

An array for optional fields



84
85
86
87
88
89
90
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 84

def self.optionals
  %w[
    eta
    eta_status
    resource_info
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



179
180
181
182
183
184
185
186
187
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 179

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} external_load_number: #{@external_load_number.inspect}, appointment_id:"\
  " #{@appointment_id.inspect}, appointment_date: #{@appointment_date.inspect}, trailer_id:"\
  " #{@trailer_id.inspect}, scheduler_crid: #{@scheduler_crid.inspect}, eta: #{@eta.inspect},"\
  " eta_status: #{@eta_status.inspect}, location: #{@location.inspect}, current_location:"\
  " #{@current_location.inspect}, current_event: #{@current_event.inspect}, positional_info:"\
  " #{@positional_info.inspect}, resource_info: #{@resource_info.inspect}>"
end

#to_custom_appointment_dateObject



160
161
162
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 160

def to_custom_appointment_date
  DateTimeHelper.to_rfc3339(appointment_date)
end

#to_custom_etaObject



164
165
166
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 164

def to_custom_eta
  DateTimeHelper.to_rfc3339(eta)
end

#to_sObject

Provides a human-readable string representation of the object.



169
170
171
172
173
174
175
176
# File 'lib/usps_api/models/shipment_tracking_event.rb', line 169

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} external_load_number: #{@external_load_number}, appointment_id:"\
  " #{@appointment_id}, appointment_date: #{@appointment_date}, trailer_id: #{@trailer_id},"\
  " scheduler_crid: #{@scheduler_crid}, eta: #{@eta}, eta_status: #{@eta_status}, location:"\
  " #{@location}, current_location: #{@current_location}, current_event: #{@current_event},"\
  " positional_info: #{@positional_info}, resource_info: #{@resource_info}>"
end