Class: WalmartApIs::Quote

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/walmart_ap_is/models/quote.rb

Overview

The estimated shipping cost associated with the transportation option.

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(cost:, expiration: SKIP, voidable_until: SKIP, additional_properties: nil) ⇒ Quote

Returns a new instance of Quote.



48
49
50
51
52
53
54
55
56
57
# File 'lib/walmart_ap_is/models/quote.rb', line 48

def initialize(cost:, expiration: SKIP, voidable_until: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @cost = cost
  @expiration = expiration unless expiration == SKIP
  @voidable_until = voidable_until unless voidable_until == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#costCurrency

The type and amount of currency.

Returns:



15
16
17
# File 'lib/walmart_ap_is/models/quote.rb', line 15

def cost
  @cost
end

#expirationDateTime

The time at which this transportation option quote expires. In ISO 8601 datetime with pattern yyyy-MM-ddTHH:mm:ss.sssZ.

Returns:

  • (DateTime)


20
21
22
# File 'lib/walmart_ap_is/models/quote.rb', line 20

def expiration
  @expiration
end

#voidable_untilDateTime

Voidable until timestamp.

Returns:

  • (DateTime)


24
25
26
# File 'lib/walmart_ap_is/models/quote.rb', line 24

def voidable_until
  @voidable_until
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/walmart_ap_is/models/quote.rb', line 60

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  cost = Currency.from_hash(hash['cost']) if hash['cost']
  expiration = if hash.key?('expiration')
                 (DateTimeHelper.from_rfc3339(hash['expiration']) if hash['expiration'])
               else
                 SKIP
               end
  voidable_until = if hash.key?('voidableUntil')
                     (DateTimeHelper.from_rfc3339(hash['voidableUntil']) if hash['voidableUntil'])
                   else
                     SKIP
                   end

  # 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.
  Quote.new(cost: cost,
            expiration: expiration,
            voidable_until: voidable_until,
            additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



27
28
29
30
31
32
33
# File 'lib/walmart_ap_is/models/quote.rb', line 27

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['cost'] = 'cost'
  @_hash['expiration'] = 'expiration'
  @_hash['voidable_until'] = 'voidableUntil'
  @_hash
end

.nullablesObject

An array for nullable fields



44
45
46
# File 'lib/walmart_ap_is/models/quote.rb', line 44

def self.nullables
  []
end

.optionalsObject

An array for optional fields



36
37
38
39
40
41
# File 'lib/walmart_ap_is/models/quote.rb', line 36

def self.optionals
  %w[
    expiration
    voidable_until
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



106
107
108
109
110
# File 'lib/walmart_ap_is/models/quote.rb', line 106

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} cost: #{@cost.inspect}, expiration: #{@expiration.inspect}, voidable_until:"\
  " #{@voidable_until.inspect}, additional_properties: #{@additional_properties}>"
end

#to_custom_expirationObject



90
91
92
# File 'lib/walmart_ap_is/models/quote.rb', line 90

def to_custom_expiration
  DateTimeHelper.to_rfc3339(expiration)
end

#to_custom_voidable_untilObject



94
95
96
# File 'lib/walmart_ap_is/models/quote.rb', line 94

def to_custom_voidable_until
  DateTimeHelper.to_rfc3339(voidable_until)
end

#to_sObject

Provides a human-readable string representation of the object.



99
100
101
102
103
# File 'lib/walmart_ap_is/models/quote.rb', line 99

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} cost: #{@cost}, expiration: #{@expiration}, voidable_until:"\
  " #{@voidable_until}, additional_properties: #{@additional_properties}>"
end