Class: UspsApi::PostOfficeLocation

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

Overview

USPS® Destination Entry Drop Shipment Location

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(facility_name: SKIP, facility_address: SKIP, facility_id: SKIP, geo_coordinates: SKIP, post_office_type: PostOfficeType::POST_OFFICE, distance: SKIP, phone_numbers: SKIP, services: SKIP, temporary_closure: SKIP, temporary_closure_date: SKIP, special_hours: SKIP, parking: SKIP, passports: SKIP, time_zone: SKIP, dst_observed: SKIP) ⇒ PostOfficeLocation

Returns a new instance of PostOfficeLocation.



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/usps_api/models/post_office_location.rb', line 121

def initialize(facility_name: SKIP, facility_address: SKIP,
               facility_id: SKIP, geo_coordinates: SKIP,
               post_office_type: PostOfficeType::POST_OFFICE,
               distance: SKIP, phone_numbers: SKIP, services: SKIP,
               temporary_closure: SKIP, temporary_closure_date: SKIP,
               special_hours: SKIP, parking: SKIP, passports: SKIP,
               time_zone: SKIP, dst_observed: SKIP)
  @facility_name = facility_name unless facility_name == SKIP
  @facility_address = facility_address unless facility_address == SKIP
  @facility_id = facility_id unless facility_id == SKIP
  @geo_coordinates = geo_coordinates unless geo_coordinates == SKIP
  @post_office_type = post_office_type unless post_office_type == SKIP
  @distance = distance unless distance == SKIP
  @phone_numbers = phone_numbers unless phone_numbers == SKIP
  @services = services unless services == SKIP
  @temporary_closure = temporary_closure unless temporary_closure == SKIP
  @temporary_closure_date = temporary_closure_date unless temporary_closure_date == SKIP
  @special_hours = special_hours unless special_hours == SKIP
  @parking = parking unless parking == SKIP
  @passports = passports unless passports == SKIP
  @time_zone = time_zone unless time_zone == SKIP
  @dst_observed = dst_observed unless dst_observed == SKIP
end

Instance Attribute Details

#distanceFloat

The distance from the provided address to the Post Office (in miles).

Returns:

  • (Float)


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

def distance
  @distance
end

#dst_observedTrueClass | FalseClass

Indicator for whether Daylight Savings Time is observed for a given facility.

Returns:

  • (TrueClass | FalseClass)


72
73
74
# File 'lib/usps_api/models/post_office_location.rb', line 72

def dst_observed
  @dst_observed
end

#facility_addressLocationsDomesticAddress

The name of the facility



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

def facility_address
  @facility_address
end

#facility_idString

The USPS® facility ID. When requesting Parcel Locker Delivery while generating a label, this ID should be provided in the request.

Returns:

  • (String)


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

def facility_id
  @facility_id
end

#facility_nameString

The name of the facility

Returns:

  • (String)


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

def facility_name
  @facility_name
end

#geo_coordinatesGeoCoordinates

The latitude and longitude values.

Returns:



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

def geo_coordinates
  @geo_coordinates
end

#parkingParking

The type of parking available at the location.

Returns:



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

def parking
  @parking
end

#passportsPassports

Facility information for passport services.

Returns:



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

def passports
  @passports
end

#phone_numbersPhoneNumbers

Post office contact information.

Returns:



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

def phone_numbers
  @phone_numbers
end

#post_office_typePostOfficeType

The type of location.

Returns:



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

def post_office_type
  @post_office_type
end

#servicesArray[Service]

A list of services offered at the location.

Returns:



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

def services
  @services
end

#special_hoursArray[SpecialHoursOfOperation]

Facility hours of operation intervals of a day.

Returns:



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

def special_hours
  @special_hours
end

#temporary_closureTrueClass | FalseClass

Indicator if the location has a current or upcoming temporary closure.

Returns:

  • (TrueClass | FalseClass)


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

def temporary_closure
  @temporary_closure
end

#temporary_closure_dateDate

The start date of the temporary closure.

Returns:

  • (Date)


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

def temporary_closure_date
  @temporary_closure_date
end

#time_zoneString

The time zone returned for a given facility.

Returns:

  • (String)


67
68
69
# File 'lib/usps_api/models/post_office_location.rb', line 67

def time_zone
  @time_zone
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



