Class: WalmartApIs::Product

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

Overview

An item.

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(identifiers:, attribute_sets: SKIP, relationships: SKIP, competitive_pricing: SKIP, sales_rankings: SKIP, offers: SKIP, additional_properties: nil) ⇒ Product

Returns a new instance of Product.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/walmart_ap_is/models/product.rb', line 64

def initialize(identifiers:, attribute_sets: SKIP, relationships: SKIP,
               competitive_pricing: SKIP, sales_rankings: SKIP,
               offers: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @identifiers = identifiers
  @attribute_sets = attribute_sets unless attribute_sets == SKIP
  @relationships = relationships unless relationships == SKIP
  @competitive_pricing = competitive_pricing unless competitive_pricing == SKIP
  @sales_rankings = sales_rankings unless sales_rankings == SKIP
  @offers = offers unless offers == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#attribute_setsArray[Object]

A list of product attributes if applicable.

Returns:

  • (Array[Object])


18
19
20
# File 'lib/walmart_ap_is/models/product.rb', line 18

def attribute_sets
  @attribute_sets
end

#competitive_pricingCompetitivePricingType

Competitive pricing information for the item.



26
27
28
# File 'lib/walmart_ap_is/models/product.rb', line 26

def competitive_pricing
  @competitive_pricing
end

#identifiersIdentifierType1

Specifies the identifiers used to uniquely identify an item.

Returns:



14
15
16
# File 'lib/walmart_ap_is/models/product.rb', line 14

def identifiers
  @identifiers
end

#offersArray[OfferType1]

A list of offers.

Returns:



34
35
36
# File 'lib/walmart_ap_is/models/product.rb', line 34

def offers
  @offers
end

#relationshipsArray[Object]

A list that contains product variation information, if applicable.

Returns:

  • (Array[Object])


22
23
24
# File 'lib/walmart_ap_is/models/product.rb', line 22

def relationships
  @relationships
end

#sales_rankingsArray[SalesRankType]

A list of sales rank information for the item, by category.

Returns:



30
31
32
# File 'lib/walmart_ap_is/models/product.rb', line 30

def sales_rankings
  @sales_rankings
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/walmart_ap_is/models/product.rb', line 80

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  identifiers = IdentifierType1.from_hash(hash['Identifiers']) if hash['Identifiers']
  attribute_sets = hash.key?('AttributeSets') ? hash['AttributeSets'] : SKIP
  relationships = hash.key?('Relationships') ? hash['Relationships'] : SKIP
  competitive_pricing = CompetitivePricingType.from_hash(hash['CompetitivePricing']) if
    hash['CompetitivePricing']
  # Parameter is an array, so we need to iterate through it
  sales_rankings = nil
  unless hash['SalesRankings'].nil?
    sales_rankings = []
    hash['SalesRankings'].each do |structure|
      sales_rankings << (SalesRankType.from_hash(structure) if structure)
    end
  end

  sales_rankings = SKIP unless hash.key?('SalesRankings')
  # Parameter is an array, so we need to iterate through it
  offers = nil
  unless hash['Offers'].nil?
    offers = []
    hash['Offers'].each do |structure|
      offers << (OfferType1.from_hash(structure) if structure)
    end
  end

  offers = SKIP unless hash.key?('Offers')

  # 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.
  Product.new(identifiers: identifiers,
              attribute_sets: attribute_sets,
              relationships: relationships,
              competitive_pricing: competitive_pricing,
              sales_rankings: sales_rankings,
              offers: offers,
              additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



37
38
39
40
41
42
43
44
45
46
# File 'lib/walmart_ap_is/models/product.rb', line 37

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['identifiers'] = 'Identifiers'
  @_hash['attribute_sets'] = 'AttributeSets'
  @_hash['relationships'] = 'Relationships'
  @_hash['competitive_pricing'] = 'CompetitivePricing'
  @_hash['sales_rankings'] = 'SalesRankings'
  @_hash['offers'] = 'Offers'
  @_hash
end

.nullablesObject

An array for nullable fields



60
61
62
# File 'lib/walmart_ap_is/models/product.rb', line 60

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    attribute_sets
    relationships
    competitive_pricing
    sales_rankings
    offers
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



137
138
139
140
141
142
143
# File 'lib/walmart_ap_is/models/product.rb', line 137

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} identifiers: #{@identifiers.inspect}, attribute_sets:"\
  " #{@attribute_sets.inspect}, relationships: #{@relationships.inspect}, competitive_pricing:"\
  " #{@competitive_pricing.inspect}, sales_rankings: #{@sales_rankings.inspect}, offers:"\
  " #{@offers.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



128
129
130
131
132
133
134
# File 'lib/walmart_ap_is/models/product.rb', line 128

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} identifiers: #{@identifiers}, attribute_sets: #{@attribute_sets},"\
  " relationships: #{@relationships}, competitive_pricing: #{@competitive_pricing},"\
  " sales_rankings: #{@sales_rankings}, offers: #{@offers}, additional_properties:"\
  " #{@additional_properties}>"
end