Class: NewStoreApi::CartResource
- Defined in:
- lib/new_store_api/models/cart_resource.rb
Overview
CartResource Model.
Instance Attribute Summary collapse
-
#associate_id ⇒ String
Associate ID.
-
#catalog ⇒ String
Catalog name.
-
#channel_id ⇒ String
Channel ID, corresponds to the store ID if channel_type is STORE.
-
#channel_type ⇒ String
Channel type (e.g. STORE).
-
#currency ⇒ String
ISO 4217 currency code.
-
#customer_id ⇒ String
Customer ID.
-
#device_id ⇒ String
Device ID.
-
#id ⇒ String
Cart ID.
-
#items ⇒ Array[ItemResource]
Cart ID.
-
#links ⇒ CartLinks
TODO: Write general description for this method.
-
#locale ⇒ String
Catalog locale.
-
#state ⇒ String
Cart state.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
-
.nullables ⇒ Object
An array for nullable fields.
-
.optionals ⇒ Object
An array for optional fields.
Instance Method Summary collapse
-
#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
constructor
A new instance of CartResource.
-
#inspect ⇒ Object
Provides a debugging-friendly string with detailed object information.
-
#to_s ⇒ Object
Provides a human-readable string representation of the object.
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_id ⇒ String
Associate ID
18 19 20 |
# File 'lib/new_store_api/models/cart_resource.rb', line 18 def associate_id @associate_id end |
#catalog ⇒ String
Catalog name
22 23 24 |
# File 'lib/new_store_api/models/cart_resource.rb', line 22 def catalog @catalog end |
#channel_id ⇒ String
Channel ID, corresponds to the store ID if channel_type is STORE
26 27 28 |
# File 'lib/new_store_api/models/cart_resource.rb', line 26 def channel_id @channel_id end |
#channel_type ⇒ String
Channel type (e.g. STORE)
30 31 32 |
# File 'lib/new_store_api/models/cart_resource.rb', line 30 def channel_type @channel_type end |
#currency ⇒ String
ISO 4217 currency code
34 35 36 |
# File 'lib/new_store_api/models/cart_resource.rb', line 34 def currency @currency end |
#customer_id ⇒ String
Customer ID
38 39 40 |
# File 'lib/new_store_api/models/cart_resource.rb', line 38 def customer_id @customer_id end |
#device_id ⇒ String
Device ID
42 43 44 |
# File 'lib/new_store_api/models/cart_resource.rb', line 42 def device_id @device_id end |
#id ⇒ String
Cart ID
46 47 48 |
# File 'lib/new_store_api/models/cart_resource.rb', line 46 def id @id end |
#items ⇒ Array[ItemResource]
Cart ID
50 51 52 |
# File 'lib/new_store_api/models/cart_resource.rb', line 50 def items @items end |
#links ⇒ CartLinks
TODO: Write general description for this method
14 15 16 |
# File 'lib/new_store_api/models/cart_resource.rb', line 14 def links @links end |
#locale ⇒ String
Catalog locale
54 55 56 |
# File 'lib/new_store_api/models/cart_resource.rb', line 54 def locale @locale end |
#state ⇒ String
Cart state
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 |
.names ⇒ Object
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 |
.nullables ⇒ Object
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 |
.optionals ⇒ Object
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
#inspect ⇒ Object
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_s ⇒ Object
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 |