146
147
148
149
150
151
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
# File 'lib/usps_api/models/post_office_location.rb', line 146

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  facility_name = hash.key?('facilityName') ? hash['facilityName'] : SKIP
  facility_address = LocationsDomesticAddress.from_hash(hash['facilityAddress']) if
    hash['facilityAddress']
  facility_id = hash.key?('facilityID') ? hash['facilityID'] : SKIP
  geo_coordinates = GeoCoordinates.from_hash(hash['geoCoordinates']) if hash['geoCoordinates']
  post_office_type = hash['postOfficeType'] ||= PostOfficeType::POST_OFFICE
  distance = hash.key?('distance') ? hash['distance'] : SKIP
  phone_numbers = PhoneNumbers.from_hash(hash['phoneNumbers']) if hash['phoneNumbers']
  # Parameter is an array, so we need to iterate through it
  services = nil
  unless hash['services'].nil?
    services = []
    hash['services'].each do |structure|
      services << (Service.from_hash(structure) if structure)
    end
  end

  services = SKIP unless hash.key?('services')
  temporary_closure =
    hash.key?('temporaryClosure') ? hash['temporaryClosure'] : SKIP
  temporary_closure_date =
    hash.key?('temporaryClosureDate') ? hash['temporaryClosureDate'] : SKIP
  # Parameter is an array, so we need to iterate through it
  special_hours = nil
  unless hash['specialHours'].nil?
    special_hours = []
    hash['specialHours'].each do |structure|
      special_hours << (SpecialHoursOfOperation.from_hash(structure) if structure)
    end
  end

  special_hours = SKIP unless hash.key?('specialHours')
  parking = hash.key?('parking') ? hash['parking'] : SKIP
  passports = Passports.from_hash(hash['passports']) if hash['passports']
  time_zone = hash.key?('timeZone') ? hash['timeZone'] : SKIP
  dst_observed = hash.key?('DSTObserved') ? hash['DSTObserved'] : SKIP

  # Create object from extracted values.
  PostOfficeLocation.new(facility_name: facility_name,
                         facility_address: facility_address,
                         facility_id: facility_id,
                         geo_coordinates: geo_coordinates,
                         post_office_type: post_office_type,
                         distance: distance,
                         phone_numbers: phone_numbers,
                         services: services,
                         temporary_closure: temporary_closure,
                         temporary_closure_date: temporary_closure_date,
                         special_hours: special_hours,
                         parking: parking,
                         passports: passports,
                         time_zone: time_zone,
                         dst_observed: dst_observed)
end

.namesObject

A mapping from model property names to API property names.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/usps_api/models/post_office_location.rb', line 75

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['facility_name'] = 'facilityName'
  @_hash['facility_address'] = 'facilityAddress'
  @_hash['facility_id'] = 'facilityID'
  @_hash['geo_coordinates'] = 'geoCoordinates'
  @_hash['post_office_type'] = 'postOfficeType'
  @_hash['distance'] = 'distance'
  @_hash['phone_numbers'] = 'phoneNumbers'
  @_hash['services'] = 'services'
  @_hash['temporary_closure'] = 'temporaryClosure'
  @_hash['temporary_closure_date'] = 'temporaryClosureDate'
  @_hash['special_hours'] = 'specialHours'
  @_hash['parking'] = 'parking'
  @_hash['passports'] = 'passports'
  @_hash['time_zone'] = 'timeZone'
  @_hash['dst_observed'] = 'DSTObserved'
  @_hash
end

.nullablesObject

An array for nullable fields



117
118
119
# File 'lib/usps_api/models/post_office_location.rb', line 117

def self.nullables
  []
end

.optionalsObject

An array for optional fields



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/usps_api/models/post_office_location.rb', line 96

def self.optionals
  %w[
    facility_name
    facility_address
    facility_id
    geo_coordinates
    post_office_type
    distance
    phone_numbers
    services
    temporary_closure
    temporary_closure_date
    special_hours
    parking
    passports
    time_zone
    dst_observed
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



217
218
219
220
221
222
223
224
225
226
227
# File 'lib/usps_api/models/post_office_location.rb', line 217

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} facility_name: #{@facility_name.inspect}, facility_address:"\
  " #{@facility_address.inspect}, facility_id: #{@facility_id.inspect}, geo_coordinates:"\
  " #{@geo_coordinates.inspect}, post_office_type: #{@post_office_type.inspect}, distance:"\
  " #{@distance.inspect}, phone_numbers: #{@phone_numbers.inspect}, services:"\
  " #{@services.inspect}, temporary_closure: #{@temporary_closure.inspect},"\
  " temporary_closure_date: #{@temporary_closure_date.inspect}, special_hours:"\
  " #{@special_hours.inspect}, parking: #{@parking.inspect}, passports: #{@passports.inspect},"\
  " time_zone: #{@time_zone.inspect}, dst_observed: #{@dst_observed.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



206
207
208
209
210
211
212
213
214
# File 'lib/usps_api/models/post_office_location.rb', line 206

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} facility_name: #{@facility_name}, facility_address: #{@facility_address},"\
  " facility_id: #{@facility_id}, geo_coordinates: #{@geo_coordinates}, post_office_type:"\
  " #{@post_office_type}, distance: #{@distance}, phone_numbers: #{@phone_numbers}, services:"\
  " #{@services}, temporary_closure: #{@temporary_closure}, temporary_closure_date:"\
  " #{@temporary_closure_date}, special_hours: #{@special_hours}, parking: #{@parking},"\
  " passports: #{@passports}, time_zone: #{@time_zone}, dst_observed: #{@dst_observed}>"
end