Class: UspsApi::PricesExtraServiceRateDetail

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

Overview

PricesExtraServiceRateDetail Model.

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(extra_service: SKIP, name: SKIP, sku: SKIP, price_type: SKIP, price: SKIP, warnings: SKIP, additional_properties: nil) ⇒ PricesExtraServiceRateDetail

Returns a new instance of PricesExtraServiceRateDetail.



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/usps_api/models/prices_extra_service_rate_detail.rb', line 66

def initialize(extra_service: SKIP, name: SKIP, sku: SKIP, price_type: SKIP,
               price: SKIP, warnings: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @extra_service = extra_service unless extra_service == SKIP
  @name = name unless name == SKIP
  @sku = sku unless sku == SKIP
  @price_type = price_type unless price_type == SKIP
  @price = price unless price == SKIP
  @warnings = warnings unless warnings == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#extra_serviceString

Number associated with the extra service

Returns:

  • (String)


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

def extra_service
  @extra_service
end

#nameString

Name of the extra service.

Returns:

  • (String)


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

def name
  @name
end

#priceFloat

The postage rate.

Returns:

  • (Float)


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

def price
  @price
end

#price_typePriceType1

The type of price applied (Retail, Commercial, Contract, NSA (deprecated)).

Returns:



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

def price_type
  @price_type
end

#skuString

The stock keeping unit for the designated rate.

Returns:

  • (String)


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

def sku
  @sku
end

#warningsArray[ContainersContainerWarnings]

A list of warnings associated with the rate calculation.

Returns:



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

def warnings
  @warnings
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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_extra_service_rate_detail.rb', line 81

def self.from_hash(hash)
  return nil unless hash

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

  warnings = SKIP unless hash.key?('warnings')

  # 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.
  PricesExtraServiceRateDetail.new(extra_service: extra_service,
                                   name: name,
                                   sku: sku,
                                   price_type: price_type,
                                   price: price,
                                   warnings: warnings,
                                   additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



38
39
40
41
42
43
44
45
46
47
# File 'lib/usps_api/models/prices_extra_service_rate_detail.rb', line 38

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['extra_service'] = 'extraService'
  @_hash['name'] = 'name'
  @_hash['sku'] = 'SKU'
  @_hash['price_type'] = 'priceType'
  @_hash['price'] = 'price'
  @_hash['warnings'] = 'warnings'
  @_hash
end

.nullablesObject

An array for nullable fields



62
63
64
# File 'lib/usps_api/models/prices_extra_service_rate_detail.rb', line 62

def self.nullables
  []
end

.optionalsObject

An array for optional fields



50
51
52
53
54
55
56
57
58
59
# File 'lib/usps_api/models/prices_extra_service_rate_detail.rb', line 50

def self.optionals
  %w[
    extra_service
    name
    sku
    price_type
    price
    warnings
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



127
128
129
130
131
132
# File 'lib/usps_api/models/prices_extra_service_rate_detail.rb', line 127

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} extra_service: #{@extra_service.inspect}, name: #{@name.inspect}, sku:"\
  " #{@sku.inspect}, price_type: #{@price_type.inspect}, price: #{@price.inspect}, warnings:"\
  " #{@warnings.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



119
120
121
122
123
124
# File 'lib/usps_api/models/prices_extra_service_rate_detail.rb', line 119

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} extra_service: #{@extra_service}, name: #{@name}, sku: #{@sku}, price_type:"\
  " #{@price_type}, price: #{@price}, warnings: #{@warnings}, additional_properties:"\
  " #{@additional_properties}>"
end