Class: UspsApi::TrackingLocation

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

Overview

Location details for the tracking event.

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(location_type:, stop_type:, stop_sequence:, drop_site_key: SKIP, zip_code5: SKIP) ⇒ TrackingLocation

Returns a new instance of TrackingLocation.



56
57
58
59
60
61
62
63
# File 'lib/usps_api/models/tracking_location.rb', line 56

def initialize(location_type:, stop_type:, stop_sequence:,
               drop_site_key: SKIP, zip_code5: SKIP)
  @location_type = location_type
  @drop_site_key = drop_site_key unless drop_site_key == SKIP
  @zip_code5 = zip_code5 unless zip_code5 == SKIP
  @stop_type = stop_type
  @stop_sequence = stop_sequence
end

Instance Attribute Details

#drop_site_keyString

Key for the drop site. Required when locationType is USPS.

Returns:

  • (String)


18
19
20
# File 'lib/usps_api/models/tracking_location.rb', line 18

def drop_site_key
  @drop_site_key
end

#location_typeLocationType

Type of location (e.g., USPS, CUSTOMER, NON_USPS).

Returns:



14
15
16
# File 'lib/usps_api/models/tracking_location.rb', line 14

def location_type
  @location_type
end

#stop_sequenceInteger

The actual stop number in the route.

Returns:

  • (Integer)


30
31
32
# File 'lib/usps_api/models/tracking_location.rb', line 30

def stop_sequence
  @stop_sequence
end

#stop_typePickupOrDelivery

Type of stop (Pickup or Delivery).

Returns:



26
27
28
# File 'lib/usps_api/models/tracking_location.rb', line 26

def stop_type
  @stop_type
end

#zip_code5String

Five-digit ZIP Code. Required when locationType is CUSTOMER or NON_USPS.

Returns:

  • (String)


22
23
24
# File 'lib/usps_api/models/tracking_location.rb', line 22

def zip_code5
  @zip_code5
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  location_type = hash.key?('locationType') ? hash['locationType'] : nil
  stop_type = hash.key?('stopType') ? hash['stopType'] : nil
  stop_sequence = hash.key?('stopSequence') ? hash['stopSequence'] : nil
  drop_site_key = hash.key?('dropSiteKey') ? hash['dropSiteKey'] : SKIP
  zip_code5 = hash.key?('ZIPCode5') ? hash['ZIPCode5'] : SKIP

  # Create object from extracted values.
  TrackingLocation.new(location_type: location_type,
                       stop_type: stop_type,
                       stop_sequence: stop_sequence,
                       drop_site_key: drop_site_key,
                       zip_code5: zip_code5)
end

.namesObject

A mapping from model property names to API property names.



33
34
35
36
37
38
39
40
41
# File 'lib/usps_api/models/tracking_location.rb', line 33

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['location_type'] = 'locationType'
  @_hash['drop_site_key'] = 'dropSiteKey'
  @_hash['zip_code5'] = 'ZIPCode5'
  @_hash['stop_type'] = 'stopType'
  @_hash['stop_sequence'] = 'stopSequence'
  @_hash
end

.nullablesObject

An array for nullable fields



52
53
54
# File 'lib/usps_api/models/tracking_location.rb', line 52

def self.nullables
  []
end

.optionalsObject

An array for optional fields



44
45
46
47
48
49
# File 'lib/usps_api/models/tracking_location.rb', line 44

def self.optionals
  %w[
    drop_site_key
    zip_code5
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



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

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} location_type: #{@location_type.inspect}, drop_site_key:"\
  " #{@drop_site_key.inspect}, zip_code5: #{@zip_code5.inspect}, stop_type:"\
  " #{@stop_type.inspect}, stop_sequence: #{@stop_sequence.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



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

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} location_type: #{@location_type}, drop_site_key: #{@drop_site_key},"\
  " zip_code5: #{@zip_code5}, stop_type: #{@stop_type}, stop_sequence: #{@stop_sequence}>"
end