Class: NewStoreApi::ItemResource

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

Overview

ItemResource 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(links = nil, add_ons = nil, extended_attributes = nil, id = nil, price = nil, product_id = nil, quantity = nil, epc = SKIP, fulfillment = SKIP, serial_number = SKIP, source_id = SKIP) ⇒ ItemResource

Returns a new instance of ItemResource.



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

def initialize(links = nil, add_ons = nil, extended_attributes = nil,
               id = nil, price = nil, product_id = nil, quantity = nil,
               epc = SKIP, fulfillment = SKIP, serial_number = SKIP,
               source_id = SKIP)
  @links = links
  @add_ons = add_ons
  @epc = epc unless epc == SKIP
  @extended_attributes = extended_attributes
  @fulfillment = fulfillment unless fulfillment == SKIP
  @id = id
  @price = price
  @product_id = product_id
  @quantity = quantity
  @serial_number = serial_number unless serial_number == SKIP
  @source_id = source_id unless source_id == SKIP
end

Instance Attribute Details

#add_onsArray[AddOnResource]

Item add-ons

Returns:



18
19
20
# File 'lib/new_store_api/models/item_resource.rb', line 18

def add_ons
  @add_ons
end

#epcString

Electronic Product Code

Returns:

  • (String)


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

def epc
  @epc
end

#extended_attributesArray[ExtAttrResource]

Extended attributes

Returns:



26
27
28
# File 'lib/new_store_api/models/item_resource.rb', line 26

def extended_attributes
  @extended_attributes
end

#fulfillmentString

Fulfillment method, can be SHIPPING,IN_STORE_HANDOVER

Returns:

  • (String)


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

def fulfillment
  @fulfillment
end

#idString

Line ID

Returns:

  • (String)


34
35
36
# File 'lib/new_store_api/models/item_resource.rb', line 34

def id
  @id
end

TODO: Write general description for this method

Returns:



14
15
16
# File 'lib/new_store_api/models/item_resource.rb', line 14

def links
  @links
end

#priceItemPrice

Line ID

Returns:



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

def price
  @price
end

#product_idString

Item ID

Returns:

  • (String)


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

def product_id
  @product_id
end

#quantityInteger

Number of items in the line

Returns:

  • (Integer)


46
47
48
# File 'lib/new_store_api/models/item_resource.rb', line 46

def quantity
  @quantity
end

#serial_numberString

Unique item serial number

Returns:

  • (String)


50
51
52
# File 'lib/new_store_api/models/item_resource.rb', line 50

def serial_number
  @serial_number
end

#source_idString

Source identifier

Returns:

  • (String)


54
55
56
# File 'lib/new_store_api/models/item_resource.rb', line 54

def source_id
  @source_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
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
# File 'lib/new_store_api/models/item_resource.rb', line 109

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  links = ItemLinks.from_hash(hash['_links']) if hash['_links']
  # Parameter is an array, so we need to iterate through it
  add_ons = nil
  unless hash['add_ons'].nil?
    add_ons = []
    hash['add_ons'].each do |structure|
      add_ons << (AddOnResource.from_hash(structure) if structure)
    end
  end

  add_ons = nil unless hash.key?('add_ons')
  # 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 << (ExtAttrResource.from_hash(structure) if structure)
    end
  end

  extended_attributes = nil unless hash.key?('extended_attributes')
  id = hash.key?('id') ? hash['id'] : nil
  price = ItemPrice.from_hash(hash['price']) if hash['price']
  product_id = hash.key?('product_id') ? hash['product_id'] : nil
  quantity = hash.key?('quantity') ? hash['quantity'] : nil
  epc = hash.key?('epc') ? hash['epc'] : SKIP
  fulfillment = hash.key?('fulfillment') ? hash['fulfillment'] : SKIP
  serial_number = hash.key?('serial_number') ? hash['serial_number'] : SKIP
  source_id = hash.key?('source_id') ? hash['source_id'] : SKIP

  # Create object from extracted values.
  ItemResource.new(links,
                   add_ons,
                   extended_attributes,
                   id,
                   price,
                   product_id,
                   quantity,
                   epc,
                   fulfillment,
                   serial_number,
                   source_id)
end

.namesObject

A mapping from model property names to API property names.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/new_store_api/models/item_resource.rb', line 57

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['links'] = '_links'
  @_hash['add_ons'] = 'add_ons'
  @_hash['epc'] = 'epc'
  @_hash['extended_attributes'] = 'extended_attributes'
  @_hash['fulfillment'] = 'fulfillment'
  @_hash['id'] = 'id'
  @_hash['price'] = 'price'
  @_hash['product_id'] = 'product_id'
  @_hash['quantity'] = 'quantity'
  @_hash['serial_number'] = 'serial_number'
  @_hash['source_id'] = 'source_id'
  @_hash
end

.nullablesObject

An array for nullable fields



84
85
86
87
88
89
# File 'lib/new_store_api/models/item_resource.rb', line 84

def self.nullables
  %w[
    add_ons
    extended_attributes
  ]
end

.optionalsObject

An array for optional fields



74
75
76
77
78
79
80
81
# File 'lib/new_store_api/models/item_resource.rb', line 74

def self.optionals
  %w[
    epc
    fulfillment
    serial_number
    source_id
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



167
168
169
170
171
172
173
174
# File 'lib/new_store_api/models/item_resource.rb', line 167

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} links: #{@links.inspect}, add_ons: #{@add_ons.inspect}, epc:"\
  " #{@epc.inspect}, extended_attributes: #{@extended_attributes.inspect}, fulfillment:"\
  " #{@fulfillment.inspect}, id: #{@id.inspect}, price: #{@price.inspect}, product_id:"\
  " #{@product_id.inspect}, quantity: #{@quantity.inspect}, serial_number:"\
  " #{@serial_number.inspect}, source_id: #{@source_id.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



158
159
160
161
162
163
164
# File 'lib/new_store_api/models/item_resource.rb', line 158

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} links: #{@links}, add_ons: #{@add_ons}, epc: #{@epc}, extended_attributes:"\
  " #{@extended_attributes}, fulfillment: #{@fulfillment}, id: #{@id}, price: #{@price},"\
  " product_id: #{@product_id}, quantity: #{@quantity}, serial_number: #{@serial_number},"\
  " source_id: #{@source_id}>"
end