Class: NewStoreApi::LineItem2

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

Overview

A single ordered product line.

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(line_item_id = nil, price = nil, product_id = nil, extended_attributes = SKIP, external_identifiers = SKIP, parent_line_item_id = SKIP, unit_external_id = SKIP) ⇒ LineItem2

Returns a new instance of LineItem2.



76
77
78
79
80
81
82
83
84
85
86
# File 'lib/new_store_api/models/line_item2.rb', line 76

def initialize(line_item_id = nil, price = nil, product_id = nil,
               extended_attributes = SKIP, external_identifiers = SKIP,
               parent_line_item_id = SKIP, unit_external_id = SKIP)
  @extended_attributes = extended_attributes unless extended_attributes == SKIP
  @external_identifiers = external_identifiers unless external_identifiers == SKIP
  @line_item_id = line_item_id
  @parent_line_item_id = parent_line_item_id unless parent_line_item_id == SKIP
  @price = price
  @product_id = product_id
  @unit_external_id = unit_external_id unless unit_external_id == SKIP
end

Instance Attribute Details

#extended_attributesArray[ExtendedAttribute]

Tenant-defined name/value pairs for this line item, propagated through the platform.

Returns:



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

def extended_attributes
  @extended_attributes
end

#external_identifiersExternalIdentifiers

Optional per-unit external identifiers for a serialised item.

Returns:



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

def external_identifiers
  @external_identifiers
end

#line_item_idString

Caller-provided identifier for this line item. Must be unique within the order.

Returns:

  • (String)


24
25
26
# File 'lib/new_store_api/models/line_item2.rb', line 24

def line_item_id
  @line_item_id
end

#parent_line_item_idString

References the line_item_id of the parent product line item this add-on is attached to. Null or omitted for a standalone product line.

Returns:

  • (String)


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

def parent_line_item_id
  @parent_line_item_id
end

#priceLineItemPrice

The required price points for a line item, in the currency's minor unit.

Returns:



33
34
35
# File 'lib/new_store_api/models/line_item2.rb', line 33

def price
  @price
end

#product_idString

The identifier of the product as it was fetched from the catalog.

Returns:

  • (String)


37
38
39
# File 'lib/new_store_api/models/line_item2.rb', line 37

def product_id
  @product_id
end

#unit_external_idString

Caller-provided external identifier for this item. Echoed back as external_item_id in the response. Null when not supplied.

Returns:

  • (String)


42
43
44
# File 'lib/new_store_api/models/line_item2.rb', line 42

def unit_external_id
  @unit_external_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
117
118
119
120
121
# File 'lib/new_store_api/models/line_item2.rb', line 89

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  line_item_id = hash.key?('line_item_id') ? hash['line_item_id'] : nil
  price = LineItemPrice.from_hash(hash['price']) if hash['price']
  product_id = hash.key?('product_id') ? hash['product_id'] : nil
  # Parameter is an array, so we need to iterate through it
  extended_attributes = nil
  unless hash['extended_attributes'].nil?
    extended_attributes = []
    hash['extended_attributes'].each do |structure|
      extended_attributes << (ExtendedAttribute.from_hash(structure) if structure)
    end
  end

  extended_attributes = SKIP unless hash.key?('extended_attributes')
  external_identifiers = ExternalIdentifiers.from_hash(hash['external_identifiers']) if
    hash['external_identifiers']
  parent_line_item_id =
    hash.key?('parent_line_item_id') ? hash['parent_line_item_id'] : SKIP
  unit_external_id =
    hash.key?('unit_external_id') ? hash['unit_external_id'] : SKIP

  # Create object from extracted values.
  LineItem2.new(line_item_id,
                price,
                product_id,
                extended_attributes,
                external_identifiers,
                parent_line_item_id,
                unit_external_id)
end

.namesObject

A mapping from model property names to API property names.



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/new_store_api/models/line_item2.rb', line 45

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['extended_attributes'] = 'extended_attributes'
  @_hash['external_identifiers'] = 'external_identifiers'
  @_hash['line_item_id'] = 'line_item_id'
  @_hash['parent_line_item_id'] = 'parent_line_item_id'
  @_hash['price'] = 'price'
  @_hash['product_id'] = 'product_id'
  @_hash['unit_external_id'] = 'unit_external_id'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  %w[
    external_identifiers
    parent_line_item_id
    unit_external_id
  ]
end

.optionalsObject

An array for optional fields



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

def self.optionals
  %w[
    extended_attributes
    external_identifiers
    parent_line_item_id
    unit_external_id
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



133
134
135
136
137
138
139
# File 'lib/new_store_api/models/line_item2.rb', line 133

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} extended_attributes: #{@extended_attributes.inspect}, external_identifiers:"\
  " #{@external_identifiers.inspect}, line_item_id: #{@line_item_id.inspect},"\
  " parent_line_item_id: #{@parent_line_item_id.inspect}, price: #{@price.inspect},"\
  " product_id: #{@product_id.inspect}, unit_external_id: #{@unit_external_id.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



124
125
126
127
128
129
130
# File 'lib/new_store_api/models/line_item2.rb', line 124

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} extended_attributes: #{@extended_attributes}, external_identifiers:"\
  " #{@external_identifiers}, line_item_id: #{@line_item_id}, parent_line_item_id:"\
  " #{@parent_line_item_id}, price: #{@price}, product_id: #{@product_id}, unit_external_id:"\
  " #{@unit_external_id}>"
end