Class: UspsApi::PricesLetterRateDetails

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

Overview

Informative details about the price.

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, additional_properties: nil) ⇒ PricesLetterRateDetails

Returns a new instance of PricesLetterRateDetails.



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

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,
               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
  @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_rate_details.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_rate_details.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_rate_details.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_rate_details.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_rate_details.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_rate_details.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_rate_details.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_rate_details.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_rate_details.rb', line 39

def start_date
  @start_date
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_rate_details.rb', line 31

def weight
  @weight
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



112
113
114
115
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/usps_api/models/prices_letter_rate_details.rb', line 112

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')

  # 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.
  PricesLetterRateDetails.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,
                              additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/usps_api/models/prices_letter_rate_details.rb', line 55

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
end

.nullablesObject

An array for nullable fields



87
88
89
# File 'lib/usps_api/models/prices_letter_rate_details.rb', line 87

def self.nullables
  []
end

.optionalsObject

An array for optional fields



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/usps_api/models/prices_letter_rate_details.rb', line 71

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

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



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

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},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



167
168
169
170
171
172
173
# File 'lib/usps_api/models/prices_letter_rate_details.rb', line 167

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},"\
  " additional_properties: #{@additional_properties}>"
end