Class: NewStoreApi::Product1

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/product1.rb

Overview

Product1 Model.

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(currency = nil, id = nil, price = nil, addon_parent_item_id = SKIP, customs_info = SKIP, dimension_height = SKIP, dimension_length = SKIP, dimension_unit = SKIP, dimension_width = SKIP, external_identifiers = SKIP, is_preorder = false, item_id = SKIP, online_from = SKIP, weight = SKIP, weight_unit = SKIP) ⇒ Product1

Returns a new instance of Product1.



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/new_store_api/models/product1.rb', line 146

def initialize(currency = nil, id = nil, price = nil,
               addon_parent_item_id = SKIP, customs_info = SKIP,
               dimension_height = SKIP, dimension_length = SKIP,
               dimension_unit = SKIP, dimension_width = SKIP,
               external_identifiers = SKIP, is_preorder = false,
               item_id = SKIP, online_from = SKIP, weight = SKIP,
               weight_unit = SKIP)
  @addon_parent_item_id = addon_parent_item_id unless addon_parent_item_id == SKIP
  @currency = currency
  @customs_info = customs_info unless customs_info == SKIP
  @dimension_height = dimension_height unless dimension_height == SKIP
  @dimension_length = dimension_length unless dimension_length == SKIP
  @dimension_unit = dimension_unit unless dimension_unit == SKIP
  @dimension_width = dimension_width unless dimension_width == SKIP
  @external_identifiers = external_identifiers unless external_identifiers == SKIP
  @id = id
  @is_preorder = is_preorder unless is_preorder == SKIP
  @item_id = item_id unless item_id == SKIP
  @online_from = online_from unless online_from == SKIP
  @price = price
  @weight = weight unless weight == SKIP
  @weight_unit = weight_unit unless weight_unit == SKIP
end

Instance Attribute Details

#addon_parent_item_idString

establish the relationship between this item and its parent, using the item_id of a parent product. this implies the parent has its item_id defined.

Returns:

  • (String)


17
18
19
# File 'lib/new_store_api/models/product1.rb', line 17

def addon_parent_item_id
  @addon_parent_item_id
end

#currencyCurrencyEnum

establish the relationship between this item and its parent, using the item_id of a parent product. this implies the parent has its item_id defined.

Returns:



23
24
25
# File 'lib/new_store_api/models/product1.rb', line 23

def currency
  @currency
end

#customs_infoOptionProductCustoms

establish the relationship between this item and its parent, using the item_id of a parent product. this implies the parent has its item_id defined.



29
30
31
# File 'lib/new_store_api/models/product1.rb', line 29

def customs_info
  @customs_info
end

#dimension_heightFloat

establish the relationship between this item and its parent, using the item_id of a parent product. this implies the parent has its item_id defined.

Returns:

  • (Float)


35
36
37
# File 'lib/new_store_api/models/product1.rb', line 35

def dimension_height
  @dimension_height
end

#dimension_lengthFloat

establish the relationship between this item and its parent, using the item_id of a parent product. this implies the parent has its item_id defined.

Returns:

  • (Float)


41
42
43
# File 'lib/new_store_api/models/product1.rb', line 41

def dimension_length
  @dimension_length
end

#dimension_unitString

establish the relationship between this item and its parent, using the item_id of a parent product. this implies the parent has its item_id defined.

Returns:

  • (String)


47
48
49
# File 'lib/new_store_api/models/product1.rb', line 47

def dimension_unit
  @dimension_unit
end

#dimension_widthFloat

establish the relationship between this item and its parent, using the item_id of a parent product. this implies the parent has its item_id defined.

Returns:

  • (Float)


53
54
55
# File 'lib/new_store_api/models/product1.rb', line 53

def dimension_width
  @dimension_width
end

#external_identifiersHash[String, Object]

establish the relationship between this item and its parent, using the item_id of a parent product. this implies the parent has its item_id defined.

Returns:

  • (Hash[String, Object])


59
60
61
# File 'lib/new_store_api/models/product1.rb', line 59

def external_identifiers
  @external_identifiers
end

#idString

It should be the NewStore imported catalog ID

Returns:

  • (String)


63
64
65
# File 'lib/new_store_api/models/product1.rb', line 63

def id
  @id
end

#is_preorderTrueClass | FalseClass

Indicates if the product is a pre-order and is available only in a future date

Returns:

  • (TrueClass | FalseClass)


68
69
70
# File 'lib/new_store_api/models/product1.rb', line 68

def is_preorder
  @is_preorder
end

#item_idString

unique item id of this product instance.

Returns:

  • (String)


72
73
74
# File 'lib/new_store_api/models/product1.rb', line 72

def item_id
  @item_id
end

#online_fromDateTime

The date when the product can be sold if pre-ordering

Returns:

  • (DateTime)


76
77
78
# File 'lib/new_store_api/models/product1.rb', line 76

def online_from
  @online_from
end

#priceFloat

The date when the product can be sold if pre-ordering

Returns:

  • (Float)


80
81
82
# File 'lib/new_store_api/models/product1.rb', line 80

def price
  @price
end

#weightFloat

The date when the product can be sold if pre-ordering

Returns:

  • (Float)


84
85
86
# File 'lib/new_store_api/models/product1.rb', line 84

def weight
  @weight
end

#weight_unitString

The date when the product can be sold if pre-ordering

Returns:

  • (String)


88
89
90
# File 'lib/new_store_api/models/product1.rb', line 88

