Class: UspsApi::RateListQuery

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

Overview

Informative details about all possible prices based on the ingredients.

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(origin_zip_code:, destination_zip_code:, weight:, length:, width:, height:, mail_class: SKIP, mail_classes: SKIP, price_type: SKIP, mailing_date: SKIP, account_type: SKIP, account_number: SKIP, has_nonstandard_characteristics: false) ⇒ RateListQuery

Returns a new instance of RateListQuery.



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/usps_api/models/rate_list_query.rb', line 137

def initialize(origin_zip_code:, destination_zip_code:, weight:, length:,
               width:, height:, mail_class: SKIP, mail_classes: SKIP,
               price_type: SKIP, mailing_date: SKIP, account_type: SKIP,
               account_number: SKIP, has_nonstandard_characteristics: false)
  @origin_zip_code = origin_zip_code
  @destination_zip_code = destination_zip_code
  @weight = weight
  @length = length
  @width = width
  @height = height
  @mail_class = mail_class unless mail_class == SKIP
  @mail_classes = mail_classes unless mail_classes == SKIP
  @price_type = price_type unless price_type == SKIP
  @mailing_date = mailing_date unless mailing_date == SKIP
  @account_type =  unless  == SKIP
  @account_number =  unless  == SKIP
  unless has_nonstandard_characteristics == SKIP
    @has_nonstandard_characteristics =
      has_nonstandard_characteristics
  end
end

Instance Attribute Details

#account_numberString

The Enterprise Payment Account, Permit number or PC Postage meter number associated with a contract.

Returns:

  • (String)


89
90
91
# File 'lib/usps_api/models/rate_list_query.rb', line 89

def 
  @account_number
end

#account_typeAccountType1

The type of payment account linked to a contract rate.

Returns:



84
85
86
# File 'lib/usps_api/models/rate_list_query.rb', line 84

def 
  @account_type
end

#destination_zip_codeString

The destination ZIP code for the package.

Returns:

  • (String)


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

def destination_zip_code
  @destination_zip_code
end

#has_nonstandard_characteristicsTrueClass | FalseClass

