snaptrade 2.0.172 → 2.0.174

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,248 @@
1
+ =begin
2
+ #SnapTrade
3
+
4
+ #Connect brokerage accounts to your app for live positions and trading
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ Contact: api@snaptrade.com
8
+ =end
9
+
10
+ require 'date'
11
+ require 'time'
12
+
13
+ module SnapTrade
14
+ # The Greeks for the option contract.
15
+ class OptionQuoteGreeks
16
+ # Delta represents the rate of change between the option's price and a $1 change in the underlying asset's price.
17
+ attr_accessor :delta
18
+
19
+ # Gamma represents the rate of change between an option's delta and the underlying asset's price.
20
+ attr_accessor :gamma
21
+
22
+ # Theta represents the rate of change between the option price and time, or time sensitivity - sometimes known as an option's time decay.
23
+ attr_accessor :theta
24
+
25
+ # Vega represents the rate of change between an option's value and the underlying asset's implied volatility.
26
+ attr_accessor :vega
27
+
28
+ # Attribute mapping from ruby-style variable name to JSON key.
29
+ def self.attribute_map
30
+ {
31
+ :'delta' => :'delta',
32
+ :'gamma' => :'gamma',
33
+ :'theta' => :'theta',
34
+ :'vega' => :'vega'
35
+ }
36
+ end
37
+
38
+ # Returns all the JSON keys this model knows about
39
+ def self.acceptable_attributes
40
+ attribute_map.values
41
+ end
42
+
43
+ # Attribute type mapping.
44
+ def self.openapi_types
45
+ {
46
+ :'delta' => :'Float',
47
+ :'gamma' => :'Float',
48
+ :'theta' => :'Float',
49
+ :'vega' => :'Float'
50
+ }
51
+ end
52
+
53
+ # List of attributes with nullable: true
54
+ def self.openapi_nullable
55
+ Set.new([
56
+ ])
57
+ end
58
+
59
+ # Initializes the object
60
+ # @param [Hash] attributes Model attributes in the form of hash
61
+ def initialize(attributes = {})
62
+ if (!attributes.is_a?(Hash))
63
+ fail ArgumentError, "The input argument (attributes) must be a hash in `SnapTrade::OptionQuoteGreeks` initialize method"
64
+ end
65
+
66
+ # check to see if the attribute exists and convert string to symbol for hash key
67
+ attributes = attributes.each_with_object({}) { |(k, v), h|
68
+ if (!self.class.attribute_map.key?(k.to_sym))
69
+ fail ArgumentError, "`#{k}` is not a valid attribute in `SnapTrade::OptionQuoteGreeks`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
70
+ end
71
+ h[k.to_sym] = v
72
+ }
73
+
74
+ if attributes.key?(:'delta')
75
+ self.delta = attributes[:'delta']
76
+ end
77
+
78
+ if attributes.key?(:'gamma')
79
+ self.gamma = attributes[:'gamma']
80
+ end
81
+
82
+ if attributes.key?(:'theta')
83
+ self.theta = attributes[:'theta']
84
+ end
85
+
86
+ if attributes.key?(:'vega')
87
+ self.vega = attributes[:'vega']
88
+ end
89
+ end
90
+
91
+ # Show invalid properties with the reasons. Usually used together with valid?
92
+ # @return Array for valid properties with the reasons
93
+ def list_invalid_properties
94
+ invalid_properties = Array.new
95
+ invalid_properties
96
+ end
97
+
98
+ # Check to see if the all the properties in the model are valid
99
+ # @return true if the model is valid
100
+ def valid?
101
+ true
102
+ end
103
+
104
+ # Checks equality by comparing each attribute.
105
+ # @param [Object] Object to be compared
106
+ def ==(o)
107
+ return true if self.equal?(o)
108
+ self.class == o.class &&
109
+ delta == o.delta &&
110
+ gamma == o.gamma &&
111
+ theta == o.theta &&
112
+ vega == o.vega
113
+ end
114
+
115
+ # @see the `==` method
116
+ # @param [Object] Object to be compared
117
+ def eql?(o)
118
+ self == o
119
+ end
120
+
121
+ # Calculates hash code according to all attributes.
122
+ # @return [Integer] Hash code
123
+ def hash
124
+ [delta, gamma, theta, vega].hash
125
+ end
126
+
127
+ # Builds the object from hash
128
+ # @param [Hash] attributes Model attributes in the form of hash
129
+ # @return [Object] Returns the model itself
130
+ def self.build_from_hash(attributes)
131
+ new.build_from_hash(attributes)
132
+ end
133
+
134
+ # Builds the object from hash
135
+ # @param [Hash] attributes Model attributes in the form of hash
136
+ # @return [Object] Returns the model itself
137
+ def build_from_hash(attributes)
138
+ return nil unless attributes.is_a?(Hash)
139
+ attributes = attributes.transform_keys(&:to_sym)
140
+ self.class.openapi_types.each_pair do |key, type|
141
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
142
+ self.send("#{key}=", nil)
143
+ elsif type =~ /\AArray<(.*)>/i
144
+ # check to ensure the input is an array given that the attribute
145
+ # is documented as an array but the input is not
146
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
147
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
148
+ end
149
+ elsif !attributes[self.class.attribute_map[key]].nil?
150
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
151
+ end
152
+ end
153
+
154
+ self
155
+ end
156
+
157
+ # Deserializes the data based on type
158
+ # @param string type Data type
159
+ # @param string value Value to be deserialized
160
+ # @return [Object] Deserialized data
161
+ def _deserialize(type, value)
162
+ case type.to_sym
163
+ when :Time
164
+ Time.parse(value)
165
+ when :Date
166
+ Date.parse(value)
167
+ when :String
168
+ value.to_s
169
+ when :Integer
170
+ value.to_i
171
+ when :Float
172
+ value.to_f
173
+ when :Boolean
174
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
175
+ true
176
+ else
177
+ false
178
+ end
179
+ when :Object
180
+ # generic object (usually a Hash), return directly
181
+ value
182
+ when /\AArray<(?<inner_type>.+)>\z/
183
+ inner_type = Regexp.last_match[:inner_type]
184
+ value.map { |v| _deserialize(inner_type, v) }
185
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
186
+ k_type = Regexp.last_match[:k_type]
187
+ v_type = Regexp.last_match[:v_type]
188
+ {}.tap do |hash|
189
+ value.each do |k, v|
190
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
191
+ end
192
+ end
193
+ else # model
194
+ # models (e.g. Pet) or oneOf
195
+ klass = SnapTrade.const_get(type)
196
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
197
+ end
198
+ end
199
+
200
+ # Returns the string representation of the object
201
+ # @return [String] String presentation of the object
202
+ def to_s
203
+ to_hash.to_s
204
+ end
205
+
206
+ # to_body is an alias to to_hash (backward compatibility)
207
+ # @return [Hash] Returns the object in the form of hash
208
+ def to_body
209
+ to_hash
210
+ end
211
+
212
+ # Returns the object in the form of hash
213
+ # @return [Hash] Returns the object in the form of hash
214
+ def to_hash
215
+ hash = {}
216
+ self.class.attribute_map.each_pair do |attr, param|
217
+ value = self.send(attr)
218
+ if value.nil?
219
+ is_nullable = self.class.openapi_nullable.include?(attr)
220
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
221
+ end
222
+
223
+ hash[param] = _to_hash(value)
224
+ end
225
+ hash
226
+ end
227
+
228
+ # Outputs non-array value in the form of hash
229
+ # For object, use to_hash. Otherwise, just return the value
230
+ # @param [Object] value Any valid value
231
+ # @return [Hash] Returns the value in the form of hash
232
+ def _to_hash(value)
233
+ if value.is_a?(Array)
234
+ value.compact.map { |v| _to_hash(v) }
235
+ elsif value.is_a?(Hash)
236
+ {}.tap do |hash|
237
+ value.each { |k, v| hash[k] = _to_hash(v) }
238
+ end
239
+ elsif value.respond_to? :to_hash
240
+ value.to_hash
241
+ else
242
+ value
243
+ end
244
+ end
245
+
246
+ end
247
+
248
+ end
@@ -34,13 +34,14 @@ module SnapTrade
34
34
  def self.openapi_types
