Class: UspsApi::Estimate

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

Overview

Delivery estimate for the unique combination of Mail Class, Destination Type, Acceptance Location, and Delivery Time

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(mail_class: SKIP, notes: SKIP, destination_type: SKIP, acceptance_date_time: SKIP, effective_acceptance_date: SKIP, cut_off_time: SKIP, service_standard: SKIP, service_standard_message: SKIP, acceptance_locations: SKIP, delivery: SKIP, presort: SKIP, is_priority_mail_next_day: SKIP) ⇒ Estimate

Returns a new instance of Estimate.



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/usps_api/models/estimate.rb', line 116

def initialize(mail_class: SKIP, notes: SKIP, destination_type: SKIP,
               acceptance_date_time: SKIP, effective_acceptance_date: SKIP,
               cut_off_time: SKIP, service_standard: SKIP,
               service_standard_message: SKIP, acceptance_locations: SKIP,
               delivery: SKIP, presort: SKIP,
               is_priority_mail_next_day: SKIP)
  @mail_class = mail_class unless mail_class == SKIP
  @notes = notes unless notes == SKIP
  @destination_type = destination_type unless destination_type == SKIP
  @acceptance_date_time = acceptance_date_time unless acceptance_date_time == SKIP
  unless effective_acceptance_date == SKIP
    @effective_acceptance_date =
      effective_acceptance_date
  end
  @cut_off_time = cut_off_time unless cut_off_time == SKIP
  @service_standard = service_standard unless service_standard == SKIP
  @service_standard_message = service_standard_message unless service_standard_message == SKIP
  @acceptance_locations = acceptance_locations unless acceptance_locations == SKIP
  @delivery = delivery unless delivery == SKIP
  @presort = presort unless presort == SKIP
  unless is_priority_mail_next_day == SKIP
    @is_priority_mail_next_day =
      is_priority_mail_next_day
  end
end

Instance Attribute Details

#acceptance_date_timeDateTime

The requested acceptance date and time in locale time at the entry location where the mailer intends to enter the pieces into the mail stream.

Returns:

  • (DateTime)


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

def acceptance_date_time
  @acceptance_date_time
end

#acceptance_locationsFacility

This is USPS® facility information.

Returns:



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

def acceptance_locations
  @acceptance_locations
end

#cut_off_timeString

The latest time packages may be entered at the acceptance location. Packages entered after the cut-off time will have an effective date one day after the requested acceptance date and time.

Returns:

  • (String)


46
47
48
# File 'lib/usps_api/models/estimate.rb', line 46

def cut_off_time
  @cut_off_time
end

#deliveryEstimateDelivery

Section Heading that displays Delivery Date information. For all Mail Classes, occurs once for each HFPU Location. Additionally, for PME Street & PO Box, occurs once for each Customer Delivery Option.

Returns:



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

def delivery
  @delivery
end

#destination_typeString

Destination type indicator for non-expedited mailing.

Returns:

  • (String)


29
30
31
# File 'lib/usps_api/models/estimate.rb', line 29

def destination_type
  @destination_type
end

#effective_acceptance_dateDate

The effective acceptance date based on the requested acceptance date, time, and the facility cut-off times.

Returns:

  • (Date)


40
41
42
# File 'lib/usps_api/models/estimate.rb', line 40

def effective_acceptance_date
  @effective_acceptance_date
end

#is_priority_mail_next_dayTrueClass | FalseClass

Indicates if the estimate is for Priority Mail Next Day service.

Returns:

  • (TrueClass | FalseClass)


73
74
75
# File 'lib/usps_api/models/estimate.rb', line 73

def is_priority_mail_next_day
  @is_priority_mail_next_day
end

#mail_classString

MailClass from request If left blank in the request then it will return standards for PRIORITY_MAIL_EXPRESS, PRIORITY_MAIL, FIRST_CLASS_PACKAGE_SERVICE, and PACKAGE_SERVICES which covers LIBRARY_MAIL, MEDIA_MAIL, and BOUND_PRINTED_MATTER.

Returns:

  • (String)


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

def mail_class
  @mail_class
end

#notesNotes

When a mailClass will be returned with more than one estimate the notes will be returned with information on what differentiates the two estimates.

Returns:



25
26
27
# File 'lib/usps_api/models/estimate.rb', line 25

def notes
  @notes
end

#presortTrueClass | FalseClass

Indicates whether the service standard information is for Presort mail.

Returns:

  • (TrueClass | FalseClass)


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

def presort
  @presort
end

#service_standardString

The service standard expected based on the origin, destination, and mail class.

Returns:

  • (String)


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

def service_standard
  @service_standard
end

#service_standard_messageString

The service standard text corresponding to the code.

Returns:

  • (String)


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

def service_standard_message
  @service_standard_message
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



