Class: UspsApi::TrackingEvent

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

Overview

To be done.

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(event_type: SKIP, event_timestamp: SKIP, gmt_timestamp: SKIP, gmt_offset: SKIP, event_country: SKIP, event_city: SKIP, event_state: SKIP, event_zip: SKIP, firm: SKIP, name: SKIP, authorized_agent: SKIP, event_code: SKIP, veri_point: SKIP, action_code: SKIP, reason_code: SKIP, additional_properties: nil) ⇒ TrackingEvent

Returns a new instance of TrackingEvent.



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
# File 'lib/usps_api/models/tracking_event.rb', line 124

def initialize(event_type: SKIP, event_timestamp: SKIP, gmt_timestamp: SKIP,
               gmt_offset: SKIP, event_country: SKIP, event_city: SKIP,
               event_state: SKIP, event_zip: SKIP, firm: SKIP, name: SKIP,
               authorized_agent: SKIP, event_code: SKIP, veri_point: SKIP,
               action_code: SKIP, reason_code: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @event_type = event_type unless event_type == SKIP
  @event_timestamp = event_timestamp unless event_timestamp == SKIP
  @gmt_timestamp = gmt_timestamp unless gmt_timestamp == SKIP
  @gmt_offset = gmt_offset unless gmt_offset == SKIP
  @event_country = event_country unless event_country == SKIP
  @event_city = event_city unless event_city == SKIP
  @event_state = event_state unless event_state == SKIP
  @event_zip = event_zip unless event_zip == SKIP
  @firm = firm unless firm == SKIP
  @name = name unless name == SKIP
  @authorized_agent = authorized_agent unless authorized_agent == SKIP
  @event_code = event_code unless event_code == SKIP
  @veri_point = veri_point unless veri_point == SKIP
  @action_code = action_code unless action_code == SKIP
  @reason_code = reason_code unless reason_code == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#action_codeString

Refer to Pub 199 page 256 for list of Action Codes

Returns:

  • (String)


69
70
71
# File 'lib/usps_api/models/tracking_event.rb', line 69

def action_code
  @action_code
end

#authorized_agentTrueClass | FalseClass

Indicating whether the person signing is an Authorized Agent.

Returns:

  • (TrueClass | FalseClass)


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

def authorized_agent
  @authorized_agent
end

#event_cityString

The city where the event occurred.

Returns:

  • (String)


35
36
37
# File 'lib/usps_api/models/tracking_event.rb', line 35

def event_city
  @event_city
end

#event_codeString

Refer to the lookup table for all the possible values. USPS® [Pub 199](postalpro.usps.com/pub199) Appendix G-4:USPS® Domestic Tracking Scan Events

Returns:

  • (String)


61
62
63
# File 'lib/usps_api/models/tracking_event.rb', line 61

def event_code
  @event_code
end

#event_countryString

The country where the event occurred.

Returns:

  • (String)


31
32
33
# File 'lib/usps_api/models/tracking_event.rb', line 31

def event_country
  @event_country
end

#event_stateString

The state where the event occurred.

Returns:

  • (String)


39
40
41
# File 'lib/usps_api/models/tracking_event.rb', line 39

def event_state
  @event_state
end

#event_timestampDateTime

The date of the event.

Returns:

  • (DateTime)


19
20
21
# File 'lib/usps_api/models/tracking_event.rb', line 19

def event_timestamp
  @event_timestamp
end

#event_typeString

The type of event

Returns:

  • (String)


15
16
17
# File 'lib/usps_api/models/tracking_event.rb', line 15

def event_type
  @event_type
end

#event_zipString

The ZIP Code™ of the event.

Returns:

  • (String)


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

def event_zip
  @event_zip
end

#firmString

The company name if delivered to a company.

Returns:

  • (String)


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

def firm
  @firm
end

#gmt_offsetString

The offset of the local time of the event from Greenwich Mean Time (GMT).

Returns:

  • (String)


27
28
29
# File 'lib/usps_api/models/tracking_event.rb', line 27

def gmt_offset
  @gmt_offset
end

#gmt_timestampDateTime

The date-time of the event in Greenwich Mean Time (GMT).

Returns:

  • (DateTime)


23
24
25
# File 'lib/usps_api/models/tracking_event.rb', line 23

def gmt_timestamp
  @gmt_timestamp
end

#nameString

The name of the persons signing for delivery (if available).

Returns:

  • (String)


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

def name
  @name
end

#reason_codeString

Refer to the lookup table for all the possible values. USPS® [Pub 199](postalpro.usps.com/pub199) Appendix G-4: USPS® Domestic Tracking Scan Events

Returns:

  • (String)


75
76
77
# File 'lib/usps_api/models/tracking_event.rb', line 75

def reason_code
  @reason_code
end

#veri_pointTrueClass | FalseClass

Delivery scan location certified, if applicable. Refer to GeoCertified

Returns:

  • (TrueClass | FalseClass)


65
66
67
# File 'lib/usps_api/models/tracking_event.rb', line 65

def veri_point
  @veri_point
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/usps_api/models/tracking_event.rb', line 152

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  event_type = hash.key?('eventType') ? hash['eventType'] : SKIP
  event_timestamp = if hash.key?('eventTimestamp')
                      (DateTimeHelper.from_rfc3339(hash['eventTimestamp']) if hash['eventTimestamp'])
                    else
                      SKIP
                    end
  gmt_timestamp = if hash.key?('GMTTimestamp')
                    (DateTimeHelper.from_rfc3339(hash['GMTTimestamp']) if hash['GMTTimestamp'])
                  else
                    SKIP
                  end
  gmt_offset = hash.key?('GMTOffset') ? hash['GMTOffset'] : SKIP
  event_country = hash.key?('eventCountry') ? hash['eventCountry'] : SKIP
  event_city = hash.key?('eventCity') ? hash['eventCity'] : SKIP
  event_state = hash.key?('eventState') ? hash['eventState'] : SKIP
  event_zip = hash.key?('eventZIP') ? hash['eventZIP'] : SKIP
  firm = hash.key?('firm') ? hash['firm'] : SKIP
  name = hash.key?('name') ? hash['name'] : SKIP
  authorized_agent =
    hash.key?('authorizedAgent') ? hash['authorizedAgent'] : SKIP
  event_code = hash.key?('eventCode') ? hash['eventCode'] : SKIP
  veri_point = hash.key?('veriPoint') ? hash['veriPoint'] : SKIP
  action_code = hash.key?('actionCode') ? hash['actionCode'] : SKIP
  reason_code = hash.key?('reasonCode') ? hash['reasonCode'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  TrackingEvent.new(event_type: event_type,
                    event_timestamp: event_timestamp,
                    gmt_timestamp: gmt_timestamp,
                    gmt_offset: gmt_offset,
                    event_country: event_country,
                    event_city: event_city,
                    event_state: event_state,
                    event_zip: event_zip,
                    firm: firm,
                    name: name,
                    authorized_agent: authorized_agent,
                    event_code: event_code,
                    veri_point: veri_point,
                    action_code: action_code,
                    reason_code: reason_code,
                    additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/usps_api/models/tracking_event.rb', line 78

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['event_type'] = 'eventType'
  @_hash['event_timestamp'] = 'eventTimestamp'
  @_hash['gmt_timestamp'] = 'GMTTimestamp'
  @_hash['gmt_offset'] = 'GMTOffset'
  @_hash['event_country'] = 'eventCountry'
  @_hash['event_city'] = 'eventCity'
  @_hash['event_state'] = 'eventState'
  @_hash['event_zip'] = 'eventZIP'
  @_hash['firm'] = 'firm'
  @_hash['name'] = 'name'
  @_hash['authorized_agent'] = 'authorizedAgent'
  @_hash['event_code'] = 'eventCode'
  @_hash['veri_point'] = 'veriPoint'
  @_hash['action_code'] = 'actionCode'
  @_hash['reason_code'] = 'reasonCode'
  @_hash
end

.nullablesObject

An array for nullable fields



120
121
122
# File 'lib/usps_api/models/tracking_event.rb', line 120

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    event_type
    event_timestamp
    gmt_timestamp
    gmt_offset
    event_country
    event_city
    event_state
    event_zip
    firm
    name
    authorized_agent
    event_code
    veri_point
    action_code
    reason_code
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (TrackingEvent | Hash)

    value against the validation is performed.



217
218
219
220
221
222
223
# File 'lib/usps_api/models/tracking_event.rb', line 217

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



237
238
239
240
241
242
243
244
245
246
247
# File 'lib/usps_api/models/tracking_event.rb', line 237

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} event_type: #{@event_type.inspect}, event_timestamp:"\
  " #{@event_timestamp.inspect}, gmt_timestamp: #{@gmt_timestamp.inspect}, gmt_offset:"\
  " #{@gmt_offset.inspect}, event_country: #{@event_country.inspect}, event_city:"\
  " #{@event_city.inspect}, event_state: #{@event_state.inspect}, event_zip:"\
  " #{@event_zip.inspect}, firm: #{@firm.inspect}, name: #{@name.inspect}, authorized_agent:"\
  " #{@authorized_agent.inspect}, event_code: #{@event_code.inspect}, veri_point:"\
  " #{@veri_point.inspect}, action_code: #{@action_code.inspect}, reason_code:"\
  " #{@reason_code.inspect}, additional_properties: #{@additional_properties}>"
end

#to_custom_event_timestampObject



207
208
209
# File 'lib/usps_api/models/tracking_event.rb', line 207

def to_custom_event_timestamp
  DateTimeHelper.to_rfc3339(event_timestamp)
end

#to_custom_gmt_timestampObject



211
212
213
# File 'lib/usps_api/models/tracking_event.rb', line 211

def to_custom_gmt_timestamp
  DateTimeHelper.to_rfc3339(gmt_timestamp)
end

#to_sObject

Provides a human-readable string representation of the object.



226
227
228
229
230
231
232
233
234
# File 'lib/usps_api/models/tracking_event.rb', line 226

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} event_type: #{@event_type}, event_timestamp: #{@event_timestamp},"\
  " gmt_timestamp: #{@gmt_timestamp}, gmt_offset: #{@gmt_offset}, event_country:"\
  " #{@event_country}, event_city: #{@event_city}, event_state: #{@event_state}, event_zip:"\
  " #{@event_zip}, firm: #{@firm}, name: #{@name}, authorized_agent: #{@authorized_agent},"\
  " event_code: #{@event_code}, veri_point: #{@veri_point}, action_code: #{@action_code},"\
  " reason_code: #{@reason_code}, additional_properties: #{@additional_properties}>"
end