Class: WalmartApIs::Item
- Defined in:
- lib/walmart_ap_is/models/item.rb
Overview
Item Model.
Instance Attribute Summary collapse
-
#attributes ⇒ Hash[String, Object]
Key product attributes (name, brand, description, etc.).
-
#identifiers ⇒ ItemIdentifiers
Key product attributes (name, brand, description, etc.).
-
#images ⇒ Array[ItemImage]
Key product attributes (name, brand, description, etc.).
-
#marketplace_id ⇒ MarketplaceId
Walmart Product ID (WPID) — alphanumeric catalog identifier.
-
#product_types ⇒ Array[ItemProductType]
Key product attributes (name, brand, description, etc.).
-
#relationships ⇒ Array[ItemRelationship]
Variant relationships (e.g. color/size variants).
-
#sales_ranks ⇒ Array[SalesRank]
Key product attributes (name, brand, description, etc.).
-
#walmart_item_id ⇒ String
Walmart Product ID (WPID) — alphanumeric catalog identifier.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
Instance Method Summary collapse
-
#initialize(walmart_item_id:, marketplace_id:, attributes: SKIP, identifiers: SKIP, images: SKIP, product_types: SKIP, sales_ranks: SKIP, relationships: SKIP, additional_properties: nil) ⇒ Item
constructor
A new instance of Item.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
Methods inherited from BaseModel
#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json
Constructor Details
#initialize(walmart_item_id:, marketplace_id:, attributes: SKIP, identifiers: SKIP, images: SKIP, product_types: SKIP, sales_ranks: SKIP, relationships: SKIP, additional_properties: nil) ⇒ Item
Returns a new instance of Item.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/walmart_ap_is/models/item.rb', line 75 def initialize(walmart_item_id:, marketplace_id:, attributes: SKIP, identifiers: SKIP, images: SKIP, product_types: SKIP, sales_ranks: SKIP, relationships: SKIP, additional_properties: nil) # Add additional model properties to the instance additional_properties = {} if additional_properties.nil? @walmart_item_id = walmart_item_id @marketplace_id = marketplace_id @attributes = attributes unless attributes == SKIP @identifiers = identifiers unless identifiers == SKIP @images = images unless images == SKIP @product_types = product_types unless product_types == SKIP @sales_ranks = sales_ranks unless sales_ranks == SKIP @relationships = relationships unless relationships == SKIP @additional_properties = additional_properties end |
Instance Attribute Details
#attributes ⇒ Hash[String, Object]
Key product attributes (name, brand, description, etc.)
22 23 24 |
# File 'lib/walmart_ap_is/models/item.rb', line 22 def attributes @attributes end |
#identifiers ⇒ ItemIdentifiers
Key product attributes (name, brand, description, etc.)
26 27 28 |
# File 'lib/walmart_ap_is/models/item.rb', line 26 def identifiers @identifiers end |
#images ⇒ Array[ItemImage]
Key product attributes (name, brand, description, etc.)
30 31 32 |
# File 'lib/walmart_ap_is/models/item.rb', line 30 def images @images end |
#marketplace_id ⇒ MarketplaceId
Walmart Product ID (WPID) — alphanumeric catalog identifier
18 19 20 |
# File 'lib/walmart_ap_is/models/item.rb', line 18 def marketplace_id @marketplace_id end |
#product_types ⇒ Array[ItemProductType]
Key product attributes (name, brand, description, etc.)
34 35 36 |
# File 'lib/walmart_ap_is/models/item.rb', line 34 def product_types @product_types end |
#relationships ⇒ Array[ItemRelationship]
Variant relationships (e.g. color/size variants)
42 43 44 |
# File 'lib/walmart_ap_is/models/item.rb', line 42 def relationships @relationships end |
#sales_ranks ⇒ Array[SalesRank]
Key product attributes (name, brand, description, etc.)
38 39 40 |
# File 'lib/walmart_ap_is/models/item.rb', line 38 def sales_ranks @sales_ranks end |
#walmart_item_id ⇒ String
Walmart Product ID (WPID) — alphanumeric catalog identifier
14 15 16 |
# File 'lib/walmart_ap_is/models/item.rb', line 14 def walmart_item_id @walmart_item_id end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
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 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/walmart_ap_is/models/item.rb', line 94 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. walmart_item_id = hash.key?('walmartItemId') ? hash['walmartItemId'] : nil marketplace_id = hash.key?('marketplaceId') ? hash['marketplaceId'] : nil attributes = hash.key?('attributes') ? hash['attributes'] : SKIP identifiers = ItemIdentifiers.from_hash(hash['identifiers']) if hash['identifiers'] # Parameter is an array, so we need to iterate through it images = nil unless hash['images'].nil? images = [] hash['images'].each do |structure| images << (ItemImage.from_hash(structure) if structure) end end images = SKIP unless hash.key?('images') # Parameter is an array, so we need to iterate through it product_types = nil unless hash['productTypes'].nil? product_types = [] hash['productTypes'].each do |structure| product_types << (ItemProductType.from_hash(structure) if structure) end end product_types = SKIP unless hash.key?('productTypes') # Parameter is an array, so we need to iterate through it sales_ranks = nil unless hash['salesRanks'].nil? sales_ranks = [] hash['salesRanks'].each do |structure| sales_ranks << (SalesRank.from_hash(structure) if structure) end end sales_ranks = SKIP unless hash.key?('salesRanks') # Parameter is an array, so we need to iterate through it relationships = nil unless hash['relationships'].nil? relationships = [] hash['relationships'].each do |structure| relationships << (ItemRelationship.from_hash(structure) if structure) end end relationships = SKIP unless hash.key?('relationships') # 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. Item.new(walmart_item_id: walmart_item_id, marketplace_id: marketplace_id, attributes: attributes, identifiers: identifiers, images: images, product_types: product_types, sales_ranks: sales_ranks, relationships: relationships, additional_properties: additional_properties) end |
.names ⇒ Object
A mapping from model property names to API property names.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/walmart_ap_is/models/item.rb', line 45 def self.names @_hash = {} if @_hash.nil? @_hash['walmart_item_id'] = 'walmartItemId' @_hash['marketplace_id'] = 'marketplaceId' @_hash['attributes'] = 'attributes' @_hash['identifiers'] = 'identifiers' @_hash['images'] = 'images' @_hash['product_types'] = 'productTypes' @_hash['sales_ranks'] = 'salesRanks' @_hash['relationships'] = 'relationships' @_hash end |
.nullables ⇒ Object
An array for nullable fields
71 72 73 |
# File 'lib/walmart_ap_is/models/item.rb', line 71 def self.nullables [] end |
.optionals ⇒ Object
An array for optional fields
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/walmart_ap_is/models/item.rb', line 59 def self.optionals %w[ attributes identifiers images product_types sales_ranks relationships ] end |
Instance Method Details
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
172 173 174 175 176 177 178 179 |
# File 'lib/walmart_ap_is/models/item.rb', line 172 def inspect class_name = self.class.name.split('::').last "<#{class_name} walmart_item_id: #{@walmart_item_id.inspect}, marketplace_id:"\ " #{@marketplace_id.inspect}, attributes: #{@attributes.inspect}, identifiers:"\ " #{@identifiers.inspect}, images: #{@images.inspect}, product_types:"\ " #{@product_types.inspect}, sales_ranks: #{@sales_ranks.inspect}, relationships:"\ " #{@relationships.inspect}, additional_properties: #{@additional_properties}>" end |
#to_s ⇒ Object
Provides a human-readable string representation of the object.
163 164 165 166 167 168 169 |
# File 'lib/walmart_ap_is/models/item.rb', line 163 def to_s class_name = self.class.name.split('::').last "<#{class_name} walmart_item_id: #{@walmart_item_id}, marketplace_id: #{@marketplace_id},"\ " attributes: #{@attributes}, identifiers: #{@identifiers}, images: #{@images},"\ " product_types: #{@product_types}, sales_ranks: #{@sales_ranks}, relationships:"\ " #{@relationships}, additional_properties: #{@additional_properties}>" end |