Class: SquareConnect::CatalogObject
- Inherits:
-
Object
- Object
- SquareConnect::CatalogObject
- 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. For a more detailed discussion of the Catalog data model, please see the [Catalog Overview](docs.connect.squareup.com/articles/catalog-overview).
Defined Under Namespace
Classes: EnumAttributeValidator
Instance Attribute Summary collapse
-
#absent_at_location_ids ⇒ Object
A list of locations where the object is not present, even if ‘present_at_all_locations` is `true`.
-
#catalog_v1_ids ⇒ Object
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.
-
#category_data ⇒ Object
Structured data for a [CatalogCategory](#type-catalogcategory), set for CatalogObjects of type ‘CATEGORY`.
-
#discount_data ⇒ Object
Structured data for a [CatalogDiscount](#type-catalogdiscount), set for CatalogObjects of type ‘DISCOUNT`.
-
#id ⇒ Object
An identifier to reference this object in the catalog.
-
#is_deleted ⇒ Object
If ‘true`, the object has been deleted from the database.
-
#item_data ⇒ Object
Structured data for a [CatalogItem](#type-catalogitem), set for CatalogObjects of type ‘ITEM`.
-
#item_variation_data ⇒ Object
Structured data for a [CatalogItemVariation](#type-catalogitemvariation), set for CatalogObjects of type ‘ITEM_VARIATION`.
-
#modifier_data ⇒ Object
Structured data for a [CatalogModifier](#type-catalogmodifier), set for CatalogObjects of type ‘MODIFIER`.
-
#modifier_list_data ⇒ Object
Structured data for a [CatalogModifierList](#type-catalogmodifierlist), set for CatalogObjects of type ‘MODIFIER_LIST`.
-
#present_at_all_locations ⇒ Object
If ‘true`, this object is present at all locations (including future locations), except where specified in the `absent_at_location_ids` field.
-
#present_at_location_ids ⇒ Object
A list of locations where the object is present, even if ‘present_at_all_locations` is `false`.
-
#tax_data ⇒ Object
Structured data for a [CatalogTax](#type-catalogtax), set for CatalogObjects of type ‘TAX`.
-
#type ⇒ Object
The type of this object.
-
#updated_at ⇒ Object
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.
-
#version ⇒ Object
The version of the object.
Class Method Summary collapse
-
.attribute_map ⇒ Object
Attribute mapping from ruby-style variable name to JSON key.
-
.swagger_types ⇒ Object
Attribute type mapping.
Instance Method Summary collapse
-
#==(o) ⇒ Object
Checks equality by comparing each attribute.
-
#_deserialize(type, value) ⇒ Object
Deserializes the data based on type.
-
#_to_hash(value) ⇒ Hash
Outputs non-array value in the form of hash For object, use to_hash.
-
#build_from_hash(attributes) ⇒ Object
Builds the object from hash.
- #eql?(o) ⇒ Boolean
-
#hash ⇒ Fixnum
Calculates hash code according to all attributes.
-
#initialize(attributes = {}) ⇒ CatalogObject
constructor
Initializes the object.
-
#list_invalid_properties ⇒ Object
Show invalid properties with the reasons.
-
#to_body ⇒ Hash
to_body is an alias to to_hash (backward compatibility).
-
#to_hash ⇒ Hash
Returns the object in the form of hash.
-
#to_s ⇒ String
Returns the string representation of the object.
-
#valid? ⇒ Boolean
Check to see if the all the properties in the model are valid.
Constructor Details
#initialize(attributes = {}) ⇒ CatalogObject
Initializes the object
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 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 |
# File 'lib/square_connect/models/catalog_object.rb', line 131 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?(:'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 end |
Instance Attribute Details
#absent_at_location_ids ⇒ Object
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_ids ⇒ Object
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_data ⇒ Object
Structured data for a [CatalogCategory](#type-catalogcategory), set for CatalogObjects of type ‘CATEGORY`.
46 47 48 |
# File 'lib/square_connect/models/catalog_object.rb', line 46 def category_data @category_data end |
#discount_data ⇒ Object
Structured data for a [CatalogDiscount](#type-catalogdiscount), set for CatalogObjects of type ‘DISCOUNT`.
55 56 57 |
# File 'lib/square_connect/models/catalog_object.rb', line 55 def discount_data @discount_data end |
#id ⇒ Object
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 |
#is_deleted ⇒ Object
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_data ⇒ Object
Structured data for a [CatalogItem](#type-catalogitem), set for CatalogObjects of type ‘ITEM`.
43 44 45 |
# File 'lib/square_connect/models/catalog_object.rb', line 43 def item_data @item_data end |
#item_variation_data ⇒ Object
Structured data for a [CatalogItemVariation](#type-catalogitemvariation), set for CatalogObjects of type ‘ITEM_VARIATION`.
49 50 51 |
# File 'lib/square_connect/models/catalog_object.rb', line 49 def item_variation_data @item_variation_data end |
#modifier_data ⇒ Object
Structured data for a [CatalogModifier](#type-catalogmodifier), set for CatalogObjects of type ‘MODIFIER`.
61 62 63 |
# File 'lib/square_connect/models/catalog_object.rb', line 61 def modifier_data @modifier_data end |
#modifier_list_data ⇒ Object
Structured data for a [CatalogModifierList](#type-catalogmodifierlist), set for CatalogObjects of type ‘MODIFIER_LIST`.
58 59 60 |
# File 'lib/square_connect/models/catalog_object.rb', line 58 def modifier_list_data @modifier_list_data end |
#present_at_all_locations ⇒ Object
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_ids ⇒ Object
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 |
#tax_data ⇒ Object
Structured data for a [CatalogTax](#type-catalogtax), set for CatalogObjects of type ‘TAX`.
52 53 54 |
# File 'lib/square_connect/models/catalog_object.rb', line 52 def tax_data @tax_data end |
#type ⇒ Object
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 all possible values.
16 17 18 |
# File 'lib/square_connect/models/catalog_object.rb', line 16 def type @type end |
#updated_at ⇒ Object
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 |
#version ⇒ Object
The version of the object. When updating an object, the version supplied by the 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_map ⇒ Object
Attribute mapping from ruby-style variable name to JSON key.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/square_connect/models/catalog_object.rb', line 86 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', :'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' } end |
.swagger_types ⇒ Object
Attribute type mapping.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/square_connect/models/catalog_object.rb', line 108 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>', :'item_data' => :'CatalogItem', :'category_data' => :'CatalogCategory', :'item_variation_data' => :'CatalogItemVariation', :'tax_data' => :'CatalogTax', :'discount_data' => :'CatalogDiscount', :'modifier_list_data' => :'CatalogModifierList', :'modifier_data' => :'CatalogModifier' } end |
Instance Method Details
#==(o) ⇒ Object
Checks equality by comparing each attribute.
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/square_connect/models/catalog_object.rb', line 265 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 && 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 end |
#_deserialize(type, value) ⇒ Object
Deserializes the data based on type
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'lib/square_connect/models/catalog_object.rb', line 322 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
388 389 390 391 392 393 394 395 396 397 398 399 400 |
# File 'lib/square_connect/models/catalog_object.rb', line 388 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
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# File 'lib/square_connect/models/catalog_object.rb', line 301 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
288 289 290 |
# File 'lib/square_connect/models/catalog_object.rb', line 288 def eql?(o) self == o end |
#hash ⇒ Fixnum
Calculates hash code according to all attributes.
294 295 296 |
# File 'lib/square_connect/models/catalog_object.rb', line 294 def hash [type, id, updated_at, version, is_deleted, catalog_v1_ids, present_at_all_locations, present_at_location_ids, absent_at_location_ids, item_data, category_data, item_variation_data, tax_data, discount_data, modifier_list_data, modifier_data].hash end |
#list_invalid_properties ⇒ Object
Show invalid properties with the reasons. Usually used together with valid?
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/square_connect/models/catalog_object.rb', line 211 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_body ⇒ Hash
to_body is an alias to to_hash (backward compatibility)
368 369 370 |
# File 'lib/square_connect/models/catalog_object.rb', line 368 def to_body to_hash end |
#to_hash ⇒ Hash
Returns the object in the form of hash
374 375 376 377 378 379 380 381 382 |
# File 'lib/square_connect/models/catalog_object.rb', line 374 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_s ⇒ String
Returns the string representation of the object
362 363 364 |
# File 'lib/square_connect/models/catalog_object.rb', line 362 def to_s to_hash.to_s end |
#valid? ⇒ Boolean
Check to see if the all the properties in the model are valid
230 231 232 233 234 235 236 237 |
# File 'lib/square_connect/models/catalog_object.rb', line 230 def valid? return false if @type.nil? type_validator = EnumAttributeValidator.new('String', ["ITEM", "CATEGORY", "ITEM_VARIATION", "TAX", "DISCOUNT", "MODIFIER_LIST", "MODIFIER"]) return false unless type_validator.valid?(@type) return false if @id.nil? return false if @id.to_s.length < 1 return true end |