Class: UspsApi::RateOption

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

Overview

RateOption 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(total_base_price: SKIP, rates: SKIP, extra_services: SKIP, total_price: SKIP, additional_properties: nil) ⇒ RateOption

Returns a new instance of RateOption.



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

def initialize(total_base_price: SKIP, rates: SKIP, extra_services: SKIP,
               total_price: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @total_base_price = total_base_price unless total_base_price == SKIP
  @rates = rates unless rates == SKIP
  @extra_services = extra_services unless extra_services == SKIP
  @total_price = total_price unless total_price == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#extra_servicesArray[PricesExtraServiceRateDetails]

List of extra services associated with the shipment.

Returns:



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

def extra_services
  @extra_services
end

#ratesArray[PricesRateDetails]

List of rate details

Returns:



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

def rates
  @rates
end

#total_base_priceFloat

The total price, including the rate, fees and pound postage.

Returns:

  • (Float)


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

def total_base_price
  @total_base_price
end

#total_priceFloat

The total price, including the ‘totalBasePrice` and all extra service prices. Note: This field is only returned when `extraServices` are passed in the request.

Returns:

  • (Float)


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

def total_price
  @total_price
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



69
70
71
72
73
74
75
76
77
78
79
80
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
# File 'lib/usps_api/models/rate_option.rb', line 69

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  total_base_price =
    hash.key?('totalBasePrice') ? hash['totalBasePrice'] : SKIP
  # Parameter is an array, so we need to iterate through it
  rates = nil
  unless hash['rates'].nil?
    rates = []
    hash['rates'].each do |structure|
      rates << (PricesRateDetails.from_hash(structure) if structure)
    end
  end

  rates = SKIP unless hash.key?('rates')
  # 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 << (PricesExtraServiceRateDetails.from_hash(structure) if structure)
    end
  end

  extra_services = SKIP unless hash.key?('extraServices')
  total_price = hash.key?('totalPrice') ? hash['totalPrice'] : 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.
  RateOption.new(total_base_price: total_base_price,
                 rates: rates,
                 extra_services: extra_services,
                 total_price: total_price,
                 additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



32
33
34
35
36
37
38
39
# File 'lib/usps_api/models/rate_option.rb', line 32

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['total_base_price'] = 'totalBasePrice'
  @_hash['rates'] = 'rates'
  @_hash['extra_services'] = 'extraServices'
  @_hash['total_price'] = 'totalPrice'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



42
43
44
45
46
47
48
49
# File 'lib/usps_api/models/rate_option.rb', line 42

def self.optionals
  %w[
    total_base_price
    rates
    extra_services
    total_price
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



121
122
123
124
125
126
# File 'lib/usps_api/models/rate_option.rb', line 121

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} total_base_price: #{@total_base_price.inspect}, rates: #{@rates.inspect},"\
  " extra_services: #{@extra_services.inspect}, total_price: #{@total_price.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



113
114
115
116
117
118
# File 'lib/usps_api/models/rate_option.rb', line 113

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} total_base_price: #{@total_base_price}, rates: #{@rates}, extra_services:"\
  " #{@extra_services}, total_price: #{@total_price}, additional_properties:"\
  " #{@additional_properties}>"
end