def weight_unit
  @weight_unit
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
# File 'lib/new_store_api/models/product1.rb', line 171

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  currency = hash.key?('currency') ? hash['currency'] : nil
  id = hash.key?('id') ? hash['id'] : nil
  price = hash.key?('price') ? hash['price'] : nil
  addon_parent_item_id =
    hash.key?('addon_parent_item_id') ? hash['addon_parent_item_id'] : SKIP
  customs_info = OptionProductCustoms.from_hash(hash['customs_info']) if hash['customs_info']
  dimension_height =
    hash.key?('dimension_height') ? hash['dimension_height'] : SKIP
  dimension_length =
    hash.key?('dimension_length') ? hash['dimension_length'] : SKIP
  dimension_unit =
    hash.key?('dimension_unit') ? hash['dimension_unit'] : SKIP
  dimension_width =
    hash.key?('dimension_width') ? hash['dimension_width'] : SKIP
  external_identifiers = hash.key?('external_identifiers') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:Product1ExternalIdentifiers), hash['external_identifiers']
  ) : SKIP
  is_preorder = hash['is_preorder'] ||= false
  item_id = hash.key?('item_id') ? hash['item_id'] : SKIP
  online_from = if hash.key?('online_from')
                  (DateTimeHelper.from_rfc3339(hash['online_from']) if hash['online_from'])
                else
                  SKIP
                end
  weight = hash.key?('weight') ? hash['weight'] : SKIP
  weight_unit = hash.key?('weight_unit') ? hash['weight_unit'] : SKIP

  # Create object from extracted values.
  Product1.new(currency,
               id,
               price,
               addon_parent_item_id,
               customs_info,
               dimension_height,
               dimension_length,
               dimension_unit,
               dimension_width,
               external_identifiers,
               is_preorder,
               item_id,
               online_from,
               weight,
               weight_unit)
end

.namesObject

A mapping from model property names to API property names.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/new_store_api/models/product1.rb', line 91

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['addon_parent_item_id'] = 'addon_parent_item_id'
  @_hash['currency'] = 'currency'
  @_hash['customs_info'] = 'customs_info'
  @_hash['dimension_height'] = 'dimension_height'
  @_hash['dimension_length'] = 'dimension_length'
  @_hash['dimension_unit'] = 'dimension_unit'
  @_hash['dimension_width'] = 'dimension_width'
  @_hash['external_identifiers'] = 'external_identifiers'
  @_hash['id'] = 'id'
  @_hash['is_preorder'] = 'is_preorder'
  @_hash['item_id'] = 'item_id'
  @_hash['online_from'] = 'online_from'
  @_hash['price'] = 'price'
  @_hash['weight'] = 'weight'
  @_hash['weight_unit'] = 'weight_unit'
  @_hash
end

.nullablesObject

An array for nullable fields



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/new_store_api/models/product1.rb', line 130

def self.nullables
  %w[
    addon_parent_item_id
    customs_info
    dimension_height
    dimension_length
    dimension_unit
    dimension_width
    external_identifiers
    item_id
    online_from
    weight
    weight_unit
  ]
end

.optionalsObject

An array for optional fields



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/new_store_api/models/product1.rb', line 112

def self.optionals
  %w[
    addon_parent_item_id
    customs_info
    dimension_height
    dimension_length
    dimension_unit
    dimension_width
    external_identifiers
    is_preorder
    item_id
    online_from
    weight
    weight_unit
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Product1 | Hash)

    value against the validation is performed.



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
# File 'lib/new_store_api/models/product1.rb', line 226

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.currency,
                            ->(val) { CurrencyEnum.validate(val) }) and
        APIHelper.valid_type?(value.id,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.price,
                              ->(val) { val.instance_of? Float })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['currency'],
                          ->(val) { CurrencyEnum.validate(val) }) and
      APIHelper.valid_type?(value['id'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['price'],
                            ->(val) { val.instance_of? Float })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



262
263
264
265
266
267
268
269
270
271
272
# File 'lib/new_store_api/models/product1.rb', line 262

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} addon_parent_item_id: #{@addon_parent_item_id.inspect}, currency:"\
  " #{@currency.inspect}, customs_info: #{@customs_info.inspect}, dimension_height:"\
  " #{@dimension_height.inspect}, dimension_length: #{@dimension_length.inspect},"\
  " dimension_unit: #{@dimension_unit.inspect}, dimension_width: #{@dimension_width.inspect},"\
  " external_identifiers: #{@external_identifiers.inspect}, id: #{@id.inspect}, is_preorder:"\
  " #{@is_preorder.inspect}, item_id: #{@item_id.inspect}, online_from:"\
  " #{@online_from.inspect}, price: #{@price.inspect}, weight: #{@weight.inspect},"\
  " weight_unit: #{@weight_unit.inspect}>"
end

#to_custom_online_fromObject



220
221
222
# File 'lib/new_store_api/models/product1.rb', line 220

def to_custom_online_from
  DateTimeHelper.to_rfc3339(online_from)
end

#to_sObject

Provides a human-readable string representation of the object.



251
252
253
254
255
256
257
258
259
# File 'lib/new_store_api/models/product1.rb', line 251

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} addon_parent_item_id: #{@addon_parent_item_id}, currency: #{@currency},"\
  " customs_info: #{@customs_info}, dimension_height: #{@dimension_height}, dimension_length:"\
  " #{@dimension_length}, dimension_unit: #{@dimension_unit}, dimension_width:"\
  " #{@dimension_width}, external_identifiers: #{@external_identifiers}, id: #{@id},"\
  " is_preorder: #{@is_preorder}, item_id: #{@item_id}, online_from: #{@online_from}, price:"\
  " #{@price}, weight: #{@weight}, weight_unit: #{@weight_unit}>"
end