snaptrade 2.0.119 → 2.0.120

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,321 @@
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 CryptoOrderForm
15
+ attr_accessor :instrument
16
+
17
+ # The action describes the intent or side of a trade. This is either `BUY` or `SELL`.
18
+ attr_accessor :side
19
+
20
+ # The type of order to place.
21
+ attr_accessor :type
22
+
23
+ # The Time in Force type for the order. This field indicates how long the order will remain active before it is executed or expires. - `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.
24
+ attr_accessor :time_in_force
25
+
26
+ # The amount of the base currency to buy or sell.
27
+ attr_accessor :amount
28
+
29
+ # The limit price. Required if the order type is LIMIT, STOP_LOSS_LIMIT or TAKE_PROFIT_LIMIT.
30
+ attr_accessor :limit_price
31
+
32
+ # The stop price. Required if the order type is STOP_LOSS_MARKET, STOP_LOSS_LIMIT, TAKE_PROFIT_MARKET or TAKE_PROFIT_LIMIT.
33
+ attr_accessor :stop_price
34
+
35
+ # Valid and required only for order type LIMIT. If true orders that would be filled immediately are rejected to avoid incurring TAKER fees.
36
+ attr_accessor :post_only
37
+
38
+ # The expiration date of the order. Required if the time_in_force is GTD.
39
+ attr_accessor :expiration_date
40
+
41
+ # Attribute mapping from ruby-style variable name to JSON key.
42
+ def self.attribute_map
43
+ {
44
+ :'instrument' => :'instrument',
45
+ :'side' => :'side',
46
+ :'type' => :'type',
47
+ :'time_in_force' => :'time_in_force',
48
+ :'amount' => :'amount',
49
+ :'limit_price' => :'limit_price',
50
+ :'stop_price' => :'stop_price',
51
+ :'post_only' => :'post_only',
52
+ :'expiration_date' => :'expiration_date'
53
+ }
54
+ end
55
+
56
+ # Returns all the JSON keys this model knows about
57
+ def self.acceptable_attributes
58
+ attribute_map.values
59
+ end
60
+
61
+ # Attribute type mapping.
62
+ def self.openapi_types
63
+ {
64
+ :'instrument' => :'CryptoTradingInstrument',
65
+ :'side' => :'ActionStrict',
66
+ :'type' => :'CryptoOrderFormType',
67
+ :'time_in_force' => :'CryptoOrderFormTimeInForce',
68
+ :'amount' => :'Float',
69
+ :'limit_price' => :'Float',
70
+ :'stop_price' => :'Float',
71
+ :'post_only' => :'Boolean',
72
+ :'expiration_date' => :'Time'
73
+ }
74
+ end
75
+
76
+ # List of attributes with nullable: true
77
+ def self.openapi_nullable
78
+ Set.new([
79
+ ])
80
+ end
81
+
82
+ # Initializes the object
83
+ # @param [Hash] attributes Model attributes in the form of hash
84
+ def initialize(attributes = {})
85
+ if (!attributes.is_a?(Hash))
86
+ fail ArgumentError, "The input argument (attributes) must be a hash in `SnapTrade::CryptoOrderForm` initialize method"
87
+ end
88
+
89
+ # check to see if the attribute exists and convert string to symbol for hash key
90
+ attributes = attributes.each_with_object({}) { |(k, v), h|
91
+ if (!self.class.attribute_map.key?(k.to_sym))
92
+ fail ArgumentError, "`#{k}` is not a valid attribute in `SnapTrade::CryptoOrderForm`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
93
+ end
94
+ h[k.to_sym] = v
95
+ }
96
+
97
+ if attributes.key?(:'instrument')
98
+ self.instrument = attributes[:'instrument']
99
+ end
100
+
101
+ if attributes.key?(:'side')
102
+ self.side = attributes[:'side']
103
+ end
104
+
105
+ if attributes.key?(:'type')
106
+ self.type = attributes[:'type']
107
+ end
108
+
109
+ if attributes.key?(:'time_in_force')
110
+ self.time_in_force = attributes[:'time_in_force']
111
+ end
112
+
113
+ if attributes.key?(:'amount')
114
+ self.amount = attributes[:'amount']
115
+ end
116
+
117
+ if attributes.key?(:'limit_price')
118
+ self.limit_price = attributes[:'limit_price']
119
+ end
120
+
121
+ if attributes.key?(:'stop_price')
122
+ self.stop_price = attributes[:'stop_price']
123
+ end
124
+
125
+ if attributes.key?(:'post_only')
126
+ self.post_only = attributes[:'post_only']
127
+ end
128
+
129
+ if attributes.key?(:'expiration_date')
130
+ self.expiration_date = attributes[:'expiration_date']
131
+ end
132
+ end
133
+
134
+ # Show invalid properties with the reasons. Usually used together with valid?
135
+ # @return Array for valid properties with the reasons
136
+ def list_invalid_properties
137
+ invalid_properties = Array.new
138
+ if @instrument.nil?
139
+ invalid_properties.push('invalid value for "instrument", instrument cannot be nil.')
140
+ end
141
+
142
+ if @side.nil?
143
+ invalid_properties.push('invalid value for "side", side cannot be nil.')
144
+ end
145
+
146
+ if @type.nil?
147
+ invalid_properties.push('invalid value for "type", type cannot be nil.')
148
+ end
149
+
150
+ if @time_in_force.nil?
151
+ invalid_properties.push('invalid value for "time_in_force", time_in_force cannot be nil.')
152
+ end
153
+
154
+ if @amount.nil?
155
+ invalid_properties.push('invalid value for "amount", amount cannot be nil.')
156
+ end
157
+
158
+ invalid_properties
159
+ end
160
+
161
+ # Check to see if the all the properties in the model are valid
162
+ # @return true if the model is valid
163
+ def valid?
164
+ return false if @instrument.nil?
165
+ return false if @side.nil?
166
+ return false if @type.nil?
167
+ return false if @time_in_force.nil?
168
+ return false if @amount.nil?
169
+ true
170
+ end
171
+
172
+ # Checks equality by comparing each attribute.
173
+ # @param [Object] Object to be compared
174
+ def ==(o)
175
+ return true if self.equal?(o)
176
+ self.class == o.class &&
177
+ instrument == o.instrument &&
178
+ side == o.side &&
179
+ type == o.type &&
180
+ time_in_force == o.time_in_force &&
181
+ amount == o.amount &&
182
+ limit_price == o.limit_price &&
183
+ stop_price == o.stop_price &&
184
+ post_only == o.post_only &&
185
+ expiration_date == o.expiration_date
186
+ end
187
+
188
+ # @see the `==` method
189
+ # @param [Object] Object to be compared
190
+ def eql?(o)
191
+ self == o
192
+ end
193
+
194
+ # Calculates hash code according to all attributes.
195
+ # @return [Integer] Hash code
196
+ def hash
197
+ [instrument, side, type, time_in_force, amount, limit_price, stop_price, post_only, expiration_date].hash
198
+ end
199
+
200
+ # Builds the object from hash
201
+ # @param [Hash] attributes Model attributes in the form of hash
202
+ # @return [Object] Returns the model itself
203
+ def self.build_from_hash(attributes)
204
+ new.build_from_hash(attributes)
205
+ end
206
+
207
+ # Builds the object from hash
208
+ # @param [Hash] attributes Model attributes in the form of hash
209
+ # @return [Object] Returns the model itself
210
+ def build_from_hash(attributes)
211
+ return nil unless attributes.is_a?(Hash)
212
+ attributes = attributes.transform_keys(&:to_sym)
213
+ self.class.openapi_types.each_pair do |key, type|
214
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
215
+ self.send("#{key}=", nil)
216
+ elsif type =~ /\AArray<(.*)>/i
217
+ # check to ensure the input is an array given that the attribute
218
+ # is documented as an array but the input is not
219
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
220
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
221
+ end
222
+ elsif !attributes[self.class.attribute_map[key]].nil?
223
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
224
+ end
225
+ end
226
+
227
+ self
228
+ end
229
+
230
+ # Deserializes the data based on type
231
+ # @param string type Data type
232
+ # @param string value Value to be deserialized
233
+ # @return [Object] Deserialized data
234
+ def _deserialize(type, value)
235
+ case type.to_sym
236
+ when :Time
237
+ Time.parse(value)
238
+ when :Date
239
+ Date.parse(value)
240
+ when :String
241
+ value.to_s
242
+ when :Integer
243
+ value.to_i
244
+ when :Float
245
+ value.to_f
246
+ when :Boolean
247
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
248
+ true
249
+ else
250
+ false
251
+ end
252
+ when :Object
253
+ # generic object (usually a Hash), return directly
254
+ value
255
+ when /\AArray<(?<inner_type>.+)>\z/
256
+ inner_type = Regexp.last_match[:inner_type]
257
+ value.map { |v| _deserialize(inner_type, v) }
258
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
259
+ k_type = Regexp.last_match[:k_type]
260
+ v_type = Regexp.last_match[:v_type]
261
+ {}.tap do |hash|
262
+ value.each do |k, v|
263
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
264
+ end
265
+ end
266
+ else # model
267
+ # models (e.g. Pet) or oneOf
268
+ klass = SnapTrade.const_get(type)
269
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
270
+ end
271
+ end
272
+
273
+ # Returns the string representation of the object
274
+ # @return [String] String presentation of the object
275
+ def to_s
276
+ to_hash.to_s
277
+ end
278
+
279
+ # to_body is an alias to to_hash (backward compatibility)
280
+ # @return [Hash] Returns the object in the form of hash
281
+ def to_body
282
+ to_hash
283
+ end
284
+
285
+ # Returns the object in the form of hash
286
+ # @return [Hash] Returns the object in the form of hash
287
+ def to_hash
288
+ hash = {}
289
+ self.class.attribute_map.each_pair do |attr, param|
290
+ value = self.send(attr)
291
+ if value.nil?
292
+ is_nullable = self.class.openapi_nullable.include?(attr)
293
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
294
+ end
295
+
296
+ hash[param] = _to_hash(value)
297
+ end
298
+ hash
299
+ end
300
+
301
+ # Outputs non-array value in the form of hash
302
+ # For object, use to_hash. Otherwise, just return the value
303
+ # @param [Object] value Any valid value
304
+ # @return [Hash] Returns the value in the form of hash
305
+ def _to_hash(value)
306
+ if value.is_a?(Array)
307
+ value.compact.map { |v| _to_hash(v) }
308
+ elsif value.is_a?(Hash)
309
+ {}.tap do |hash|
310
+ value.each { |k, v| hash[k] = _to_hash(v) }
311
+ end
312
+ elsif value.respond_to? :to_hash
313
+ value.to_hash
314
+ else
315
+ value
316
+ end
317
+ end
318
+
319
+ end
320
+
321
+ end
@@ -0,0 +1,39 @@
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 CryptoOrderFormTimeInForce
15
+ GTC = "GTC".freeze
16
+ FOK = "FOK".freeze
17
+ IOC = "IOC".freeze
18
+ GTD = "GTD".freeze
19
+
20
+ def self.all_vars
21
+ @all_vars ||= [GTC, FOK, IOC, GTD].freeze
22
+ end
23
+
24
+ # Builds the enum from string
25
+ # @param [String] The enum value in the form of the string
26
+ # @return [String] The enum value
27
+ def self.build_from_hash(value)
28
+ new.build_from_hash(value)
29
+ end
30
+
31
+ # Builds the enum from string
32
+ # @param [String] The enum value in the form of the string
33
+ # @return [String] The enum value
34
+ def build_from_hash(value)
35
+ return value if CryptoOrderFormTimeInForce.all_vars.include?(value)
36
+ raise "Invalid ENUM value #{value} for class #CryptoOrderFormTimeInForce"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,41 @@
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 CryptoOrderFormType
15
+ MARKET = "MARKET".freeze
16
+ LIMIT = "LIMIT".freeze
17
+ STOP_LOSS_MARKET = "STOP_LOSS_MARKET".freeze
18
+ STOP_LOSS_LIMIT = "STOP_LOSS_LIMIT".freeze
19
+ TAKE_PROFIT_MARKET = "TAKE_PROFIT_MARKET".freeze
20
+ TAKE_PROFIT_LIMIT = "TAKE_PROFIT_LIMIT".freeze
21
+
22
+ def self.all_vars
23
+ @all_vars ||= [MARKET, LIMIT, STOP_LOSS_MARKET, STOP_LOSS_LIMIT, TAKE_PROFIT_MARKET, TAKE_PROFIT_LIMIT].freeze
24
+ end
25
+
26
+ # Builds the enum from string
27
+ # @param [String] The enum value in the form of the string
28
+ # @return [String] The enum value
29
+ def self.build_from_hash(value)
30
+ new.build_from_hash(value)
31
+ end
32
+
33
+ # Builds the enum from string
34
+ # @param [String] The enum value in the form of the string
35
+ # @return [String] The enum value
36
+ def build_from_hash(value)
37
+ return value if CryptoOrderFormType.all_vars.include?(value)
38
+ raise "Invalid ENUM value #{value} for class #CryptoOrderFormType"
39
+ end
40
+ end
41
+ end
@@ -12,7 +12,7 @@ require 'time'
12
12
 
