Class: SquareConnect::CatalogObject

Inherits:
Object
  • Object
show all
Defined in:
lib/square_connect/models/catalog_object.rb

Overview

The wrapper object for object types in the Catalog data model. The type of a particular ‘CatalogObject` is determined by the value of `type` and only the corresponding data field may be set. - if type = `ITEM`, only `item_data` will be populated and it will contain a valid [CatalogItem](#type-catalogitem) object. - if type = `ITEM_VARIATION`, only `item_variation_data` will be populated and it will contain a valid [CatalogItemVariation](#type-catalogitemvariation) object. - if type = `MODIFIER`, only `modifier_data` will be populated and it will contain a valid [CatalogModifier](#type-catalogmodifier) object. - if type = `MODIFIER_LIST`, only `modifier_list_data` will be populated and it will contain a valid [CatalogModifierList](#type-catalogmodifierlist) object. - if type = `CATEGORY`, only `category_data` will be populated and it will contain a valid [CatalogCategory](#type-catalogcategory) object. - if type = `DISCOUNT`, only `discount_data` will be populated and it will contain a valid [CatalogDiscount](#type-catalogdiscount) object. - if type = `TAX`, only `tax_data` will be populated and it will contain a valid [CatalogTax](#type-catalogtax) object. - if type = `IMAGE`, only `image_data` will be populated and it will contain a valid [CatalogImage](#type-catalogimage) object. For a more detailed discussion of the Catalog data model, please see the [Design a Catalog](/catalog-api/design-a-catalog) guide.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ CatalogObject

Initializes the object

Parameters:

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

    Model attributes in the form of hash



150
151
152
153
154
155
156
157
158
159
160
161
162
163
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
# File 'lib/square_connect/models/catalog_object.rb', line 150

def initialize(attributes = {})
  return unless attributes.is_a?(Hash)

  # convert string to symbol for hash key
  attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}

  if attributes.has_key?(:'type')
    self.type = attributes[:'type']
  end

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

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

  if attributes.has_key?(:'version')
    self.version = attributes[:'version']
  end

  if attributes.has_key?(:'is_deleted')
    self.is_deleted = attributes[:'is_deleted']
  end

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

  if attributes.has_key?(:'present_at_all_locations')
    self.present_at_all_locations = attributes[:'present_at_all_locations']
  end

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

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

  if attributes.has_key?(:'image_id')
    self.image_id = attributes[:'image_id']
  end

  if attributes.has_key?(:'item_data')
    self.item_data = attributes[:'item_data']
  end

  if attributes.has_key?(:'category_data')
    self.category_data = attributes[:'category_data']
  end

  if attributes.has_key?(:'item_variation_data')
    self.item_variation_data = attributes[:'item_variation_data']
  end

  if attributes.has_key?(:'tax_data')
    self.tax_data = attributes[:'tax_data']
  end

  if attributes.has_key?(:'discount_data')
    self.discount_data = attributes[:'discount_data']
  end

  if attributes.has_key?(:'modifier_list_data')
    self.modifier_list_data = attributes[:'modifier_list_data']
  end

  if attributes.has_key?(:'modifier_data')
    self.modifier_data = attributes[:'modifier_data']
  end

  if attributes.has_key?(:'time_period_data')
    self.time_period_data = attributes[:'time_period_data']
  end

  if attributes.has_key?(:'product_set_data')
    self.product_set_data = attributes[:'product_set_data']
  end

  if attributes.has_key?(:'pricing_rule_data')
    self.pricing_rule_data = attributes[:'pricing_rule_data']
  end

  if attributes.has_key?(:'image_data')
    self.image_data = attributes[:'image_data']
  end

  if attributes.has_key?(:'measurement_unit_data')
    self.measurement_unit_data = attributes[:'measurement_unit_data']
  end

  if attributes.has_key?(:'item_option_data')
    self.item_option_data = attributes[:'item_option_data']
  end

  if attributes.has_key?(:'item_option_value_data')
    self.item_option_value_data = attributes[:'item_option_value_data']
  end

end

Instance Attribute Details

#absent_at_location_idsObject

A list of locations where the object is not present, even if ‘present_at_all_locations` is `true`.



