snaptrade 2.0.217 → 2.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9b12d3207e97475d1d855d8adb86c139d4abc8cdab5d64220158a8a6686df327
4
- data.tar.gz: 9316e9b555efed30ceb1ebaf72162878e8a9c387212b6ed6ad224b2580497dd7
3
+ metadata.gz: 5349d61ab043f9918af1b6472dfc08b04af0a69c9c331eeb8f7d87c2ef71b298
4
+ data.tar.gz: c58ec1366f413c0803ee8803ab9e126eae8dc9bf8b0a9d69f9a46d3d74071560
5
5
  SHA512:
6
- metadata.gz: ad6a49682812402cfdfc0f95ba5ee652277d2b373c4a0961bde7d0b217a0044080209fe81f80e4298ef5faf211741699aed5eb1c8816ac41e291b9a535a73ebb
7
- data.tar.gz: 12ca9e303d15c7d59d906e2bfebc3878100fbdbc863e06020535e640912b50f916049e4ead2b8ba996b3906cc6cb314f58f13b5562f61fee8af7640fd584979e
6
+ metadata.gz: b14a96eb2edc26421da21e317aa6f857d50759e0bfe4c52c0d9a2a946e5c5a58ffc4820d3c0cabfb933e0f898e4203172d3d9c5e58c9f2fbb55b5768e06ae83b
7
+ data.tar.gz: a01ea3893a7d22b6e054f24030a9a79035e57cc65c16e0aebd5ff8877f6ab99c0ef9b1261953321d9685f2f8e0752a6119de3a1a3059c727581caef357469343
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- snaptrade (2.0.217)
4
+ snaptrade (2.1.0)
5
5
  faraday (>= 1.0.1, < 3.0)
6
6
  faraday-multipart (~> 1.0, >= 1.0.4)
7
7
 
@@ -43,7 +43,7 @@ GEM
43
43
  rainbow (3.1.1)
44
44
  rake (13.0.6)
45
45
  regexp_parser (2.12.0)
46
- reline (0.6.3)
46
+ reline (0.7.0)
47
47
  io-console (~> 0.5)
48
48
  rexml (3.4.4)
49
49
  rspec (3.13.2)
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  Connect brokerage accounts to your app for live positions and trading
8
8
 