13
13
  module SnapTrade
14
14
  # Preview of an order.
15
- class SimpleOrderPreview
15
+ class CryptoOrderPreview
16
16
  attr_accessor :estimated_fee
17
17
 
18
18
  # Attribute mapping from ruby-style variable name to JSON key.
@@ -30,7 +30,7 @@ module SnapTrade
30
30
  # Attribute type mapping.
31
31
  def self.openapi_types
32
32
  {
33
- :'estimated_fee' => :'SimpleOrderPreviewEstimatedFee'
33
+ :'estimated_fee' => :'CryptoOrderPreviewEstimatedFee'
34
34
  }
35
35
  end
36
36
 
@@ -44,13 +44,13 @@ module SnapTrade
44
44
  # @param [Hash] attributes Model attributes in the form of hash
45
45
  def initialize(attributes = {})
46
46
  if (!attributes.is_a?(Hash))
47
- fail ArgumentError, "The input argument (attributes) must be a hash in `SnapTrade::SimpleOrderPreview` initialize method"
47
+ fail ArgumentError, "The input argument (attributes) must be a hash in `SnapTrade::CryptoOrderPreview` initialize method"
48
48
  end
49
49
 
50
50
  # check to see if the attribute exists and convert string to symbol for hash key
51
51
  attributes = attributes.each_with_object({}) { |(k, v), h|
52
52
  if (!self.class.attribute_map.key?(k.to_sym))
53
- fail ArgumentError, "`#{k}` is not a valid attribute in `SnapTrade::SimpleOrderPreview`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
53
+ fail ArgumentError, "`#{k}` is not a valid attribute in `SnapTrade::CryptoOrderPreview`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
54
54
  end
55
55
  h[k.to_sym] = v
56
56
  }
