Class: UspsApi::RateOption1

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

Overview

RateOption1 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, duties_taxes_fees_quote: SKIP, extra_services: SKIP, total_price: SKIP, additional_properties: nil) ⇒ RateOption1

Returns a new instance of RateOption1.



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

def initialize(total_base_price: SKIP, rates: SKIP,
               duties_taxes_fees_quote: 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
  @duties_taxes_fees_quote = duties_taxes_fees_quote unless duties_taxes_fees_quote == 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

#duties_taxes_fees_quoteDutiesTaxesFeesQuote

The duties, taxes, and fees details. Included if ‘requestDutiesTaxesFees` is `true` and the shipping destination has applicable duties, taxes, and fees.



24
25
26
# File 'lib/usps_api/models/rate_option1.rb', line 24

def duties_taxes_fees_quote
  @duties_taxes_fees_quote
end

#extra_servicesArray[ExtraService3]

A list of Extra Services to be included in the total rates search. If no extra services are specified all applicable extra services for the mail class will be returned.

Returns:



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

def extra_services
  @extra_services
end

#ratesArray[InternationalPricesRateDetails]

List of rate details, including SKU, description and rate ingredients

Returns:



18
19
20
# File 'lib/usps_api/models/rate_option1.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_option1.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)


37
38
39
# File 'lib/usps_api/models/rate_option1.rb', line 37

def total_price
  @total_price
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
117
118
119
120
121
122
123
124
125
# File 'lib/usps_api/models/rate_option1.rb', line 81

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 << (InternationalPricesRateDetails.from_hash(structure) if structure)
    end
  end

  rates = SKIP unless hash.key?('rates')
  duties_taxes_fees_quote = DutiesTaxesFeesQuote.from_hash(hash['dutiesTaxesFeesQuote']) if
    hash['dutiesTaxesFeesQuote']
  # 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 << (ExtraService3.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.
  RateOption1.new(total_base_price: total_base_price,
                  rates: rates,
                  duties_taxes_fees_quote: duties_taxes_fees_quote,
                  extra_services: extra_services,
                  total_price: total_price,
                  additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



40
41
42
43
44
45
46
47
48
# File 'lib/usps_api/models/rate_option1.rb', line 40

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

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

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

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



136
137
138
139
140
141
142
# File 'lib/usps_api/models/rate_option1.rb', line 136

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} total_base_price: #{@total_base_price.inspect}, rates: #{@rates.inspect},"\
  " duties_taxes_fees_quote: #{@duties_taxes_fees_quote.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.



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

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