35
35
  {
36
36
  :'brokerage_order_id' => :'String',
37
- :'order' => :'AccountOrderRecord'
37
+ :'order' => :'OrderUpdatedResponseOrder'
38
38
  }
39
39
  end
40
40
 
41
41
  # List of attributes with nullable: true
42
42
  def self.openapi_nullable
43
43
  Set.new([
44
+ :'order'
44
45
  ])
45
46
  end
46
47
 
@@ -0,0 +1,441 @@
1
+ =begin
2
+ #SnapTrade
3
+
4
+ #Connect brokerage accounts to your app for live positions and trading
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+ Contact: api@snaptrade.com
8
+ =end
9
+
10
+ require 'date'
11
+ require 'time'
12
+
13
+ module SnapTrade
14
+ class OrderUpdatedResponseOrder
15
+ # Order ID returned by brokerage. This is the unique identifier for the order in the brokerage system.
16
+ attr_accessor :brokerage_order_id
17
+
18
+ # Indicates the status of an order. SnapTrade does a best effort to map brokerage statuses to statuses in this enum. Possible values include: - NONE - PENDING - ACCEPTED - FAILED - REJECTED - CANCELED - PARTIAL_CANCELED - CANCEL_PENDING - EXECUTED - PARTIAL - REPLACE_PENDING - REPLACED - EXPIRED - QUEUED - TRIGGERED - ACTIVATED
19
+ attr_accessor :status
20
+
21
+ attr_accessor :universal_symbol
22
+
23
+ attr_accessor :option_symbol
24
+
25
+ attr_accessor :quote_universal_symbol
26
+
27
+ attr_accessor :quote_currency
28
+
29
+ # The action describes the intent or side of a trade. This is usually `BUY` or `SELL` but can include other potential values like the following depending on the specific brokerage. - BUY - SELL - BUY_COVER - SELL_SHORT - BUY_OPEN - BUY_CLOSE - SELL_OPEN - SELL_CLOSE
30
+ attr_accessor :action
31
+
32
+ # The total number of shares or contracts of the order. This should be the sum of the filled, canceled, and open quantities. Can be a decimal number for fractional shares.
33
+ attr_accessor :total_quantity
34
+
35
+ # The number of shares or contracts that are still open (waiting for execution). Can be a decimal number for fractional shares.
36
+ attr_accessor :open_quantity
37
+
38
+ # The number of shares or contracts that have been canceled. Can be a decimal number for fractional shares.
39
+ attr_accessor :canceled_quantity
40
+
41
+ # The number of shares or contracts that have been filled. Can be a decimal number for fractional shares.
42
+ attr_accessor :filled_quantity
43
+
44
+ # The price at which the order was executed.
45
+ attr_accessor :execution_price
46
+
47
+ # The limit price is maximum price one is willing to pay for a buy order or the minimum price one is willing to accept for a sell order. Should only apply to `Limit` and `StopLimit` orders.
48
+ attr_accessor :limit_price
49
+
50
+ # The stop price is the price at which a stop order is triggered. Should only apply to `Stop` and `StopLimit` orders.
51
+ attr_accessor :stop_price
52
+
53
+ # The type of order placed. The most common values are `Market`, `Limit`, `Stop`, and `StopLimit`. We try our best to map brokerage order types to these values. When mapping fails, we will return the brokerage's order type value.
54
+ attr_accessor :order_type
55
+
56
+ # The Time in Force type for the order. This field indicates how long the order will remain active before it is executed or expires. We try our best to map brokerage time in force values to the following. When mapping fails, we will return the brokerage's time in force value. - `Day` - Day. The order is valid only for the trading day on which it is placed. - `GTC` - Good Til Canceled. The order is valid until it is executed or canceled. - `FOK` - Fill Or Kill. The order must be executed in its entirety immediately or be canceled completely. - `IOC` - Immediate Or Cancel. The order must be executed immediately. Any portion of the order that cannot be filled immediately will be canceled. - `GTD` - Good Til Date. The order is valid until the specified date. - `MOO` - Market On Open. The order is to be executed at the day's opening price. - `EHP` - Extended Hours P.M. The order is to be placed during extended hour trading, after markets close.
57
+ attr_accessor :time_in_force
58
+
59
+ # The time the order was placed. This is the time the order was submitted to the brokerage.
60
+ attr_accessor :time_placed
61
+
62
+ # The time the order was last updated in the brokerage system. This value is not always available from the brokerage.
63
+ attr_accessor :time_updated
64
+
65
+ # The time the order was executed in the brokerage system. This value is not always available from the brokerage.
66
+ attr_accessor :time_executed
67
+
68
+ # The time the order expires. This value is not always available from the brokerage.
69
+ attr_accessor :expiry_date
70
+
71
+ # A unique ID for the security within SnapTrade, scoped to the brokerage account that the security belongs to. This is a legacy field and should not be used. Do not rely on this being a stable ID as it can change.
72
+ attr_accessor :symbol
73
+
74
+ attr_accessor :child_brokerage_order_ids
75
+
76
+ # Attribute mapping from ruby-style variable name to JSON key.
77
+ def self.attribute_map
78
+ {
79
+ :'brokerage_order_id' => :'brokerage_order_id',
80
+ :'status' => :'status',
81
+ :'universal_symbol' => :'universal_symbol',
82
+ :'option_symbol' => :'option_symbol',
83
+ :'quote_universal_symbol' => :'quote_universal_symbol',
84
+ :'quote_currency' => :'quote_currency',
85
+ :'action' => :'action',
86
+ :'total_quantity' => :'total_quantity',
87
+ :'open_quantity' => :'open_quantity',
88
+ :'canceled_quantity' => :'canceled_quantity',
89
+ :'filled_quantity' => :'filled_quantity',
90
+ :'execution_price' => :'execution_price',
91
+ :'limit_price' => :'limit_price',
92
+ :'stop_price' => :'stop_price',
93
+ :'order_type' => :'order_type',
94
+ :'time_in_force' => :'time_in_force',
95
+ :'time_placed' => :'time_placed',
96
+ :'time_updated' => :'time_updated',
97
+ :'time_executed' => :'time_executed',
98
+ :'expiry_date' => :'expiry_date',
99
+ :'symbol' => :'symbol',
100
+ :'child_brokerage_order_ids' => :'child_brokerage_order_ids'
101
+ }
102
+ end
103
+
104
+ # Returns all the JSON keys this model knows about
105
+ def self.acceptable_attributes
106
+ attribute_map.values
107
+ end
108
+
109
+ # Attribute type mapping.
110
+ def self.openapi_types
111
+ {
112
+ :'brokerage_order_id' => :'String',
113
+ :'status' => :'AccountOrderRecordStatus',
114
+ :'universal_symbol' => :'AccountOrderRecordUniversalSymbol',
115
+ :'option_symbol' => :'AccountOrderRecordOptionSymbol',
116
+ :'quote_universal_symbol' => :'AccountOrderRecordQuoteUniversalSymbol',
117
+ :'quote_currency' => :'AccountOrderRecordQuoteCurrency',
118
+ :'action' => :'String',
119
+ :'total_quantity' => :'String',
120
+ :'open_quantity' => :'String',
121
+ :'canceled_quantity' => :'String',
122
+ :'filled_quantity' => :'String',
123
+ :'execution_price' => :'Float',
124
+ :'limit_price' => :'Float',
125
+ :'stop_price' => :'Float',
126
+ :'order_type' => :'String',
127
+ :'time_in_force' => :'String',
128
+ :'time_placed' => :'Time',
129
+ :'time_updated' => :'Time',
130
+ :'time_executed' => :'Time',
131
+ :'expiry_date' => :'Time',
132
+ :'symbol' => :'String',
133
+ :'child_brokerage_order_ids' => :'AccountOrderRecordChildBrokerageOrderIds'
134
+ }
135
+ end
136
+
137
+ # List of attributes with nullable: true
138
+ def self.openapi_nullable
139
+ Set.new([
140
+ :'total_quantity',
141
+ :'open_quantity',
142
+ :'canceled_quantity',
143
+ :'filled_quantity',
144
+ :'execution_price',
145
+ :'limit_price',
146
+ :'stop_price',
147
+ :'order_type',
148
+ :'time_updated',
149
+ :'time_executed',
150
+ :'expiry_date',
151
+ :'child_brokerage_order_ids'
152
+ ])
153
+ end
154
+
155
+ # List of class defined in allOf (OpenAPI v3)
156
+ def self.openapi_all_of
157
+ [
158
+ :'AccountOrderRecord'
159
+ ]
160
+ end
161
+
162
+ # Initializes the object
163
+ # @param [Hash] attributes Model attributes in the form of hash
164
+ def initialize(attributes = {})
165
+ if (!attributes.is_a?(Hash))
166
+ fail ArgumentError, "The input argument (attributes) must be a hash in `SnapTrade::OrderUpdatedResponseOrder` initialize method"
167
+ end
168
+
169
+ # check to see if the attribute exists and convert string to symbol for hash key
170
+ attributes = attributes.each_with_object({}) { |(k, v), h|
171
+ if (!self.class.attribute_map.key?(k.to_sym))
172
+ fail ArgumentError, "`#{k}` is not a valid attribute in `SnapTrade::OrderUpdatedResponseOrder`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
173
+ end
174
+ h[k.to_sym] = v
175
+ }
176
+
177
+ if attributes.key?(:'brokerage_order_id')
178
+ self.brokerage_order_id = attributes[:'brokerage_order_id']
179
+ end
180
+
181
+ if attributes.key?(:'status')
182
+ self.status = attributes[:'status']
183
+ end
184
+
185
+ if attributes.key?(:'universal_symbol')
186
+ self.universal_symbol = attributes[:'universal_symbol']
187
+ end
188
+
189
+ if attributes.key?(:'option_symbol')
190
+ self.option_symbol = attributes[:'option_symbol']
191
+ end
192
+
193
+ if attributes.key?(:'quote_universal_symbol')
194
+ self.quote_universal_symbol = attributes[:'quote_universal_symbol']
195
+ end
196
+
197
+ if attributes.key?(:'quote_currency')
198
+ self.quote_currency = attributes[:'quote_currency']
199
+ end
200
+
201
+ if attributes.key?(:'action')
202
+ self.action = attributes[:'action']
203
+ end
204
+
205
+ if attributes.key?(:'total_quantity')
206
+ self.total_quantity = attributes[:'total_quantity']
207
+ end
208
+
209
+ if attributes.key?(:'open_quantity')
210
+ self.open_quantity = attributes[:'open_quantity']
211
+ end
212
+
213
+ if attributes.key?(:'canceled_quantity')
214
+ self.canceled_quantity = attributes[:'canceled_quantity']
215
+ end
216
+
217
+ if attributes.key?(:'filled_quantity')
218
+ self.filled_quantity = attributes[:'filled_quantity']
219
+ end
220
+
221
+ if attributes.key?(:'execution_price')
222
+ self.execution_price = attributes[:'execution_price']
223
+ end
224
+
225
+ if attributes.key?(:'limit_price')
226
+ self.limit_price = attributes[:'limit_price']
227
+ end
228
+
229
+ if attributes.key?(:'stop_price')
230
+ self.stop_price = attributes[:'stop_price']
231
+ end
232
+
233
+ if attributes.key?(:'order_type')
234
+ self.order_type = attributes[:'order_type']
235
+ end
236
+
237
+ if attributes.key?(:'time_in_force')
238
+ self.time_in_force = attributes[:'time_in_force']
239
+ end
240
+
241
+ if attributes.key?(:'time_placed')
242
+ self.time_placed = attributes[:'time_placed']
243
+ end
244
+
245
+ if attributes.key?(:'time_updated')
246
+ self.time_updated = attributes[:'time_updated']
247
+ end
248
+
249
+ if attributes.key?(:'time_executed')
250
+ self.time_executed = attributes[:'time_executed']
251
+ end
252
+
253
+ if attributes.key?(:'expiry_date')
254
+ self.expiry_date = attributes[:'expiry_date']
255
+ end
256
+
257
+ if attributes.key?(:'symbol')
258
+ self.symbol = attributes[:'symbol']
259
+ end
260
+
261
+ if attributes.key?(:'child_brokerage_order_ids')
262
+ self.child_brokerage_order_ids = attributes[:'child_brokerage_order_ids']
263
+ end
264
+ end
265
+
266
+ # Show invalid properties with the reasons. Usually used together with valid?
267
+ # @return Array for valid properties with the reasons
268
+ def list_invalid_properties
269
+ invalid_properties = Array.new
270
+ invalid_properties
271
+ end
272
+
273
+ # Check to see if the all the properties in the model are valid
274
+ # @return true if the model is valid
275
+ def valid?
276
+ true
277
+ end
278
+
279
+ # Checks equality by comparing each attribute.
280
+ # @param [Object] Object to be compared
281
+ def ==(o)
282
+ return true if self.equal?(o)
283
+ self.class == o.class &&
284
+ brokerage_order_id == o.brokerage_order_id &&
285
+ status == o.status &&
286
+ universal_symbol == o.universal_symbol &&
287
+ option_symbol == o.option_symbol &&
288
+ quote_universal_symbol == o.quote_universal_symbol &&
289
+ quote_currency == o.quote_currency &&
290
+ action == o.action &&
291
+ total_quantity == o.total_quantity &&
292
+ open_quantity == o.open_quantity &&
293
+ canceled_quantity == o.canceled_quantity &&
294
+ filled_quantity == o.filled_quantity &&
295
+ execution_price == o.execution_price &&
296
+ limit_price == o.limit_price &&
297
+ stop_price == o.stop_price &&
298
+ order_type == o.order_type &&
299
+ time_in_force == o.time_in_force &&
300
+ time_placed == o.time_placed &&
301
+ time_updated == o.time_updated &&
302
+ time_executed == o.time_executed &&
303
+ expiry_date == o.expiry_date &&
304
+ symbol == o.symbol &&
305
+ child_brokerage_order_ids == o.child_brokerage_order_ids
306
+ end
307
+
308
+ # @see the `==` method
309
+ # @param [Object] Object to be compared
310
+ def eql?(o)
311
+ self == o
312
+ end
313
+
314
+ # Calculates hash code according to all attributes.
315
+ # @return [Integer] Hash code
316
+ def hash
317
+ [brokerage_order_id, status, universal_symbol, option_symbol, quote_universal_symbol, quote_currency, action, total_quantity, open_quantity, canceled_quantity, filled_quantity, execution_price, limit_price, stop_price, order_type, time_in_force, time_placed, time_updated, time_executed, expiry_date, symbol, child_brokerage_order_ids].hash
318
+ end
319
+
320
+ # Builds the object from hash
321
+ # @param [Hash] attributes Model attributes in the form of hash
322
+ # @return [Object] Returns the model itself
323
+ def self.build_from_hash(attributes)
324
+ new.build_from_hash(attributes)
325
+ end
326
+
327
+ # Builds the object from hash
328
+ # @param [Hash] attributes Model attributes in the form of hash
329
+ # @return [Object] Returns the model itself
330
+ def build_from_hash(attributes)
331
+ return nil unless attributes.is_a?(Hash)
332
+ attributes = attributes.transform_keys(&:to_sym)
333
+ self.class.openapi_types.each_pair do |key, type|
334
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
335
+ self.send("#{key}=", nil)
336
+ elsif type =~ /\AArray<(.*)>/i
337
+ # check to ensure the input is an array given that the attribute
338
+ # is documented as an array but the input is not
339
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
340
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
341
+ end
342
+ elsif !attributes[self.class.attribute_map[key]].nil?
343
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
344
+ end
345
+ end
346
+
347
+ self
348
+ end
349
+
350
+ # Deserializes the data based on type
351
+ # @param string type Data type
352
+ # @param string value Value to be deserialized
353
+ # @return [Object] Deserialized data
354
+ def _deserialize(type, value)
355
+ case type.to_sym
356
+ when :Time
357
+ Time.parse(value)
358
+ when :Date
359
+ Date.parse(value)
360
+ when :String
361
+ value.to_s
362
+ when :Integer
363
+ value.to_i
364
+ when :Float
365
+ value.to_f
366
+ when :Boolean
367
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
368
+ true
369
+ else
370
+ false
371
+ end
372
+ when :Object
373
+ # generic object (usually a Hash), return directly
374
+ value
375
+ when /\AArray<(?<inner_type>.+)>\z/
376
+ inner_type = Regexp.last_match[:inner_type]
377
+ value.map { |v| _deserialize(inner_type, v) }
378
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
379
+ k_type = Regexp.last_match[:k_type]
380
+ v_type = Regexp.last_match[:v_type]
381
+ {}.tap do |hash|
382
+ value.each do |k, v|
383
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
384
+ end
385
+ end
386
+ else # model
387
+ # models (e.g. Pet) or oneOf
388
+ klass = SnapTrade.const_get(type)
389
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
390
+ end
391
+ end
392
+
393
+ # Returns the string representation of the object
394
+ # @return [String] String presentation of the object
395
+ def to_s
396
+ to_hash.to_s
397
+ end
398
+
399
+ # to_body is an alias to to_hash (backward compatibility)
400
+ # @return [Hash] Returns the object in the form of hash
401
+ def to_body
402
+ to_hash
403
+ end
404
+
405
+ # Returns the object in the form of hash
406
+ # @return [Hash] Returns the object in the form of hash
407
+ def to_hash
408
+ hash = {}
409
+ self.class.attribute_map.each_pair do |attr, param|
410
+ value = self.send(attr)
411
+ if value.nil?
412
+ is_nullable = self.class.openapi_nullable.include?(attr)
413
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
414
+ end
415
+
416
+ hash[param] = _to_hash(value)
417
+ end
418
+ hash
419
+ end
420
+
421
+ # Outputs non-array value in the form of hash
422
+ # For object, use to_hash. Otherwise, just return the value
423
+ # @param [Object] value Any valid value
424
+ # @return [Hash] Returns the value in the form of hash
425
+ def _to_hash(value)
426
+ if value.is_a?(Array)
427
+ value.compact.map { |v| _to_hash(v) }
428
+ elsif value.is_a?(Hash)
429
+ {}.tap do |hash|
430
+ value.each { |k, v| hash[k] = _to_hash(v) }
431
+ end
432
+ elsif value.respond_to? :to_hash
433
+ value.to_hash
434
+ else
435
+ value
436
+ end
437
+ end
438
+
439
+ end
440
+
441
+ end