@@ -12,7 +12,7 @@ require 'time'
12
12
 
13
13
  module SnapTrade
14
14
  # The estimated order fee.
15
- class SimpleOrderPreviewEstimatedFee
15
+ class CryptoOrderPreviewEstimatedFee
16
16
  # Symbol to identify a cryptocurrency or fiat currency on a crypto exchange. Fiat currencies symbols are ISO-4217 codes.
17
17
  attr_accessor :currency
18
18
 
@@ -49,13 +49,13 @@ module SnapTrade
49
49
  # @param [Hash] attributes Model attributes in the form of hash
50
50
  def initialize(attributes = {})
51
51
  if (!attributes.is_a?(Hash))
52
- fail ArgumentError, "The input argument (attributes) must be a hash in `SnapTrade::SimpleOrderPreviewEstimatedFee` initialize method"
52
+ fail ArgumentError, "The input argument (attributes) must be a hash in `SnapTrade::CryptoOrderPreviewEstimatedFee` initialize method"
53
53
  end
54
54
 
55
55
  # check to see if the attribute exists and convert string to symbol for hash key
56
56
  attributes = attributes.each_with_object({}) { |(k, v), h|
57
57
  if (!self.class.attribute_map.key?(k.to_sym))
58
- fail ArgumentError, "`#{k}` is not a valid attribute in `SnapTrade::SimpleOrderPreviewEstimatedFee`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
58
+ fail ArgumentError, "`#{k}` is not a valid attribute in `SnapTrade::CryptoOrderPreviewEstimatedFee`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
59
59
  end
60
60
  h[k.to_sym] = v
61
61
  }
