Class: UspsApi::LetterRatesQuery

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

Overview

Letter rate ingredients for calculating base prices.

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(weight:, length:, height:, thickness:, processing_category:, mailing_date: SKIP, non_machinable_indicators: SKIP, extra_services: SKIP, item_value: SKIP) ⇒ LetterRatesQuery

Returns a new instance of LetterRatesQuery.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/usps_api/models/letter_rates_query.rb', line 123

def initialize(weight:, length:, height:, thickness:, processing_category:,
               mailing_date: SKIP, non_machinable_indicators: SKIP,
               extra_services: SKIP, item_value: SKIP)
  @weight = weight
  @length = length
  @height = height
  @thickness = thickness
  @processing_category = processing_category
  @mailing_date = mailing_date unless mailing_date == SKIP
  unless non_machinable_indicators == SKIP
    @non_machinable_indicators =
      non_machinable_indicators
  end
  @extra_services = extra_services unless extra_services == SKIP
  @item_value = item_value unless item_value == SKIP
end

Instance Attribute Details

#extra_servicesArray[ExtraService11]

Extra Service Code requested.

  • 910 - Certified Mail

  • 911 - Certified Mail Restricted Delivery

  • 930 - Insurance <=$500

  • 931 - Insurance > $500

  • 934 - Insurance Restricted Delivery

  • 940 - Registered Mail

  • 941 - Registered Mail Restricted Delivery

  • 955 - Return Receipt

  • 957 - Return Receipt Electronic

  • 985 - Hold for Pickup

Returns:



86
87
88
# File 'lib/usps_api/models/letter_rates_query.rb', line 86

def extra_services
  @extra_services
end

#heightFloat

The letter/flat/card height measured in inches. The height is the dimension perpendicular to the length.

Returns:

  • (Float)


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

def height
  @height
end

#item_valueFloat

The value of the item. Required for Insurance. The price for Insurance and Registered Mail extra services will vary based on this value.

Returns:

  • (Float)


91
92
93
# File 'lib/usps_api/models/letter_rates_query.rb', line 91

def item_value
  @item_value
end

#lengthFloat

The letter/flat/card length measured in inches. For ‘LETTERS` and `CARDS` the length is the dimension parallel to the delivery address as read. For `FLATS` the length is the longest dimension.

Returns:

  • (Float)


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

def length
  @length
end

#mailing_dateDate

The date the package or letter/flat/card will be mailed. The mailing date may be today plus 0 to 7 days in advance. Enter the date in the full-date notation as defined by [RFC 3339, section 5.6](datatracker.ietf.org/doc/html/rfc3339#section-5.6).

Returns:

  • (Date)


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

def mailing_date
  @mailing_date
end

#non_machinable_indicatorsNonMachinableIndicators

Set of boolean indicators used to determine whether a letter/flat/card qualifies as nonmachinable.



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

def non_machinable_indicators
  @non_machinable_indicators
end

#processing_categoryProcessingCategory21

  • LETTERS

    To be eligible for mailing at the price for letters, a piece must be:

    * Rectangular
    * At least 3-1/2 inches high x 5 inches long x 0.007 inch thick.
    * No more than 6-1/8 inches high x 11-1/2 inches long x 1/4 inch
    

thick.

For additional information on letters, please refer to the [Postal

Explorer](pe.usps.com/businessmail101?ViewName=Letters).

  • FLATS The Postal Service uses the word “flats” to refer to large envelopes,

newsletters, and magazines. The words large envelopes and flats are used interchangeably. Whatever you call them, flats must:

* Have one dimension that is greater than 6-1/8 inches high OR 11-½

inches long OR ¼ inch thick.

  * Be no more than 12 inches high x 15 inches long x ¾ inch thick.
For additional information on flats, please refer to the [Postal

Explorer](pe.usps.com/businessmail101?ViewName=Flats).

  • CARDS To be eligible for mailing at the price for postcards, a piece must be:

    * Rectangular
    * At least 3-1/2 inches high x 5 inches long x 0.007 inch thick.
    * No more than 4-1/4 inches high x 6 inches long x 0.016 inch thick.
    

    For additional information on postcards, please refer to the [Postal

Explorer](pe.usps.com/businessmail101?ViewName=Cards).



60
61
62
# File 'lib/usps_api/models/letter_rates_query.rb', line 60

def processing_category
  @processing_category
end

#thicknessFloat

The letter/flat/card thickness measured in inches. The minimum dimension is always the thickness.

Returns:

  • (Float)


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

def thickness
  @thickness
end

#weightFloat

This is the calculated weight for the package based on user input. The greater of dimWeight and weight will be used to calculated the rate. Weight unit of measurement is in ounces.

Returns:

  • (Float)


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

def weight
  @weight
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



141
142
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
# File 'lib/usps_api/models/letter_rates_query.rb', line 141

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  weight = hash.key?('weight') ? hash['weight'] : nil
  length = hash.key?('length') ? hash['length'] : nil
  height = hash.key?('height') ? hash['height'] : nil
  thickness = hash.key?('thickness') ? hash['thickness'] : nil
  processing_category =
    hash.key?('processingCategory') ? hash['processingCategory'] : nil
  mailing_date = hash.key?('mailingDate') ? hash['mailingDate'] : SKIP
  if hash['nonMachinableIndicators']
    non_machinable_indicators = NonMachinableIndicators.from_hash(hash['nonMachinableIndicators'])
  end
  extra_services = hash.key?('extraServices') ? hash['extraServices'] : SKIP
  item_value = hash.key?('itemValue') ? hash['itemValue'] : SKIP

  # Create object from extracted values.
  LetterRatesQuery.new(weight: weight,
                       length: length,
                       height: height,
                       thickness: thickness,
                       processing_category: processing_category,
                       mailing_date: mailing_date,
                       non_machinable_indicators: non_machinable_indicators,
                       extra_services: extra_services,
                       item_value: item_value)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['weight'] = 'weight'
  @_hash['length'] = 'length'
  @_hash['height'] = 'height'
  @_hash['thickness'] = 'thickness'
  @_hash['processing_category'] = 'processingCategory'
  @_hash['mailing_date'] = 'mailingDate'
  @_hash['non_machinable_indicators'] = 'nonMachinableIndicators'
  @_hash['extra_services'] = 'extraServices'
  @_hash['item_value'] = 'itemValue'
  @_hash
end

.nullablesObject

An array for nullable fields



119
120
121
# File 'lib/usps_api/models/letter_rates_query.rb', line 119

def self.nullables
  []
end

.optionalsObject

An array for optional fields



109
110
111
112
113
114
115
116
# File 'lib/usps_api/models/letter_rates_query.rb', line 109

def self.optionals
  %w[
    mailing_date
    non_machinable_indicators
    extra_services
    item_value
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



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

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} weight: #{@weight.inspect}, length: #{@length.inspect}, height:"\
  " #{@height.inspect}, thickness: #{@thickness.inspect}, processing_category:"\
  " #{@processing_category.inspect}, mailing_date: #{@mailing_date.inspect},"\
  " non_machinable_indicators: #{@non_machinable_indicators.inspect}, extra_services:"\
  " #{@extra_services.inspect}, item_value: #{@item_value.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



171
172
173
174
175
176
177
# File 'lib/usps_api/models/letter_rates_query.rb', line 171

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} weight: #{@weight}, length: #{@length}, height: #{@height}, thickness:"\
  " #{@thickness}, processing_category: #{@processing_category}, mailing_date:"\
  " #{@mailing_date}, non_machinable_indicators: #{@non_machinable_indicators},"\
  " extra_services: #{@extra_services}, item_value: #{@item_value}>"
end