Package is nonstandard. Nonstandard packages include cylindrical tubes and rolls, certain high-density items, cartons containing more than 24 ounces of liquids in one or more glass containers, cartons containing 1 gallon or more of liquid in metal or plastic containers, and items in [201.7.6.2](pe.usps.com/text/dmm300/201.htm#7.6.2).

Returns:

  • (TrueClass | FalseClass)


97
98
99
# File 'lib/usps_api/models/rate_list_query.rb', line 97

def has_nonstandard_characteristics
  @has_nonstandard_characteristics
end

#heightFloat

This is the package height in inches.

Returns:

  • (Float)


38
39
40
# File 'lib/usps_api/models/rate_list_query.rb', line 38

def height
  @height
end

#lengthFloat

This is the package length in inches. The maximum dimension is always length.

Returns:

  • (Float)


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

def length
  @length
end

#mail_classMailClassOutboundOnly

The mail service requested.

Note:
- A single mail class option is deprecated and will be removed in the

next major revision. This attribute will be replaced with the list of mail classes.

- `PARCEL_SELECT_LIGHTWEIGHT` is deprecated and will convert to

‘PARCEL_SELECT`

- `FIRST-CLASS_PACKAGE_SERVICE` is deprecated and will convert to

‘USPS_GROUND_ADVANTAGE`

- `USPS_RETAIL_GROUND` is no longer supported and will return a 400 if

used



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

def mail_class
  @mail_class
end

#mail_classesArray[MailClassOutboundOnly]

A list of mail classes. Note:

  • ‘PARCEL_SELECT_LIGHTWEIGHT` is deprecated and will convert to

‘PARCEL_SELECT`.

  • ‘FIRST-CLASS_PACKAGE_SERVICE` is deprecated and will convert to

‘USPS_GROUND_ADVANTAGE`.

  • ‘USPS_RETAIL_GROUND` is no longer supported and will return a 400 if

used.

  • Certain mail classes, such as ‘MEDIA_MAIL`, `BOUND_PRINTED_MATTER`, and

‘LIBRARY_MAIL`, have eligibility rules on what can be mailed using that service. For more details on these mail classes, please visit [What are Package Services?](faq.usps.com/s/article/What-are-Package-Services).

Returns:



68
69
70
# File 'lib/usps_api/models/rate_list_query.rb', line 68

def mail_classes
  @mail_classes
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)


80
81
82
# File 'lib/usps_api/models/rate_list_query.rb', line 80

def mailing_date
  @mailing_date
end

#origin_zip_codeString

The originating ZIP code for the package.

Returns:

  • (String)


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

def origin_zip_code
  @origin_zip_code
end

#price_typePricesPriceType

Price type can be * ‘RETAIL’ * ‘COMMERCIAL’ * ‘CONTRACT’ * ‘NSA’ (deprecated)

Returns:



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

def price_type
  @price_type
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 pounds.

Returns:

  • (Float)


24
25
26
# File 'lib/usps_api/models/rate_list_query.rb', line 24

def weight
  @weight
end

#widthFloat

This is the package width in inches. The second longest dimension is always width.

Returns:

  • (Float)


34
35
36
# File 'lib/usps_api/models/rate_list_query.rb', line 34

def width
  @width
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  origin_zip_code = hash.key?('originZIPCode') ? hash['originZIPCode'] : nil
  destination_zip_code =
    hash.key?('destinationZIPCode') ? hash['destinationZIPCode'] : nil
  weight = hash.key?('weight') ? hash['weight'] : nil
  length = hash.key?('length') ? hash['length'] : nil
  width = hash.key?('width') ? hash['width'] : nil
  height = hash.key?('height') ? hash['height'] : nil
  mail_class = hash.key?('mailClass') ? hash['mailClass'] : SKIP
  mail_classes = hash.key?('mailClasses') ? hash['mailClasses'] : SKIP
  price_type = hash.key?('priceType') ? hash['priceType'] : SKIP
  mailing_date = hash.key?('mailingDate') ? hash['mailingDate'] : SKIP
   = hash.key?('accountType') ? hash['accountType'] : SKIP
   = hash.key?('accountNumber') ? hash['accountNumber'] : SKIP
  has_nonstandard_characteristics =
    hash['hasNonstandardCharacteristics'] ||= false

  # Create object from extracted values.
  RateListQuery.new(origin_zip_code: origin_zip_code,
                    destination_zip_code: destination_zip_code,
                    weight: weight,
                    length: length,
                    width: width,
                    height: height,
                    mail_class: mail_class,
                    mail_classes: mail_classes,
                    price_type: price_type,
                    mailing_date: mailing_date,
                    account_type: ,
                    account_number: ,
                    has_nonstandard_characteristics: has_nonstandard_characteristics)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['origin_zip_code'] = 'originZIPCode'
  @_hash['destination_zip_code'] = 'destinationZIPCode'
  @_hash['weight'] = 'weight'
  @_hash['length'] = 'length'
  @_hash['width'] = 'width'
  @_hash['height'] = 'height'
  @_hash['mail_class'] = 'mailClass'
  @_hash['mail_classes'] = 'mailClasses'
  @_hash['price_type'] = 'priceType'
  @_hash['mailing_date'] = 'mailingDate'
  @_hash['account_type'] = 'accountType'
  @_hash['account_number'] = 'accountNumber'
  @_hash['has_nonstandard_characteristics'] =
    'hasNonstandardCharacteristics'
  @_hash
end

.nullablesObject

An array for nullable fields



133
134
135
# File 'lib/usps_api/models/rate_list_query.rb', line 133

def self.nullables
  []
end

.optionalsObject

An array for optional fields



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/usps_api/models/rate_list_query.rb', line 120

def self.optionals
  %w[
    mail_class
    mail_classes
    price_type
    mailing_date
    account_type
    account_number
    has_nonstandard_characteristics
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



208
209
210
211
212
213
214
215
216
217
# File 'lib/usps_api/models/rate_list_query.rb', line 208

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} origin_zip_code: #{@origin_zip_code.inspect}, destination_zip_code:"\
  " #{@destination_zip_code.inspect}, weight: #{@weight.inspect}, length: #{@length.inspect},"\
  " width: #{@width.inspect}, height: #{@height.inspect}, mail_class: #{@mail_class.inspect},"\
  " mail_classes: #{@mail_classes.inspect}, price_type: #{@price_type.inspect}, mailing_date:"\
  " #{@mailing_date.inspect}, account_type: #{@account_type.inspect}, account_number:"\
  " #{@account_number.inspect}, has_nonstandard_characteristics:"\
  " #{@has_nonstandard_characteristics.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



197
198
199
200
201
202
203
204
205
# File 'lib/usps_api/models/rate_list_query.rb', line 197

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} origin_zip_code: #{@origin_zip_code}, destination_zip_code:"\
  " #{@destination_zip_code}, weight: #{@weight}, length: #{@length}, width: #{@width},"\
  " height: #{@height}, mail_class: #{@mail_class}, mail_classes: #{@mail_classes},"\
  " price_type: #{@price_type}, mailing_date: #{@mailing_date}, account_type:"\
  " #{@account_type}, account_number: #{@account_number}, has_nonstandard_characteristics:"\
  " #{@has_nonstandard_characteristics}>"
end