Class: WalmartApIs::PriceType

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

Overview

Item price information. LandedPrice = ListingPrice + Shipping. Walmart does not have a seller-configurable per-offer loyalty points mechanism; the Points field from the SP-API reference spec is omitted. See ADR-030.

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(listing_price:, landed_price: SKIP, shipping: SKIP, additional_properties: nil) ⇒ PriceType

Returns a new instance of PriceType.



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

def initialize(listing_price:, landed_price: SKIP, shipping: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @landed_price = landed_price unless landed_price == SKIP
  @listing_price = listing_price
  @shipping = shipping unless shipping == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#landed_priceMoneyType

Currency type and monetary value.

Returns:



16
17
18
# File 'lib/walmart_ap_is/models/price_type.rb', line 16

def landed_price
  @landed_price
end

#listing_priceMoneyType

Currency type and monetary value.

Returns:



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

def listing_price
  @listing_price
end

#shippingMoneyType

Currency type and monetary value.

Returns:



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

def shipping
  @shipping
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
# File 'lib/walmart_ap_is/models/price_type.rb', line 60

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  listing_price = MoneyType.from_hash(hash['ListingPrice']) if hash['ListingPrice']
  landed_price = MoneyType.from_hash(hash['LandedPrice']) if hash['LandedPrice']
  shipping = MoneyType.from_hash(hash['Shipping']) if hash['Shipping']

  # 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.
  PriceType.new(listing_price: listing_price,
                landed_price: landed_price,
                shipping: shipping,
                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/price_type.rb', line 27

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['landed_price'] = 'LandedPrice'
  @_hash['listing_price'] = 'ListingPrice'
  @_hash['shipping'] = 'Shipping'
  @_hash
end

.nullablesObject

An array for nullable fields



44
45
46
# File 'lib/walmart_ap_is/models/price_type.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/price_type.rb', line 36

def self.optionals
  %w[
    landed_price
    shipping
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



90
91
92
93
94
95
# File 'lib/walmart_ap_is/models/price_type.rb', line 90

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

#to_sObject

Provides a human-readable string representation of the object.



83
84
85
86
87
# File 'lib/walmart_ap_is/models/price_type.rb', line 83

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