@@ -0,0 +1,237 @@
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 CryptoTradingInstrument
15
+ # The instrument's trading ticker symbol
16
+ attr_accessor :symbol
17
+
18
+ # The instrument's type
19
+ attr_accessor :type
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :'symbol' => :'symbol',
25
+ :'type' => :'type'
26
+ }
27
+ end
28
+
29
+ # Returns all the JSON keys this model knows about
30
+ def self.acceptable_attributes
31
+ attribute_map.values
32
+ end
33
+
34
+ # Attribute type mapping.
35
+ def self.openapi_types
36
+ {
37
+ :'symbol' => :'String',
38
+ :'type' => :'CryptoTradingInstrumentType'
39
+ }
40
+ end
41
+
42
+ # List of attributes with nullable: true
43
+ def self.openapi_nullable
44
+ Set.new([
45
+ ])
46
+ end
47
+
48
+ # Initializes the object
49
+ # @param [Hash] attributes Model attributes in the form of hash
50
+ def initialize(attributes = {})
51
+ if (!attributes.is_a?(Hash))
52
+ fail ArgumentError, "The input argument (attributes) must be a hash in `SnapTrade::CryptoTradingInstrument` initialize method"
53
+ end
54
+
55
+ # check to see if the attribute exists and convert string to symbol for hash key
56
+ attributes = attributes.each_with_object({}) { |(k, v), h|
57
+ if (!self.class.attribute_map.key?(k.to_sym))
58
+ fail ArgumentError, "`#{k}` is not a valid attribute in `SnapTrade::CryptoTradingInstrument`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
59
+ end
60
+ h[k.to_sym] = v
61
+ }
62
+
63
+ if attributes.key?(:'symbol')
64
+ self.symbol = attributes[:'symbol']
65
+ end
66
+
67
+ if attributes.key?(:'type')
68
+ self.type = attributes[:'type']
69
+ end
70
+ end
71
+
72
+ # Show invalid properties with the reasons. Usually used together with valid?
73
+ # @return Array for valid properties with the reasons
74
+ def list_invalid_properties
75
+ invalid_properties = Array.new
76
+ if @symbol.nil?
77
+ invalid_properties.push('invalid value for "symbol", symbol cannot be nil.')
78
+ end
79
+
80
+ if @type.nil?
81
+ invalid_properties.push('invalid value for "type", type cannot be nil.')
82
+ end
83
+
84
+ invalid_properties
85
+ end
86
+
87
+ # Check to see if the all the properties in the model are valid
88
+ # @return true if the model is valid
89
+ def valid?
90
+ return false if @symbol.nil?
91
+ return false if @type.nil?
92
+ true
93
+ end
94
+
95
+ # Checks equality by comparing each attribute.
96
+ # @param [Object] Object to be compared
97
+ def ==(o)
98
+ return true if self.equal?(o)
99
+ self.class == o.class &&
100
+ symbol == o.symbol &&
101
+ type == o.type
102
+ end
103
+
104
+ # @see the `==` method
105
+ # @param [Object] Object to be compared
106
+ def eql?(o)
107
+ self == o
108
+ end
109
+
110
+ # Calculates hash code according to all attributes.
111
+ # @return [Integer] Hash code
112
+ def hash
113
+ [symbol, type].hash
114
+ end
115
+
116
+ # Builds the object from hash
117
+ # @param [Hash] attributes Model attributes in the form of hash
118
+ # @return [Object] Returns the model itself
119
+ def self.build_from_hash(attributes)
120
+ new.build_from_hash(attributes)
121
+ end
122
+
123
+ # Builds the object from hash
124
+ # @param [Hash] attributes Model attributes in the form of hash
125
+ # @return [Object] Returns the model itself
126
+ def build_from_hash(attributes)
127
+ return nil unless attributes.is_a?(Hash)
128
+ attributes = attributes.transform_keys(&:to_sym)
129
+ self.class.openapi_types.each_pair do |key, type|
130
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
131
+ self.send("#{key}=", nil)
132
+ elsif type =~ /\AArray<(.*)>/i
133
+ # check to ensure the input is an array given that the attribute
134
+ # is documented as an array but the input is not
135
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
136
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
137
+ end
138
+ elsif !attributes[self.class.attribute_map[key]].nil?
139
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
140
+ end
141
+ end
142
+
143
+ self
144
+ end
145
+
146
+ # Deserializes the data based on type
147
+ # @param string type Data type
148
+ # @param string value Value to be deserialized
149
+ # @return [Object] Deserialized data
150
+ def _deserialize(type, value)
151
+ case type.to_sym
152
+ when :Time
153
+ Time.parse(value)
154
+ when :Date
155
+ Date.parse(value)
156
+ when :String
157
+ value.to_s
158
+ when :Integer
159
+ value.to_i
160
+ when :Float
161
+ value.to_f
162
+ when :Boolean
163
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
164
+ true
165
+ else
166
+ false
167
+ end
168
+ when :Object
169
+ # generic object (usually a Hash), return directly
170
+ value
171
+ when /\AArray<(?<inner_type>.+)>\z/
172
+ inner_type = Regexp.last_match[:inner_type]
173
+ value.map { |v| _deserialize(inner_type, v) }
174
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
175
+ k_type = Regexp.last_match[:k_type]
176
+ v_type = Regexp.last_match[:v_type]
177
+ {}.tap do |hash|
178
+ value.each do |k, v|
179
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
180
+ end
181
+ end
182
+ else # model
183
+ # models (e.g. Pet) or oneOf
184
+ klass = SnapTrade.const_get(type)
185
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
186
+ end
187
+ end
188
+
189
+ # Returns the string representation of the object
190
+ # @return [String] String presentation of the object
191
+ def to_s
192
+ to_hash.to_s
193
+ end
194
+
195
+ # to_body is an alias to to_hash (backward compatibility)
196
+ # @return [Hash] Returns the object in the form of hash
197
+ def to_body
198
+ to_hash
199
+ end
200
+
201
+ # Returns the object in the form of hash
202
+ # @return [Hash] Returns the object in the form of hash
203
+ def to_hash
204
+ hash = {}
205
+ self.class.attribute_map.each_pair do |attr, param|
206
+ value = self.send(attr)
207
+ if value.nil?
208
+ is_nullable = self.class.openapi_nullable.include?(attr)
209
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
210
+ end
211
+
212
+ hash[param] = _to_hash(value)
213
+ end
214
+ hash
215
+ end
216
+
217
+ # Outputs non-array value in the form of hash
218
+ # For object, use to_hash. Otherwise, just return the value
219
+ # @param [Object] value Any valid value
220
+ # @return [Hash] Returns the value in the form of hash
221
+ def _to_hash(value)
222
+ if value.is_a?(Array)
223
+ value.compact.map { |v| _to_hash(v) }
224
+ elsif value.is_a?(Hash)
225
+ {}.tap do |hash|
226
+ value.each { |k, v| hash[k] = _to_hash(v) }
227
+ end
228
+ elsif value.respond_to? :to_hash
229
+ value.to_hash
230
+ else
231
+ value
232
+ end
233
+ end
234
+
235
+ end
236
+
237
+ end