40
41
42
# File 'lib/square_connect/models/catalog_object.rb', line 40

def absent_at_location_ids
  @absent_at_location_ids
end

#catalog_v1_idsObject

The Connect V1 IDs for this object at each [location](#type-location) where it is present, where they differ from the object’s Connect V2 ID. The field will only be present for objects that have been created or modified by legacy APIs.



31
32
33
# File 'lib/square_connect/models/catalog_object.rb', line 31

def catalog_v1_ids
  @catalog_v1_ids
end

#category_dataObject

Structured data for a [CatalogCategory](#type-catalogcategory), set for CatalogObjects of type ‘CATEGORY`.



49
50
51
# File 'lib/square_connect/models/catalog_object.rb', line 49

def category_data
  @category_data
end

#discount_dataObject

Structured data for a [CatalogDiscount](#type-catalogdiscount), set for CatalogObjects of type ‘DISCOUNT`.



58
59
60
# File 'lib/square_connect/models/catalog_object.rb', line 58

def discount_data
  @discount_data
end

#idObject

An identifier to reference this object in the catalog. When a new CatalogObject is inserted, the client should set the id to a temporary identifier starting with a ‘’#‘` character. Other objects being inserted or updated within the same request may use this identifier to refer to the new object. When the server receives the new object, it will supply a unique identifier that replaces the temporary identifier for all future references.



19
20
21
# File 'lib/square_connect/models/catalog_object.rb', line 19

def id
  @id
end

#image_dataObject

Structured data for a [CatalogImage](#type-catalogimage), set for CatalogObjects of type ‘IMAGE`.



76
77
78
# File 'lib/square_connect/models/catalog_object.rb', line 76

def image_data
  @image_data
end

#image_idObject

Identifies the ‘CatalogImage` attached to this `CatalogObject`.



43
44
45
# File 'lib/square_connect/models/catalog_object.rb', line 43

def image_id
  @image_id
end

#is_deletedObject

If ‘true`, the object has been deleted from the database. Must be `false` for new objects being inserted. When deleted, the `updated_at` field will equal the deletion time.



28
29
30
# File 'lib/square_connect/models/catalog_object.rb', line 28

def is_deleted
  @is_deleted
end

#item_dataObject

Structured data for a [CatalogItem](#type-catalogitem), set for CatalogObjects of type ‘ITEM`.



46
47
48
# File 'lib/square_connect/models/catalog_object.rb', line 46

def item_data
  @item_data
end

#item_option_dataObject

Structured data for a [CatalogItemOption](#type-catalogitemoption), set for CatalogObjects of type ‘ITEM_OPTION`.



82
83
84
# File 'lib/square_connect/models/catalog_object.rb', line 82

def item_option_data
  @item_option_data
end

#item_option_value_dataObject

Structured data for a [CatalogItemOptionValue](#type-catalogitemoptionvalue), set for CatalogObjects of type ‘ITEM_OPTION_VAL`.



85
86
87
# File 'lib/square_connect/models/catalog_object.rb', line 85

def item_option_value_data
  @item_option_value_data
end

#item_variation_dataObject

Structured data for a [CatalogItemVariation](#type-catalogitemvariation), set for CatalogObjects of type ‘ITEM_VARIATION`.



52
53
54
# File 'lib/square_connect/models/catalog_object.rb', line 52

def item_variation_data
  @item_variation_data
end

#measurement_unit_dataObject

Structured data for a [CatalogMeasurementUnit](#type-catalogmeasurementunit), set for CatalogObjects of type ‘MEASUREMENT_UNIT`.



79
80
81
# File 'lib/square_connect/models/catalog_object.rb', line 79

def measurement_unit_data
  @measurement_unit_data
end

#modifier_dataObject

Structured data for a [CatalogModifier](#type-catalogmodifier), set for CatalogObjects of type ‘MODIFIER`.



64
65
66
# File 'lib/square_connect/models/catalog_object.rb', line 64

def modifier_data
  @modifier_data
end

#modifier_list_dataObject

Structured data for a [CatalogModifierList](#type-catalogmodifierlist), set for CatalogObjects of type ‘MODIFIER_LIST`.



61
62
63
# File 'lib/square_connect/models/catalog_object.rb', line 61

def modifier_list_data
  @modifier_list_data
end

#present_at_all_locationsObject

If ‘true`, this object is present at all locations (including future locations), except where specified in the `absent_at_location_ids` field. If `false`, this object is not present at any locations (including future locations), except where specified in the `present_at_location_ids` field. If not specified, defaults to `true`.



34
35
36
# File 'lib/square_connect/models/catalog_object.rb', line 34

def present_at_all_locations
  @present_at_all_locations
end

#present_at_location_idsObject

A list of locations where the object is present, even if ‘present_at_all_locations` is `false`.



37
38
39
# File 'lib/square_connect/models/catalog_object.rb', line 37

def present_at_location_ids
  @present_at_location_ids
end

#pricing_rule_dataObject

Structured data for a [CatalogPricingRule](#type-catalogpricingrule), set for CatalogObjects of type ‘PRICING_RULE`.



73
74
75
# File 'lib/square_connect/models/catalog_object.rb', line 73

def pricing_rule_data
  @pricing_rule_data
end

#product_set_dataObject

Structured data for a [CatalogProductSet](#type-catalogproductset), set for CatalogObjects of type ‘PRODUCT_SET`.



70
71
72
# File 'lib/square_connect/models/catalog_object.rb', line 70

def product_set_data
  @product_set_data
end

#tax_dataObject

Structured data for a [CatalogTax](#type-catalogtax), set for CatalogObjects of type ‘TAX`.



55
56
57
# File 'lib/square_connect/models/catalog_object.rb', line 55

def tax_data
  @tax_data
end

#time_period_dataObject

Structured data for a [CatalogTimePeriod](#type-catalogtimeperiod), set for CatalogObjects of type ‘TIME_PERIOD`.



67
68
69
# File 'lib/square_connect/models/catalog_object.rb', line 67

def time_period_data
  @time_period_data
end

#typeObject

The type of this object. Each object type has expected properties expressed in a structured format within its corresponding ‘*_data` field below. See [CatalogObjectType](#type-catalogobjecttype) for possible values



16
17
18
# File 'lib/square_connect/models/catalog_object.rb', line 16

def type
  @type
end

#updated_atObject

Last modification [timestamp](#workingwithdates) in RFC 3339 format, e.g., ‘"2016-08-15T23:59:33.123Z"` would indicate the UTC time (denoted by `Z`) of August 15, 2016 at 23:59:33 and 123 milliseconds.



22
23
24
# File 'lib/square_connect/models/catalog_object.rb', line 22

def updated_at
  @updated_at
end

#versionObject

The version of the object. When updating an object, the version supplied must match the version in the database, otherwise the write will be rejected as conflicting.



25
26
27
# File 'lib/square_connect/models/catalog_object.rb', line 25

def version
  @version
end

Class Method Details

.attribute_mapObject

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



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
# File 'lib/square_connect/models/catalog_object.rb', line 89

def self.attribute_map
  {
    :'type' => :'type',
    :'id' => :'id',
    :'updated_at' => :'updated_at',
    :'version' => :'version',
    :'is_deleted' => :'is_deleted',
    :'catalog_v1_ids' => :'catalog_v1_ids',
    :'present_at_all_locations' => :'present_at_all_locations',
    :'present_at_location_ids' => :'present_at_location_ids',
    :'absent_at_location_ids' => :'absent_at_location_ids',
    :'image_id' => :'image_id',
    :'item_data' => :'item_data',
    :'category_data' => :'category_data',
    :'item_variation_data' => :'item_variation_data',
    :'tax_data' => :'tax_data',
    :'discount_data' => :'discount_data',
    :'modifier_list_data' => :'modifier_list_data',
    :'modifier_data' => :'modifier_data',
    :'time_period_data' => :'time_period_data',
    :'product_set_data' => :'product_set_data',
    :'pricing_rule_data' => :'pricing_rule_data',
    :'image_data' => :'image_data',
    :'measurement_unit_data' => :'measurement_unit_data',
    :'item_option_data' => :'item_option_data',
    :'item_option_value_data' => :'item_option_value_data'
  }
end

.swagger_typesObject

Attribute type mapping.



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
# File 'lib/square_connect/models/catalog_object.rb', line 119

def self.swagger_types
  {
    :'type' => :'String',
    :'id' => :'String',
    :'updated_at' => :'String',
    :'version' => :'Integer',
    :'is_deleted' => :'BOOLEAN',
    :'catalog_v1_ids' => :'Array<CatalogV1Id>',
    :'present_at_all_locations' => :'BOOLEAN',
    :'present_at_location_ids' => :'Array<String>',
    :'absent_at_location_ids' => :'Array<String>',
    :'image_id' => :'String',
    :'item_data' => :'CatalogItem',
    :'category_data' => :'CatalogCategory',
    :'item_variation_data' => :'CatalogItemVariation',
    :'tax_data' => :'CatalogTax',
    :'discount_data' => :'CatalogDiscount',
    :'modifier_list_data' => :'CatalogModifierList',
    :'modifier_data' => :'CatalogModifier',
    :'time_period_data' => :'CatalogTimePeriod',
    :'product_set_data' => :'CatalogProductSet',
    :'pricing_rule_data' => :'CatalogPricingRule',
    :'image_data' => :'CatalogImage',
    :'measurement_unit_data' => :'CatalogMeasurementUnit',
    :'item_option_data' => :'CatalogItemOption',
    :'item_option_value_data' => :'CatalogItemOptionValue'
  }
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
327
328
329
330
331
# File 'lib/square_connect/models/catalog_object.rb', line 304

def ==(o)
  return true if self.equal?(o)
  self.class == o.class &&
      type == o.type &&
      id == o.id &&
      updated_at == o.updated_at &&
      version == o.version &&
      is_deleted == o.is_deleted &&
      catalog_v1_ids == o.catalog_v1_ids &&
      present_at_all_locations == o.present_at_all_locations &&
      present_at_location_ids == o.present_at_location_ids &&
      absent_at_location_ids == o.absent_at_location_ids &&
      image_id == o.image_id &&
      item_data == o.item_data &&
      category_data == o.category_data &&
      item_variation_data == o.item_variation_data &&
      tax_data == o.tax_data &&
      discount_data == o.discount_data &&
      modifier_list_data == o.modifier_list_data &&
      modifier_data == o.modifier_data &&
      time_period_data == o.time_period_data &&
      product_set_data == o.product_set_data &&
      pricing_rule_data == o.pricing_rule_data &&
      image_data == o.image_data &&
      measurement_unit_data == o.measurement_unit_data &&
      item_option_data == o.item_option_data &&
      item_option_value_data == o.item_option_value_data
end

#_deserialize(type, value) ⇒ Object

Deserializes the data based on type

Parameters:

  • string

    type Data type

  • string

    value Value to be deserialized

Returns:

  • (Object)

    Deserialized data



369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/square_connect/models/catalog_object.rb', line 369

def _deserialize(type, value)
  case type.to_sym
  when :DateTime
    DateTime.parse(value)
  when :Date
    Date.parse(value)
  when :String
    value.to_s
  when :Integer
    value.to_i
  when :Float
    value.to_f
  when :BOOLEAN
    if value.to_s =~ /\A(true|t|yes|y|1)\z/i
      true
    else
      false
    end
  when :Object
    # generic object (usually a Hash), return directly
    value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |v| _deserialize(inner_type, v) }
  when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
    k_type = Regexp.last_match[:k_type]
    v_type = Regexp.last_match[:v_type]
    {}.tap do |hash|
      value.each do |k, v|
        hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
      end
    end
  else # model
    temp_model = SquareConnect.const_get(type).new
    temp_model.build_from_hash(value)
  end
end

#_to_hash(value) ⇒ Hash

Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value

Parameters:

  • value (Object)

    Any valid value

Returns:

  • (Hash)

    Returns the value in the form of hash



435
436
437
438
439
440
441
442
443
444
445
446
447
# File 'lib/square_connect/models/catalog_object.rb', line 435

def _to_hash(value)
  if value.is_a?(Array)
    value.compact.map{ |v| _to_hash(v) }
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.each { |k, v| hash[k] = _to_hash(v) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash
  else
    value
  end
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



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/square_connect/models/catalog_object.rb', line 348

def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)
  self.class.swagger_types.each_pair do |key, type|
    if type =~ /\AArray<(.*)>/i
      # check to ensure the input is an array given that the the attribute
      # is documented as an array but the input is not
      if attributes[self.class.attribute_map[key]].is_a?(Array)
        self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
      end
    elsif !attributes[self.class.attribute_map[key]].nil?
      self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
    end # or else data not found in attributes(hash), not an issue as the data can be optional
  end

  self
end

#eql?(o) ⇒ Boolean

Parameters:

  • Object (Object)

    to be compared

Returns:

  • (Boolean)

See Also:

  • `==` method


335
336
337
# File 'lib/square_connect/models/catalog_object.rb', line 335

def eql?(o)
  self == o
end

#hashFixnum

Calculates hash code according to all attributes.

Returns:

  • (Fixnum)

    Hash code



341
342
343
# File 'lib/square_connect/models/catalog_object.rb', line 341

def hash
  [type, id, updated_at, version, is_deleted, catalog_v1_ids, present_at_all_locations, present_at_location_ids, absent_at_location_ids, image_id, item_data, category_data, item_variation_data, tax_data, discount_data, modifier_list_data, modifier_data, time_period_data, product_set_data, pricing_rule_data, image_data, measurement_unit_data, item_option_data, item_option_value_data].hash
end

#list_invalid_propertiesObject

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

Returns:

  • Array for valid properies with the reasons



262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/square_connect/models/catalog_object.rb', line 262

def list_invalid_properties
  invalid_properties = Array.new
  if @type.nil?
    invalid_properties.push("invalid value for 'type', type cannot be nil.")
  end

  if @id.nil?
    invalid_properties.push("invalid value for 'id', id cannot be nil.")
  end

  if @id.to_s.length < 1
    invalid_properties.push("invalid value for 'id', the character length must be great than or equal to 1.")
  end

  return invalid_properties
end

#to_bodyHash

to_body is an alias to to_hash (backward compatibility)

Returns:

  • (Hash)

    Returns the object in the form of hash



415
416
417
# File 'lib/square_connect/models/catalog_object.rb', line 415

def to_body
  to_hash
end

#to_hashHash

Returns the object in the form of hash

Returns:

  • (Hash)

    Returns the object in the form of hash



421
422
423
424
425
426
427
428
429
# File 'lib/square_connect/models/catalog_object.rb', line 421

def to_hash
  hash = {}
  self.class.attribute_map.each_pair do |attr, param|
    value = self.send(attr)
    next if value.nil?
    hash[param] = _to_hash(value)
  end
  hash
end

#to_sString

Returns the string representation of the object

Returns:

  • (String)

    String presentation of the object



409
410
411
# File 'lib/square_connect/models/catalog_object.rb', line 409

def to_s
  to_hash.to_s
end

#valid?Boolean

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

Returns:

  • (Boolean)

    true if the model is valid



281
282
283
284
285
286
# File 'lib/square_connect/models/catalog_object.rb', line 281

def valid?
  return false if @type.nil?
  return false if @id.nil?
  return false if @id.to_s.length < 1
  return true
end