Class: UspsApi::RateOptions

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

Overview

Options used to determine the rate

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_price: SKIP, total_base_price: SKIP, rates: SKIP, extra_services: SKIP, additional_properties: nil) ⇒ RateOptions

Returns a new instance of RateOptions.



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

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

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

Instance Attribute Details

#extra_servicesArray[ExtraService6]

Extra services requested on the package.

Returns:



30
31
32
# File 'lib/usps_api/models/rate_options.rb', line 30

def extra_services
  @extra_services
end

#ratesArray[Rate]

List of available rates for the package including base postage and extra service fees

Returns:



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

def rates
  @rates
end

#total_base_priceFloat

The price of the rate, fees, and pound postage.

Returns:

  • (Float)


21
22
23
# File 'lib/usps_api/models/rate_options.rb', line 21

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)


17
18
19
# File 'lib/usps_api/models/rate_options.rb', line 17

def total_price
  @total_price
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
111
# File 'lib/usps_api/models/rate_options.rb', line 70

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  total_price = hash.key?('totalPrice') ? hash['totalPrice'] : SKIP
  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 << (Rate.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 << (ExtraService6.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.
  RateOptions.new(total_price: total_price,
                  total_base_price: total_base_price,
                  rates: rates,
                  extra_services: extra_services,
                  additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



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

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

.nullablesObject

An array for nullable fields



53
54
55
# File 'lib/usps_api/models/rate_options.rb', line 53

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

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

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



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

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

#to_sObject

Provides a human-readable string representation of the object.



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

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