Class: NewStoreApi::LineItem21

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

Overview

Line item with product information and optional addon relationships

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(product_id = nil, addon_parent_item_id = SKIP, is_preorder = false, line_item_id = SKIP) ⇒ LineItem21

Returns a new instance of LineItem21.



67
68
69
70
71
72
73
# File 'lib/new_store_api/models/line_item21.rb', line 67

def initialize(product_id = nil, addon_parent_item_id = SKIP,
               is_preorder = false, line_item_id = SKIP)
  @addon_parent_item_id = addon_parent_item_id unless addon_parent_item_id == SKIP
  @is_preorder = is_preorder unless is_preorder == SKIP
  @line_item_id = line_item_id unless line_item_id == SKIP
  @product_id = product_id
end

Instance Attribute Details

#addon_parent_item_idString

Line item ID of the parent product of this addon. If specified, must reference the product's line_item_id in this list. Null if this is not an addon or for backward compatibility with the delivery service API.

Returns:

  • (String)


16
17
18
# File 'lib/new_store_api/models/line_item21.rb', line 16

def addon_parent_item_id
  @addon_parent_item_id
end

#is_preorderTrueClass | FalseClass

Indicates if the product is a preorder item. If true, the product is expected to be available in the future and should have future availability.

Returns:

  • (TrueClass | FalseClass)


22
23
24
# File 'lib/new_store_api/models/line_item21.rb', line 22

def is_preorder
  @is_preorder
end

#line_item_idString

Line item ID of the unique instance of the product or addon. Optional for backward compatibility with the delivery service API. Its main use is to set the relationship between parent items and addons. If not specified, response will not have it. If specified, all other line items must have a line_item_id.

Returns:

  • (String)


30
31
32
# File 'lib/new_store_api/models/line_item21.rb', line 30

def line_item_id
  @line_item_id
end

#product_idString

Line item ID of the unique instance of the product or addon. Optional for backward compatibility with the delivery service API. Its main use is to set the relationship between parent items and addons. If not specified, response will not have it. If specified, all other line items must have a line_item_id.

Returns:

  • (String)


38
39
40
# File 'lib/new_store_api/models/line_item21.rb', line 38

def product_id
  @product_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/new_store_api/models/line_item21.rb', line 76

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  product_id = hash.key?('product_id') ? hash['product_id'] : nil
  addon_parent_item_id =
    hash.key?('addon_parent_item_id') ? hash['addon_parent_item_id'] : SKIP
  is_preorder = hash['is_preorder'] ||= false
  line_item_id = hash.key?('line_item_id') ? hash['line_item_id'] : SKIP

  # Create object from extracted values.
  LineItem21.new(product_id,
                 addon_parent_item_id,
                 is_preorder,
                 line_item_id)
end

.namesObject

A mapping from model property names to API property names.



41
42
43
44
45
46
47
48
# File 'lib/new_store_api/models/line_item21.rb', line 41

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['addon_parent_item_id'] = 'addon_parent_item_id'
  @_hash['is_preorder'] = 'is_preorder'
  @_hash['line_item_id'] = 'line_item_id'
  @_hash['product_id'] = 'product_id'
  @_hash
end

.nullablesObject

An array for nullable fields



60
61
62
63
64
65
# File 'lib/new_store_api/models/line_item21.rb', line 60

def self.nullables
  %w[
    addon_parent_item_id
    line_item_id
  ]
end

.optionalsObject

An array for optional fields



51
52
53
54
55
56
57
# File 'lib/new_store_api/models/line_item21.rb', line 51

def self.optionals
  %w[
    addon_parent_item_id
    is_preorder
    line_item_id
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (LineItem21 | Hash)

    value against the validation is performed.



95
96
97
98
99
100
101
102
103
104
105
# File 'lib/new_store_api/models/line_item21.rb', line 95

def self.validate(value)
  if value.instance_of? self
    return APIHelper.valid_type?(value.product_id,
                                 ->(val) { val.instance_of? String })
  end

  return false unless value.instance_of? Hash

  APIHelper.valid_type?(value['product_id'],
                        ->(val) { val.instance_of? String })
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



115
116
117
118
119
120
# File 'lib/new_store_api/models/line_item21.rb', line 115

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

#to_sObject

Provides a human-readable string representation of the object.



108
109
110
111
112
# File 'lib/new_store_api/models/line_item21.rb', line 108

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