Class: NewStoreApi::ResponseUnitItem

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

Overview

An item identifier triplet echoed back in the order response.

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(id = nil, product_id = nil, external_item_id = SKIP) ⇒ ResponseUnitItem

Returns a new instance of ResponseUnitItem.



48
49
50
51
52
# File 'lib/new_store_api/models/response_unit_item.rb', line 48

def initialize(id = nil, product_id = nil, external_item_id = SKIP)
  @external_item_id = external_item_id unless external_item_id == SKIP
  @id = id
  @product_id = product_id
end

Instance Attribute Details

#external_item_idString

The external order item id as specified in the request (unit_external_id). Null when not supplied.

Returns:

  • (String)


15
16
17
# File 'lib/new_store_api/models/response_unit_item.rb', line 15

def external_item_id
  @external_item_id
end

#idString

An identifier that is assigned to the item by the system.

Returns:

  • (String)


19
20
21
# File 'lib/new_store_api/models/response_unit_item.rb', line 19

def id
  @id
end

#product_idString

The product id from the catalog.

Returns:

  • (String)


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

def product_id
  @product_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/new_store_api/models/response_unit_item.rb', line 55

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : nil
  product_id = hash.key?('product_id') ? hash['product_id'] : nil
  external_item_id =
    hash.key?('external_item_id') ? hash['external_item_id'] : SKIP

  # Create object from extracted values.
  ResponseUnitItem.new(id,
                       product_id,
                       external_item_id)
end

.namesObject

A mapping from model property names to API property names.



26
27
28
29
30
31
32
# File 'lib/new_store_api/models/response_unit_item.rb', line 26

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['external_item_id'] = 'external_item_id'
  @_hash['id'] = 'id'
  @_hash['product_id'] = 'product_id'
  @_hash
end

.nullablesObject

An array for nullable fields



42
43
44
45
46
# File 'lib/new_store_api/models/response_unit_item.rb', line 42

def self.nullables
  %w[
    external_item_id
  ]
end

.optionalsObject

An array for optional fields



35
36
37
38
39
# File 'lib/new_store_api/models/response_unit_item.rb', line 35

def self.optionals
  %w[
    external_item_id
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



78
79
80
81
82
# File 'lib/new_store_api/models/response_unit_item.rb', line 78

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} external_item_id: #{@external_item_id.inspect}, id: #{@id.inspect},"\
  " product_id: #{@product_id.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



71
72
73
74
75
# File 'lib/new_store_api/models/response_unit_item.rb', line 71

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} external_item_id: #{@external_item_id}, id: #{@id}, product_id:"\
  " #{@product_id}>"
end