Class: Zernio::Product

Inherits:
ApiModelBase show all
Defined in:
lib/zernio-sdk/models/product.rb

Overview

A product on the connected platform with its variants, options and images. All data lives on the platform; Zernio proxies it and stores nothing.

Defined Under Namespace

Classes: EnumAttributeValidator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApiModelBase

_deserialize, #_to_hash, #to_body, #to_s

Constructor Details

#initialize(attributes = {}) ⇒ Product

Initializes the object

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes in the form of hash



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/zernio-sdk/models/product.rb', line 164

def initialize(attributes = {})
  if (!attributes.is_a?(Hash))
    fail ArgumentError, "The input argument (attributes) must be a hash in `Zernio::Product` initialize method"
  end

  # check to see if the attribute exists and convert string to symbol for hash key
  acceptable_attribute_map = self.class.acceptable_attribute_map
  attributes = attributes.each_with_object({}) { |(k, v), h|
    if (!acceptable_attribute_map.key?(k.to_sym))
      fail ArgumentError, "`#{k}` is not a valid attribute in `Zernio::Product`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
    end
    h[k.to_sym] = v
  }

  if attributes.key?(:'id')
    self.id = attributes[:'id']
  end

  if attributes.key?(:'platform')
    self.platform = attributes[:'platform']
  end

  if attributes.key?(:'title')
    self.title = attributes[:'title']
  end

  if attributes.key?(:'handle')
    self.handle = attributes[:'handle']
  end

  if attributes.key?(:'description_html')
    self.description_html = attributes[:'description_html']
  end

  if attributes.key?(:'vendor')
    self.vendor = attributes[:'vendor']
  end

  if attributes.key?(:'product_type')
    self.product_type = attributes[:'product_type']
  end

  if attributes.key?(:'tags')
    if (value = attributes[:'tags']).is_a?(Array)
      self.tags = value
    end
  end

  if attributes.key?(:'status')
    self.status = attributes[:'status']
  end

  if attributes.key?(:'featured_image')
    self.featured_image = attributes[:'featured_image']
  end

  if attributes.key?(:'images')
    if (value = attributes[:'images']).is_a?(Array)
      self.images = value
    end
  end

  if attributes.key?(:'options')
    if (value = attributes[:'options']).is_a?(Array)
      self.options = value
    end
  end

  if attributes.key?(:'variants')
    if (value = attributes[:'variants']).is_a?(Array)
      self.variants = value
    end
  end

  if attributes.key?(:'seo')
    self.seo = attributes[:'seo']
  end

  if attributes.key?(:'total_inventory')
    self.total_inventory = attributes[:'total_inventory']
  end

  if attributes.key?(:'online_store_url')
    self.online_store_url = attributes[:'online_store_url']
  end

  if attributes.key?(:'created_at')
    self.created_at = attributes[:'created_at']
  end

  if attributes.key?(:'updated_at')
    self.updated_at = attributes[:'updated_at']
  end

  if attributes.key?(:'published_at')
    self.published_at = attributes[:'published_at']
  end
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



59
60
61
# File 'lib/zernio-sdk/models/product.rb', line 59

def created_at
  @created_at
end

#description_htmlObject

Product description as HTML.



30
31
32
# File 'lib/zernio-sdk/models/product.rb', line 30

def description_html
  @description_html
end

Returns the value of attribute featured_image.



41
42
43
# File 'lib/zernio-sdk/models/product.rb', line 41

def featured_image
  @featured_image
end

#handleObject

URL slug of the product.



27
28
29
# File 'lib/zernio-sdk/models/product.rb', line 27

def handle
  @handle
end

#idObject

Platform-native product id (numeric string for Shopify).



20
21
22
# File 'lib/zernio-sdk/models/product.rb', line 20

def id
  @id
end

#imagesObject

First 20 images in the product media, in store order.



44
45
46
# File 'lib/zernio-sdk/models/product.rb', line 44