9
- [![npm](https://img.shields.io/badge/gem-v2.0.217-blue)](https://rubygems.org/gems/snaptrade/versions/2.0.217)
9
+ [![npm](https://img.shields.io/badge/gem-v2.1.0-blue)](https://rubygems.org/gems/snaptrade/versions/2.1.0)
10
10
  [![More Info](https://img.shields.io/badge/More%20Info-Click%20Here-orange)](https://snaptrade.com/)
11
11
 
12
12
  </div>
@@ -54,6 +54,7 @@ Connect brokerage accounts to your app for live positions and trading
54
54
  * [`snaptrade.experimental_endpoints.get_user_account_order_detail_v2`](#snaptradeexperimental_endpointsget_user_account_order_detail_v2)
55
55
  * [`snaptrade.experimental_endpoints.get_user_account_orders_v2`](#snaptradeexperimental_endpointsget_user_account_orders_v2)
56
56
  * [`snaptrade.experimental_endpoints.get_user_account_recent_orders_v2`](#snaptradeexperimental_endpointsget_user_account_recent_orders_v2)
57
+ * [`snaptrade.experimental_endpoints.list_connection_accounts`](#snaptradeexperimental_endpointslist_connection_accounts)
57
58
  * [`snaptrade.experimental_endpoints.list_subscriptions`](#snaptradeexperimental_endpointslist_subscriptions)
58
59
  * [`snaptrade.options.list_option_holdings`](#snaptradeoptionslist_option_holdings)
59
60
  * [`snaptrade.reference_data.get_currency_exchange_rate_pair`](#snaptradereference_dataget_currency_exchange_rate_pair)
@@ -94,7 +95,7 @@ Connect brokerage accounts to your app for live positions and trading
94
95
  Add to Gemfile:
95
96
 
96
97
  ```ruby
97
- gem 'snaptrade', '~> 2.0.217'
98
+ gem 'snaptrade', '~> 2.1.0'
98
99
  ```
99
100
 
100
101
  ## Getting Started<a id="getting-started"></a>
@@ -1554,6 +1555,50 @@ false to retrieve non executed orders as well
1554
1555
  ---
1555
1556
 
1556
1557
 
1558
+ ### `snaptrade.experimental_endpoints.list_connection_accounts`<a id="snaptradeexperimental_endpointslist_connection_accounts"></a>
1559
+
1560
+ Experimental and subject to change without notice.
1561
+
1562
+ Returns the accounts that belong to the specified connection for the authenticated user, using the `kind`-discriminated account shape.
1563
+
1564
+ Each item in the response carries a `kind` field (currently only `investment` is implemented) that determines which additional fields are present -- see the `ConnectionAccount` schema.
1565
+
1566
+ On Pay as you Go / Real-time, this endpoint refreshes each account's opening date, funding date, and market value live from the brokerage on each call.
1567
+
1568
+ On Pay as you Go / Daily, this endpoint returns Daily data. Daily data is cached and refreshed once a day. Exact refresh timing may vary by brokerage. To force a refresh, use the [manual refresh endpoint](/reference/Connections/Connections_refreshBrokerageAuthorization).
1569
+
1570
+ Check your API key on the [Customer Dashboard billing page](https://dashboard.snaptrade.com/settings/billing) to see whether your plan includes real-time data.
1571
+
1572
+
1573
+ #### 🛠️ Usage<a id="🛠️-usage"></a>
1574
+
1575
+ ```ruby
1576
+ result = snaptrade.experimental_endpoints.list_connection_accounts(
1577
+ authorization_id: "87b24961-b51e-4db8-9226-f198f6518a89",
1578
+ user_id: "snaptrade-user-123",
1579
+ user_secret: "adf2aa34-8219-40f7-a6b3-60156985cc61",
1580
+ )
1581
+ p result
1582
+ ```
1583
+
1584
+ #### ⚙️ Parameters<a id="⚙️-parameters"></a>
1585
+
1586
+ ##### authorization_id: `String`<a id="authorization_id-string"></a>
1587
+ ##### user_id: `String`<a id="user_id-string"></a>
1588
+ ##### user_secret: `String`<a id="user_secret-string"></a>
1589
+ #### 🔄 Return<a id="🔄-return"></a>
1590
+
1591
+ [ConnectionAccount](./lib/snaptrade/models/connection_account.rb)
1592
+
1593
+ #### 🌐 Endpoint<a id="🌐-endpoint"></a>
1594
+
1595
+ `/connections/{authorizationId}/accounts` `GET`
1596
+
1597
+ [🔙 **Back to Table of Contents**](#table-of-contents)
1598
+
1599
+ ---
1600
+
1601
+
1557
1602
  ### `snaptrade.experimental_endpoints.list_subscriptions`<a id="snaptradeexperimental_endpointslist_subscriptions"></a>
1558
1603
 
1559
1604
  Returns active Trade Detection subscriptions for your Client ID. Cancelled subscriptions are not returned.
@@ -619,6 +619,129 @@ module SnapTrade
619
619
  end
620
620
 
621
621
 
622
+ # List accounts for a connection (discriminated union)
623
+ #
624
+ # Experimental and subject to change without notice.
625
+ #
626
+ # Returns the accounts that belong to the specified connection for the authenticated user, using the `kind`-discriminated account shape.
627
+ #
628
+ # Each item in the response carries a `kind` field (currently only `investment` is implemented) that determines which additional fields are present -- see the `ConnectionAccount` schema.
629
+ #
630
+ # On Pay as you Go / Real-time, this endpoint refreshes each account's opening date, funding date, and market value live from the brokerage on each call.
631
+ #
632
+ # On Pay as you Go / Daily, this endpoint returns Daily data. Daily data is cached and refreshed once a day. Exact refresh timing may vary by brokerage. To force a refresh, use the [manual refresh endpoint](/reference/Connections/Connections_refreshBrokerageAuthorization).
633
+ #
634
+ # Check your API key on the [Customer Dashboard billing page](https://dashboard.snaptrade.com/settings/billing) to see whether your plan includes real-time data.
635
+ #
636
+ # @param authorization_id [String]
637
+ # @param user_id [String]
638
+ # @param user_secret [String]
639
+ # @param [Hash] extra additional parameters to pass along through :header_params, :query_params, or parameter name
640
+ def list_connection_accounts(authorization_id:, user_id:, user_secret:, extra: {})
641
+ data, _status_code, _headers = list_connection_accounts_with_http_info_impl(authorization_id, user_id, user_secret, extra)
642
+ data
643
+ end
644
+
645
+ # List accounts for a connection (discriminated union)
646
+ #
647
+ # Experimental and subject to change without notice.
648
+ #
649
+ # Returns the accounts that belong to the specified connection for the authenticated user, using the `kind`-discriminated account shape.
650
+ #
651
+ # Each item in the response carries a `kind` field (currently only `investment` is implemented) that determines which additional fields are present -- see the `ConnectionAccount` schema.
652
+ #
653
+ # On Pay as you Go / Real-time, this endpoint refreshes each account's opening date, funding date, and market value live from the brokerage on each call.
654
+ #
655
+ # On Pay as you Go / Daily, this endpoint returns Daily data. Daily data is cached and refreshed once a day. Exact refresh timing may vary by brokerage. To force a refresh, use the [manual refresh endpoint](/reference/Connections/Connections_refreshBrokerageAuthorization).
656
+ #
657
+ # Check your API key on the [Customer Dashboard billing page](https://dashboard.snaptrade.com/settings/billing) to see whether your plan includes real-time data.
658
+ #
659
+ # @param authorization_id [String]
660
+ # @param user_id [String]
661
+ # @param user_secret [String]
662
+ # @param [Hash] extra additional parameters to pass along through :header_params, :query_params, or parameter name
663
+ def list_connection_accounts_with_http_info(authorization_id:, user_id:, user_secret:, extra: {})
664
+ list_connection_accounts_with_http_info_impl(authorization_id, user_id, user_secret, extra)
665
+ end
666
+
667
+ # List accounts for a connection (discriminated union)
668
+ # Experimental and subject to change without notice. Returns the accounts that belong to the specified connection for the authenticated user, using the `kind`-discriminated account shape. Each item in the response carries a `kind` field (currently only `investment` is implemented) that determines which additional fields are present -- see the `ConnectionAccount` schema. On Pay as you Go / Real-time, this endpoint refreshes each account's opening date, funding date, and market value live from the brokerage on each call. On Pay as you Go / Daily, this endpoint returns Daily data. Daily data is cached and refreshed once a day. Exact refresh timing may vary by brokerage. To force a refresh, use the [manual refresh endpoint](/reference/Connections/Connections_refreshBrokerageAuthorization). Check your API key on the [Customer Dashboard billing page](https://dashboard.snaptrade.com/settings/billing) to see whether your plan includes real-time data.
669
+ # @param authorization_id [String]
670
+ # @param user_id [String]
671
+ # @param user_secret [String]
672
+ # @param [Hash] opts the optional parameters
673
+ # @return [Array<ConnectionAccount>]
674
+ private def list_connection_accounts_impl(authorization_id, user_id, user_secret, opts = {})
675
+ data, _status_code, _headers = list_connection_accounts_with_http_info(authorization_id, user_id, user_secret, opts)
676
+ data
677
+ end
678
+
679
+ # List accounts for a connection (discriminated union)
680
+ # Experimental and subject to change without notice. Returns the accounts that belong to the specified connection for the authenticated user, using the &#x60;kind&#x60;-discriminated account shape. Each item in the response carries a &#x60;kind&#x60; field (currently only &#x60;investment&#x60; is implemented) that determines which additional fields are present -- see the &#x60;ConnectionAccount&#x60; schema. On Pay as you Go / Real-time, this endpoint refreshes each account&#39;s opening date, funding date, and market value live from the brokerage on each call. On Pay as you Go / Daily, this endpoint returns Daily data. Daily data is cached and refreshed once a day. Exact refresh timing may vary by brokerage. To force a refresh, use the [manual refresh endpoint](/reference/Connections/Connections_refreshBrokerageAuthorization). Check your API key on the [Customer Dashboard billing page](https://dashboard.snaptrade.com/settings/billing) to see whether your plan includes real-time data.
681
+ # @param authorization_id [String]
682
+ # @param user_id [String]
683
+ # @param user_secret [String]
684
+ # @param [Hash] opts the optional parameters
685
+ # @return [Array<(Array<ConnectionAccount>, Integer, Hash)>] Array<ConnectionAccount> data, response status code and response headers
686
+ private def list_connection_accounts_with_http_info_impl(authorization_id, user_id, user_secret, opts = {})
687
+ if @api_client.config.debugging
688
+ @api_client.config.logger.debug 'Calling API: ExperimentalEndpointsApi.list_connection_accounts ...'
689
+ end
690
+ # verify the required parameter 'authorization_id' is set
691
+ if @api_client.config.client_side_validation && authorization_id.nil?
692
+ fail ArgumentError, "Missing the required parameter 'authorization_id' when calling ExperimentalEndpointsApi.list_connection_accounts"
693
+ end
694
+ # verify the required parameter 'user_id' is set
695
+ if @api_client.config.client_side_validation && user_id.nil?
696
+ fail ArgumentError, "Missing the required parameter 'user_id' when calling ExperimentalEndpointsApi.list_connection_accounts"
697
+ end
698
+ # verify the required parameter 'user_secret' is set
699
+ if @api_client.config.client_side_validation && user_secret.nil?
700
+ fail ArgumentError, "Missing the required parameter 'user_secret' when calling ExperimentalEndpointsApi.list_connection_accounts"
701
+ end
702
+ # resource path
703
+ local_var_path = '/connections/{authorizationId}/accounts'.sub('{' + 'authorizationId' + '}', CGI.escape(authorization_id.to_s))
704
+
705
+ # query parameters
706
+ query_params = opts[:query_params] || {}
707
+ query_params[:'userId'] = user_id
708
+ query_params[:'userSecret'] = user_secret
709
+
710
+ # header parameters
711
+ header_params = opts[:header_params] || {}
712
+ # HTTP header 'Accept' (if needed)
713
+ header_params['Accept'] = @api_client.select_header_accept(['application/json'])
714
+
715
+ # form parameters
716
+ form_params = opts[:form_params] || {}
717
+
718
+ # http body (model)
719
+ post_body = opts[:debug_body]
720
+
721
+ # return_type
722
+ return_type = opts[:debug_return_type] || 'Array<ConnectionAccount>'
723
+
724
+ # auth_names
725
+ auth_names = opts[:debug_auth_names] || ['PartnerClientId', 'PartnerSignature', 'PartnerTimestamp']
726
+
727
+ new_options = opts.merge(
728
+ :operation => :"ExperimentalEndpointsApi.list_connection_accounts",
729
+ :header_params => header_params,
730
+ :query_params => query_params,
731
+ :form_params => form_params,
732
+ :body => post_body,
733
+ :auth_names => auth_names,
734
+ :return_type => return_type
735
+ )
736
+
737
+ data, status_code, headers, response = @api_client.call_api(:GET, local_var_path, new_options)
738
+ if @api_client.config.debugging
739
+ @api_client.config.logger.debug "API called: ExperimentalEndpointsApi#list_connection_accounts\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
740
+ end
741
+ return data, status_code, headers, response
742
+ end
743
+
744
+
622
745
  # List active Trade Detection subscriptions
623
746
  #
624
747
  # Returns active Trade Detection subscriptions for your Client ID. Cancelled subscriptions are not returned.
@@ -22,7 +22,7 @@ module SnapTrade
22
22
  # Type of instrument for the leg. - EQUITY - OPTION - CRYPTO
23
23
  attr_accessor :asset_type
24
24
 
25
- # Market Identifier Code (MIC) for the exchange on which the instrument trades.
25
+ # Market Identifier Code (MIC) for the exchange on which the instrument trades. Omitted for instruments with no listing exchange, such as index options (VIX, SPX).
26
26
  attr_accessor :exchange_mic_code
27
27
 
28
28
  # Financial Instrument Global Identifier (FIGI) if available.
@@ -21,7 +21,7 @@ module SnapTrade
21
21
  # Last known market price _per share_. The freshness of this price depends on the brokerage. Some brokerages provide real-time prices, while others provide delayed prices. It is recommended that you rely on your own third-party market data provider for most up to date prices.
22
22
  attr_accessor :price
23
23
 
24
- # Book price or average purchase price for the position. For options, this is per-contract.
24
+ # Book price or average purchase price for the position. For options, this is per-share.
25
25
  attr_accessor :cost_basis
26
26
 
27
27
  # ISO-4217 currency code for the position `price` and `cost_basis`.
@@ -0,0 +1,51 @@
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
+ # A single account under a connection, from the `kind`-discriminated union used by `Connections_listConnectionAccounts`. Use `kind` to determine which schema is present. Only `investment` is implemented today; `deposit` and `line_of_credit` will be added as additional variants in a future release.
15
+ module ConnectionAccount
16
+ class << self
17
+ # List of class defined in oneOf (OpenAPI v3)
18
+ def openapi_one_of
19
+ [
20
+ :'InvestmentAccount'
21
+ ]
22
+ end
23
+
24
+ # Discriminator's property name (OpenAPI v3)
25
+ def openapi_discriminator_name
26
+ :'kind'
27
+ end
28
+
29
+ # Discriminator's mapping (OpenAPI v3)
30
+ def openapi_discriminator_mapping
31
+ {
32
+ :'investment' => :'InvestmentAccount'
33
+ }
34
+ end
35
+
36
+ # Builds the object
37
+ # @param [Mixed] Data to be matched against the list of oneOf items
38
+ # @return [Object] Returns the model or the data itself
39
+ def build(data)
40
+ discriminator_value = data[openapi_discriminator_name]
41
+ return nil if discriminator_value.nil?
42
+
43
+ klass = openapi_discriminator_mapping[discriminator_value.to_s.to_sym]
44
+ return nil unless klass
45
+
46
+ SnapTrade.const_get(klass).build_from_hash(data)
47
+ end
48
+ end
49
+ end
50
+
51
+ end
@@ -0,0 +1,250 @@
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
+ # Contains status updates for the account sync process between SnapTrade and the brokerage, used only by `Connections_listConnectionAccounts`. Each property is optional -- a brokerage may not report sync status for every data type. `orders`/`positions`/`balances` are the timestamp of the last successful sync of that data type (null if never synced).
15
+ class ConnectionAccountSyncStatus
16
+ attr_accessor :transactions
17
+
18
+ # The last time orders were successfully synced by SnapTrade.
19
+ attr_accessor :orders
20
+
21
+ # The last time positions were successfully synced by SnapTrade.
22
+ attr_accessor :positions
23
+
24
+ # The last time balances were successfully synced by SnapTrade.
25
+ attr_accessor :balances
26
+
27
+ # Attribute mapping from ruby-style variable name to JSON key.
28
+ def self.attribute_map
29
+ {
30
+ :'transactions' => :'transactions',
31
+ :'orders' => :'orders',
32
+ :'positions' => :'positions',
33
+ :'balances' => :'balances'
34
+ }
35
+ end
36
+
37
+ # Returns all the JSON keys this model knows about
38
+ def self.acceptable_attributes
39
+ attribute_map.values
40
+ end
41
+
42
+ # Attribute type mapping.
43
+ def self.openapi_types
44
+ {
45
+ :'transactions' => :'TransactionsStatus',
46
+ :'orders' => :'Time',
47
+ :'positions' => :'Time',
48
+ :'balances' => :'Time'
49
+ }
50
+ end
51
+
52
+ # List of attributes with nullable: true
53
+ def self.openapi_nullable
54
+ Set.new([
55
+ :'orders',
56
+ :'positions',
57
+ :'balances'
58
+ ])
59
+ end
60
+
61
+ # Initializes the object
62
+ # @param [Hash] attributes Model attributes in the form of hash
63
+ def initialize(attributes = {})
64
+ if (!attributes.is_a?(Hash))
65
+ fail ArgumentError, "The input argument (attributes) must be a hash in `SnapTrade::ConnectionAccountSyncStatus` initialize method"
66
+ end
67
+
68
+ # check to see if the attribute exists and convert string to symbol for hash key
69
+ attributes = attributes.each_with_object({}) { |(k, v), h|
70
+ if (!self.class.attribute_map.key?(k.to_sym))
71
+ fail ArgumentError, "`#{k}` is not a valid attribute in `SnapTrade::ConnectionAccountSyncStatus`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
72
+ end
73
+ h[k.to_sym] = v
74
+ }
75
+
76
+ if attributes.key?(:'transactions')
77
+ self.transactions = attributes[:'transactions']
78
+ end
79
+
80
+ if attributes.key?(:'orders')
81
+ self.orders = attributes[:'orders']
82
+ end
83
+
84
+ if attributes.key?(:'positions')
85
+ self.positions = attributes[:'positions']
86
+ end
87
+
88
+ if attributes.key?(:'balances')
89
+ self.balances = attributes[:'balances']
90
+ end
91
+ end
92
+
93
+ # Show invalid properties with the reasons. Usually used together with valid?
94
+ # @return Array for valid properties with the reasons
95
+ def list_invalid_properties
96
+ invalid_properties = Array.new
97
+ invalid_properties
98
+ end
99
+
100
+ # Check to see if the all the properties in the model are valid
101
+ # @return true if the model is valid
102
+ def valid?
103
+ true
104
+ end
105
+
106
+ # Checks equality by comparing each attribute.
107
+ # @param [Object] Object to be compared
108
+ def ==(o)
109
+ return true if self.equal?(o)
110
+ self.class == o.class &&
111
+ transactions == o.transactions &&
112
+ orders == o.orders &&
113
+ positions == o.positions &&
114
+ balances == o.balances
115
+ end
116
+
117
+ # @see the `==` method
118
+ # @param [Object] Object to be compared
119
+ def eql?(o)
120
+ self == o
121
+ end
122
+
123
+ # Calculates hash code according to all attributes.
124
+ # @return [Integer] Hash code
125
+ def hash
126
+ [transactions, orders, positions, balances].hash
127
+ end
128
+
129
+ # Builds the object from hash
130
+ # @param [Hash] attributes Model attributes in the form of hash
131
+ # @return [Object] Returns the model itself
132
+ def self.build_from_hash(attributes)
133
+ new.build_from_hash(attributes)
134
+ end
135
+
136
+ # Builds the object from hash
137
+ # @param [Hash] attributes Model attributes in the form of hash
138
+ # @return [Object] Returns the model itself
139
+ def build_from_hash(attributes)
140
+ return nil unless attributes.is_a?(Hash)
141
+ attributes = attributes.transform_keys(&:to_sym)
142
+ self.class.openapi_types.each_pair do |key, type|
143
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
144
+ self.send("#{key}=", nil)
145
+ elsif type =~ /\AArray<(.*)>/i
146
+ # check to ensure the input is an array given that the attribute
147
+ # is documented as an array but the input is not
148
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
149
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
150
+ end
151
+ elsif !attributes[self.class.attribute_map[key]].nil?
152
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
153
+ end
154
+ end
155
+
156
+ self
157
+ end
158
+
159
+ # Deserializes the data based on type
160
+ # @param string type Data type
161
+ # @param string value Value to be deserialized
162
+ # @return [Object] Deserialized data
163
+ def _deserialize(type, value)
164
+ case type.to_sym
165
+ when :Time
166
+ Time.parse(value)
167
+ when :Date
168
+ Date.parse(value)
169
+ when :String
170
+ value.to_s
171
+ when :Integer
172
+ value.to_i
173
+ when :Float
174
+ value.to_f
175
+ when :Boolean
176
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
177
+ true
178
+ else
179
+ false
180
+ end
181
+ when :Object
182
+ # generic object (usually a Hash), return directly
183
+ value
184
+ when /\AArray<(?<inner_type>.+)>\z/
185
+ inner_type = Regexp.last_match[:inner_type]
186
+ value.map { |v| _deserialize(inner_type, v) }
187
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
188
+ k_type = Regexp.last_match[:k_type]
189
+ v_type = Regexp.last_match[:v_type]
190
+ {}.tap do |hash|
191
+ value.each do |k, v|
192
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
193
+ end
194
+ end
195
+ else # model
196
+ # models (e.g. Pet) or oneOf
197
+ klass = SnapTrade.const_get(type)
198
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
199
+ end
200
+ end
201
+
202
+ # Returns the string representation of the object
203
+ # @return [String] String presentation of the object
204
+ def to_s
205
+ to_hash.to_s
206
+ end
207
+
208
+ # to_body is an alias to to_hash (backward compatibility)
209
+ # @return [Hash] Returns the object in the form of hash
210
+ def to_body
211
+ to_hash
212
+ end
213
+
214
+ # Returns the object in the form of hash
215
+ # @return [Hash] Returns the object in the form of hash
216
+ def to_hash
217
+ hash = {}
218
+ self.class.attribute_map.each_pair do |attr, param|
219
+ value = self.send(attr)
220
+ if value.nil?
221
+ is_nullable = self.class.openapi_nullable.include?(attr)
222
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
223
+ end
224
+
225
+ hash[param] = _to_hash(value)
226
+ end
227
+ hash
228
+ end
229
+
230
+ # Outputs non-array value in the form of hash
231
+ # For object, use to_hash. Otherwise, just return the value
232
+ # @param [Object] value Any valid value
233
+ # @return [Hash] Returns the value in the form of hash
234
+ def _to_hash(value)
235
+ if value.is_a?(Array)
236
+ value.compact.map { |v| _to_hash(v) }
237
+ elsif value.is_a?(Hash)
238
+ {}.tap do |hash|
239
+ value.each { |k, v| hash[k] = _to_hash(v) }
240
+ end
241
+ elsif value.respond_to? :to_hash
242
+ value.to_hash
243
+ else
244
+ value
245
+ end
246
+ end
247
+
248
+ end
249
+
250
+ end