Class: NewStoreApi::CartResource

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

Overview

CartResource 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, associate_id = nil, catalog = nil, channel_id = nil, channel_type = nil, currency = nil, id = nil, items = nil, locale = nil, state = nil, customer_id = SKIP, device_id = SKIP) ⇒ CartResource

Returns a new instance of CartResource.



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

def initialize(links = nil, associate_id = nil, catalog = nil,
               channel_id = nil, channel_type = nil, currency = nil,
               id = nil, items = nil, locale = nil, state = nil,
               customer_id = SKIP, device_id = SKIP)
  @links = links
  @associate_id = associate_id
  @catalog = catalog
  @channel_id = channel_id
  @channel_type = channel_type
  @currency = currency
  @customer_id = customer_id unless customer_id == SKIP
  @device_id = device_id unless device_id == SKIP
  @id = id
  @items = items
  @locale = locale
  @state = state
end

Instance Attribute Details

#associate_idString

Associate ID

Returns:

  • (String)


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

def associate_id
  @associate_id
end

#catalogString

Catalog name

Returns:

  • (String)


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

def catalog
  @catalog
end

#channel_idString

Channel ID, corresponds to the store ID if channel_type is STORE

Returns:

  • (String)


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

def channel_id
  @channel_id
end

#channel_typeString

Channel type (e.g. STORE)

Returns:

  • (String)


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

def channel_type
  @channel_type
end

#currencyString

ISO 4217 currency code

Returns:

  • (String)


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

def currency
  @currency
end

#customer_idString

Customer ID

Returns:

  • (String)


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

def customer_id
  @customer_id
end

#device_idString

Device ID

Returns:

  • (String)


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

def device_id
  @device_id
end

#idString

Cart ID

Returns:

  • (String)


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

def id
  @id
end

#itemsArray[ItemResource]

Cart ID

Returns:



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

def items
  @items
end

TODO: Write general description for this method

Returns:



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

def links
  @links
end

#localeString

Catalog locale

Returns:

  • (String)


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

def locale
  @locale
end

#stateString

Cart state

Returns:

  • (String)


58
59
60
# File 'lib/new_store_api/models/cart_resource.rb', line 58

def state
  @state
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  links = CartLinks.from_hash(hash['_links']) if hash['_links']
  associate_id = hash.key?('associate_id') ? hash['associate_id'] : nil
  catalog = hash.key?('catalog') ? hash['catalog'] : nil
  channel_id = hash.key?('channel_id') ? hash['channel_id'] : nil
  channel_type = hash.key?('channel_type') ? hash['channel_type'] : nil
  currency = hash.key?('currency') ? hash['currency'] : nil
  id = hash.key?('id') ? hash['id'] : nil
  # Parameter is an array, so we need to iterate through it
  items = nil
  unless hash['items'].nil?
    items = []
    hash['items'].each do |structure|
      items << (ItemResource.from_hash(structure) if structure)
    end
  end

  items = nil unless hash.key?('items')
  locale = hash.key?('locale') ? hash['locale'] : nil
  state = hash.key?('state') ? hash['state'] : nil
  customer_id = hash.key?('customer_id') ? hash['customer_id'] : SKIP
  device_id = hash.key?('device_id') ? hash['device_id'] : SKIP

  # Create object from extracted values.
  CartResource.new(links,
                   associate_id,
                   catalog,
                   channel_id,
                   channel_type,
                   currency,
                   id,
                   items,
                   locale,
                   state,
                   customer_id,
                   device_id)
end

.namesObject

A mapping from model property names to API property names.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/new_store_api/models/cart_resource.rb', line 61

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['links'] = '_links'
  @_hash['associate_id'] = 'associate_id'
  @_hash['catalog'] = 'catalog'
  @_hash['channel_id'] = 'channel_id'
  @_hash['channel_type'] = 'channel_type'
  @_hash['currency'] = 'currency'
  @_hash['customer_id'] = 'customer_id'
  @_hash['device_id'] = 'device_id'
  @_hash['id'] = 'id'
  @_hash['items'] = 'items'
  @_hash['locale'] = 'locale'
  @_hash['state'] = 'state'
  @_hash
end

.nullablesObject

An array for nullable fields



87
88
89
90
91
# File 'lib/new_store_api/models/cart_resource.rb', line 87

def self.nullables
  %w[
    items
  ]
end

.optionalsObject

An array for optional fields



79
80
81
82
83
84
# File 'lib/new_store_api/models/cart_resource.rb', line 79

def self.optionals
  %w[
    customer_id
    device_id
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



163
164
165
166
167
168
169
170
# File 'lib/new_store_api/models/cart_resource.rb', line 163

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} links: #{@links.inspect}, associate_id: #{@associate_id.inspect}, catalog:"\
  " #{@catalog.inspect}, channel_id: #{@channel_id.inspect}, channel_type:"\
  " #{@channel_type.inspect}, currency: #{@currency.inspect}, customer_id:"\
  " #{@customer_id.inspect}, device_id: #{@device_id.inspect}, id: #{@id.inspect}, items:"\
  " #{@items.inspect}, locale: #{@locale.inspect}, state: #{@state.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



154
155
156
157
158
159
160
# File 'lib/new_store_api/models/cart_resource.rb', line 154

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} links: #{@links}, associate_id: #{@associate_id}, catalog: #{@catalog},"\
  " channel_id: #{@channel_id}, channel_type: #{@channel_type}, currency: #{@currency},"\
  " customer_id: #{@customer_id}, device_id: #{@device_id}, id: #{@id}, items: #{@items},"\
  " locale: #{@locale}, state: #{@state}>"
end