143
144
145
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
# File 'lib/usps_api/models/estimate.rb', line 143

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  mail_class = hash.key?('mailClass') ? hash['mailClass'] : SKIP
  notes = hash.key?('notes') ? hash['notes'] : SKIP
  destination_type =
    hash.key?('destinationType') ? hash['destinationType'] : SKIP
  acceptance_date_time = if hash.key?('acceptanceDateTime')
                           (DateTimeHelper.from_rfc3339(hash['acceptanceDateTime']) if hash['acceptanceDateTime'])
                         else
                           SKIP
                         end
  effective_acceptance_date =
    hash.key?('effectiveAcceptanceDate') ? hash['effectiveAcceptanceDate'] : SKIP
  cut_off_time = hash.key?('cutOffTime') ? hash['cutOffTime'] : SKIP
  service_standard =
    hash.key?('serviceStandard') ? hash['serviceStandard'] : SKIP
  service_standard_message =
    hash.key?('serviceStandardMessage') ? hash['serviceStandardMessage'] : SKIP
  acceptance_locations = Facility.from_hash(hash['acceptanceLocations']) if
    hash['acceptanceLocations']
  delivery = EstimateDelivery.from_hash(hash['delivery']) if hash['delivery']
  presort = hash.key?('presort') ? hash['presort'] : SKIP
  is_priority_mail_next_day =
    hash.key?('isPriorityMailNextDay') ? hash['isPriorityMailNextDay'] : SKIP

  # Create object from extracted values.
  Estimate.new(mail_class: mail_class,
               notes: notes,
               destination_type: destination_type,
               acceptance_date_time: acceptance_date_time,
               effective_acceptance_date: effective_acceptance_date,
               cut_off_time: cut_off_time,
               service_standard: service_standard,
               service_standard_message: service_standard_message,
               acceptance_locations: acceptance_locations,
               delivery: delivery,
               presort: presort,
               is_priority_mail_next_day: is_priority_mail_next_day)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['mail_class'] = 'mailClass'
  @_hash['notes'] = 'notes'
  @_hash['destination_type'] = 'destinationType'
  @_hash['acceptance_date_time'] = 'acceptanceDateTime'
  @_hash['effective_acceptance_date'] = 'effectiveAcceptanceDate'
  @_hash['cut_off_time'] = 'cutOffTime'
  @_hash['service_standard'] = 'serviceStandard'
  @_hash['service_standard_message'] = 'serviceStandardMessage'
  @_hash['acceptance_locations'] = 'acceptanceLocations'
  @_hash['delivery'] = 'delivery'
  @_hash['presort'] = 'presort'
  @_hash['is_priority_mail_next_day'] = 'isPriorityMailNextDay'
  @_hash
end

.nullablesObject

An array for nullable fields



112
113
114
# File 'lib/usps_api/models/estimate.rb', line 112

def self.nullables
  []
end

.optionalsObject

An array for optional fields



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/usps_api/models/estimate.rb', line 94

def self.optionals
  %w[
    mail_class
    notes
    destination_type
    acceptance_date_time
    effective_acceptance_date
    cut_off_time
    service_standard
    service_standard_message
    acceptance_locations
    delivery
    presort
    is_priority_mail_next_day
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



202
203
204
205
206
207
208
209
210
211
212
# File 'lib/usps_api/models/estimate.rb', line 202

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} mail_class: #{@mail_class.inspect}, notes: #{@notes.inspect},"\
  " destination_type: #{@destination_type.inspect}, acceptance_date_time:"\
  " #{@acceptance_date_time.inspect}, effective_acceptance_date:"\
  " #{@effective_acceptance_date.inspect}, cut_off_time: #{@cut_off_time.inspect},"\
  " service_standard: #{@service_standard.inspect}, service_standard_message:"\
  " #{@service_standard_message.inspect}, acceptance_locations:"\
  " #{@acceptance_locations.inspect}, delivery: #{@delivery.inspect}, presort:"\
  " #{@presort.inspect}, is_priority_mail_next_day: #{@is_priority_mail_next_day.inspect}>"
end

#to_custom_acceptance_date_timeObject



185
186
187
# File 'lib/usps_api/models/estimate.rb', line 185

def to_custom_acceptance_date_time
  DateTimeHelper.to_rfc3339(acceptance_date_time)
end

#to_sObject

Provides a human-readable string representation of the object.



190
191
192
193
194
195
196
197
198
199
# File 'lib/usps_api/models/estimate.rb', line 190

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} mail_class: #{@mail_class}, notes: #{@notes}, destination_type:"\
  " #{@destination_type}, acceptance_date_time: #{@acceptance_date_time},"\
  " effective_acceptance_date: #{@effective_acceptance_date}, cut_off_time: #{@cut_off_time},"\
  " service_standard: #{@service_standard}, service_standard_message:"\
  " #{@service_standard_message}, acceptance_locations: #{@acceptance_locations}, delivery:"\
  " #{@delivery}, presort: #{@presort}, is_priority_mail_next_day:"\
  " #{@is_priority_mail_next_day}>"
end