def images
  @images
end

#online_store_urlObject

Public storefront URL; null while the product is not published to the online store.



57
58
59
# File 'lib/zernio-sdk/models/product.rb', line 57

def online_store_url
  @online_store_url
end

#optionsObject

Option axes (e.g. Size, Color) and their values.



47
48
49
# File 'lib/zernio-sdk/models/product.rb', line 47

def options
  @options
end

#platformObject

Returns the value of attribute platform.



22
23
24
# File 'lib/zernio-sdk/models/product.rb', line 22

def platform
  @platform
end

#product_typeObject

Free-text product type as set on the store.



35
36
37
# File 'lib/zernio-sdk/models/product.rb', line 35

def product_type
  @product_type
end

#published_atObject

Returns the value of attribute published_at.



63
64
65
# File 'lib/zernio-sdk/models/product.rb', line 63

def published_at
  @published_at
end

#seoObject

Returns the value of attribute seo.



52
53
54
# File 'lib/zernio-sdk/models/product.rb', line 52

def seo
  @seo
end

#statusObject

Returns the value of attribute status.



39
40
41
# File 'lib/zernio-sdk/models/product.rb', line 39

def status
  @status
end

#tagsObject

Returns the value of attribute tags.



37
38
39
# File 'lib/zernio-sdk/models/product.rb', line 37

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



24
25
26
# File 'lib/zernio-sdk/models/product.rb', line 24

def title
  @title
end

#total_inventoryObject

Returns the value of attribute total_inventory.



54
55
56
# File 'lib/zernio-sdk/models/product.rb', line 54

def total_inventory
  @total_inventory
end

#updated_atObject

Returns the value of attribute updated_at.



61
62
63
# File 'lib/zernio-sdk/models/product.rb', line 61

def updated_at
  @updated_at
end

#variantsObject

First 100 variants.



50
51
52
# File 'lib/zernio-sdk/models/product.rb', line 50

def variants
  @variants
end

#vendorObject

Returns the value of attribute vendor.



32
33
34
# File 'lib/zernio-sdk/models/product.rb', line 32

def vendor
  @vendor
end

Class Method Details

.acceptable_attribute_mapObject

Returns attribute mapping this model knows about



113
114
115
# File 'lib/zernio-sdk/models/product.rb', line 113

def self.acceptable_attribute_map
  attribute_map
end

.acceptable_attributesObject

Returns all the JSON keys this model knows about



118
119
120
# File 'lib/zernio-sdk/models/product.rb', line 118

def self.acceptable_attributes
  acceptable_attribute_map.values
end

.attribute_mapObject

Attribute mapping from ruby-style variable name to JSON key.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/zernio-sdk/models/product.rb', line 88

def self.attribute_map
  {
    :'id' => :'id',
    :'platform' => :'platform',
    :'title' => :'title',
    :'handle' => :'handle',
    :'description_html' => :'descriptionHtml',
    :'vendor' => :'vendor',
    :'product_type' => :'productType',
    :'tags' => :'tags',
    :'status' => :'status',
    :'featured_image' => :'featuredImage',
    :'images' => :'images',
    :'options' => :'options',
    :'variants' => :'variants',
    :'seo' => :'seo',
    :'total_inventory' => :'totalInventory',
    :'online_store_url' => :'onlineStoreUrl',
    :'created_at' => :'createdAt',
    :'updated_at' => :'updatedAt',
    :'published_at' => :'publishedAt'
  }
end

.build_from_hash(attributes) ⇒ Object

Builds the object from hash

Parameters:

  • attributes (Hash)

    Model attributes in the form of hash

Returns:

  • (Object)

    Returns the model itself



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/zernio-sdk/models/product.rb', line 343

