Class: UspsApi::PricesLetterRates

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

Overview

Rate Details for the request letter search criteria.

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(sku: SKIP, description: SKIP, price_type: SKIP, price: SKIP, weight: SKIP, fees: SKIP, start_date: SKIP, end_date: SKIP, mail_class: SKIP, extra_services: SKIP, warnings: SKIP, additional_properties: nil) ⇒ PricesLetterRates

Returns a new instance of PricesLetterRates.



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

def initialize(sku: SKIP, description: SKIP, price_type: SKIP, price: SKIP,
               weight: SKIP, fees: SKIP, start_date: SKIP, end_date: SKIP,
               mail_class: SKIP, extra_services: SKIP, warnings: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @sku = sku unless sku == SKIP
  @description = description unless description == SKIP
  @price_type = price_type unless price_type == SKIP
  @price = price unless price == SKIP
  @weight = weight unless weight == SKIP
  @fees = fees unless fees == SKIP
  @start_date = start_date unless start_date == SKIP
  @end_date = end_date unless end_date == SKIP
  @mail_class = mail_class unless mail_class == SKIP
  @extra_services = extra_services unless extra_services == SKIP
  @warnings = warnings unless warnings == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#descriptionString

The description of the price.

Returns:

  • (String)


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

def description
  @description
end

#end_dateString

Effective end date of the rate. If blank the rate doesn’t have an end date as of yet.

Returns:

  • (String)


44
45
46
# File 'lib/usps_api/models/prices_letter_rates.rb', line 44

def end_date
  @end_date
end

#extra_servicesArray[PricesExtraServiceRateDetail]

The extra service rate details that match the search criteria.

Returns:



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

def extra_services
  @extra_services
end

#feesArray[Fee1]

The fees associated with the package.

Returns:



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

def fees
  @fees
end

#mail_classMailClass3

The mail class of the price.

Returns:



48
49
50
# File 'lib/usps_api/models/prices_letter_rates.rb', line 48

def mail_class
  @mail_class
end

#priceFloat

The postage price.

Returns:

  • (Float)


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

def price
  @price
end

#price_typePriceType3

The type of price type applied (Retail).

Returns:



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

def price_type
  @price_type
end

#skuString

The stock keeping unit for the designated rate.

Returns:

  • (String)


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

def sku
  @sku
end

#start_dateDate

Effective start date of the rate.

Returns:

  • (Date)


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

def start_date
  @start_date
end

#warningsArray[String]

List of warnings

Returns:

  • (Array[String])


56
57
58
# File 'lib/usps_api/models/prices_letter_rates.rb', line 56

def warnings
  @warnings
end

#weightFloat

The calculated weight for the package based on user input. The greater of dimWeight and weight will be used to calculated the rate.

Returns:

  • (Float)


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

def weight
  @weight
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
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
169
170
171
172
173
# File 'lib/usps_api/models/prices_letter_rates.rb', line 119

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  sku = hash.key?('SKU') ? hash['SKU'] : SKIP
  description = hash.key?('description') ? hash['description'] : SKIP
  price_type = hash.key?('priceType') ? hash['priceType'] : SKIP
  price = hash.key?('price') ? hash['price'] : SKIP
  weight = hash.key?('weight') ? hash['weight'] : SKIP
  # Parameter is an array, so we need to iterate through it
  fees = nil
  unless hash['fees'].nil?
    fees = []
    hash['fees'].each do |structure|
      fees << (Fee1.from_hash(structure) if structure)
    end
  end

  fees = SKIP unless hash.key?('fees')
  start_date = hash.key?('startDate') ? hash['startDate'] : SKIP
  end_date = hash.key?('endDate') ? hash['endDate'] : SKIP
  mail_class = hash.key?('mailClass') ? hash['mailClass'] : SKIP
  # Parameter is an array, so we need to iterate through it
  extra_services = nil
  unless hash['extraServices'].nil?
    extra_services = []
    hash['extraServices'].each do |structure|
      extra_services << (PricesExtraServiceRateDetail.from_hash(structure) if structure)
    end
  end

  extra_services = SKIP unless hash.key?('extraServices')
  warnings = hash.key?('warnings') ? hash['warnings'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  PricesLetterRates.new(sku: sku,
                        description: description,
                        price_type: price_type,
                        price: price,
                        weight: weight,
                        fees: fees,
                        start_date: start_date,
                        end_date: end_date,
                        mail_class: mail_class,
                        extra_services: extra_services,
                        warnings: warnings,
                        additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/usps_api/models/prices_letter_rates.rb', line 59

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['sku'] = 'SKU'
  @_hash['description'] = 'description'
  @_hash['price_type'] = 'priceType'
  @_hash['price'] = 'price'
  @_hash['weight'] = 'weight'
  @_hash['fees'] = 'fees'
  @_hash['start_date'] = 'startDate'
  @_hash['end_date'] = 'endDate'
  @_hash['mail_class'] = 'mailClass'
  @_hash['extra_services'] = 'extraServices'
  @_hash['warnings'] = 'warnings'
  @_hash
end

.nullablesObject

An array for nullable fields



93
94
95
# File 'lib/usps_api/models/prices_letter_rates.rb', line 93

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    sku
    description
    price_type
    price
    weight
    fees
    start_date
    end_date
    mail_class
    extra_services
    warnings
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



185
186
187
188
189
190
191
192
# File 'lib/usps_api/models/prices_letter_rates.rb', line 185

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} sku: #{@sku.inspect}, description: #{@description.inspect}, price_type:"\
  " #{@price_type.inspect}, price: #{@price.inspect}, weight: #{@weight.inspect}, fees:"\
  " #{@fees.inspect}, start_date: #{@start_date.inspect}, end_date: #{@end_date.inspect},"\
  " mail_class: #{@mail_class.inspect}, extra_services: #{@extra_services.inspect}, warnings:"\
  " #{@warnings.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



176
177
178
179
180
181
182
# File 'lib/usps_api/models/prices_letter_rates.rb', line 176

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} sku: #{@sku}, description: #{@description}, price_type: #{@price_type},"\
  " price: #{@price}, weight: #{@weight}, fees: #{@fees}, start_date: #{@start_date},"\
  " end_date: #{@end_date}, mail_class: #{@mail_class}, extra_services: #{@extra_services},"\
  " warnings: #{@warnings}, additional_properties: #{@additional_properties}>"
end