def self.build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  attributes = attributes.transform_keys(&:to_sym)
  transformed_hash = {}
  openapi_types.each_pair do |key, type|
    if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = nil
    elsif type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the attribute
      # is documented as an array but the input is not
      if attributes[attribute_map[key]].is_a?(Array)
        transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
      end
    elsif !attributes[attribute_map[key]].nil?
      transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
    end
  end
  new(transformed_hash)
end

.openapi_nullableObject

List of attributes with nullable: true



148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/zernio-sdk/models/product.rb', line 148

def self.openapi_nullable
  Set.new([
    :'description_html',
    :'vendor',
    :'product_type',
    :'featured_image',
    :'total_inventory',
    :'online_store_url',
    :'created_at',
    :'updated_at',
    :'published_at'
  ])
end

.openapi_typesObject

Attribute type mapping.



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/zernio-sdk/models/product.rb', line 123

def self.openapi_types
  {
    :'id' => :'String',
    :'platform' => :'String',
    :'title' => :'String',
    :'handle' => :'String',
    :'description_html' => :'String',
    :'vendor' => :'String',
    :'product_type' => :'String',
    :'tags' => :'Array<String>',
    :'status' => :'String',
    :'featured_image' => :'ProductImage',
    :'images' => :'Array<ProductImage>',
    :'options' => :'Array<ProductOptionsInner>',
    :'variants' => :'Array<ProductVariant>',
    :'seo' => :'ProductSeo',
    :'total_inventory' => :'Integer',
    :'online_store_url' => :'String',
    :'created_at' => :'Time',
    :'updated_at' => :'Time',
    :'published_at' => :'Time'
  }
end

Instance Method Details

#==(o) ⇒ Object

Checks equality by comparing each attribute.

Parameters:

  • Object (Object)

    to be compared



304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/zernio-sdk/models/product.rb', line 304

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      id == o.id &&
      platform == o.platform &&
      title == o.title &&
      handle == o.handle &&
      description_html == o.description_html &&
      vendor == o.vendor &&
      product_type == o.product_type &&
      tags == o.tags &&
      status == o.status &&
      featured_image == o.featured_image &&
      images == o.images &&
      options == o.options &&
      variants == o.variants &&
      seo == o.seo &&
      total_inventory == o.total_inventory &&
      online_store_url == o.online_store_url &&
      created_at == o.created_at &&
      updated_at == o.updated_at &&
      published_at == o.published_at
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


330
331
332
# File 'lib/zernio-sdk/models/product.rb', line 330

def eql?(o)
  self == o
end

#hashInteger

Calculates hash code according to all attributes.

Returns:

  • (Integer)

    Hash code



336
337
338
# File 'lib/zernio-sdk/models/product.rb', line 336

def hash
  [id, platform, title, handle, description_html, vendor, product_type, tags, status, featured_image, images, options, variants, seo, total_inventory, online_store_url, created_at, updated_at, published_at].hash
end

#list_invalid_propertiesObject

Show invalid properties with the reasons. Usually used together with valid?

Returns:

  • Array for valid properties with the reasons



265
266
267
268
269
# File 'lib/zernio-sdk/models/product.rb', line 265

def list_invalid_properties
  warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
  invalid_properties = Array.new
  invalid_properties
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'lib/zernio-sdk/models/product.rb', line 365

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    if value.nil?
      is_nullable = self.class.openapi_nullable.include?(attr)
      next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
    end

    hash[param] = _to_hash(value)
  end
  hash
end

#valid?Boolean

Check to see if the all the properties in the model are valid

Returns:

  • (Boolean)

    true if the model is valid



273
274
275
276
277
278
279
280
# File 'lib/zernio-sdk/models/product.rb', line 273

def valid?
  warn '[DEPRECATED] the `valid?` method is obsolete'
  platform_validator = EnumAttributeValidator.new('String', ["shopify"])
  return false unless platform_validator.valid?(@platform)
  status_validator = EnumAttributeValidator.new('String', ["active", "draft", "archived"])
  return false unless status_validator.valid?(@status)
  true
end