snaptrade 3.0.38 → 3.0.39
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 +4 -4
- data/README.md +37 -2
- data/lib/snaptrade/api/management_api.rb +110 -0
- data/lib/snaptrade/models/model503_currency_conversion_unavailable_response.rb +238 -0
- data/lib/snaptrade/models/partner_stats.rb +382 -0
- data/lib/snaptrade/version.rb +1 -1
- data/lib/snaptrade.rb +5 -0
- data/spec/api/management_api_spec.rb +42 -0
- data/spec/models/model503_currency_conversion_unavailable_response_spec.rb +41 -0
- data/spec/models/partner_stats_spec.rb +107 -0
- metadata +252 -243
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b5e11a52d73daa75fdd998c88c23d8055b6737600353cc6f9cf5b6530149f807
|
|
4
|
+
data.tar.gz: d85df14a9c4f11d17aba3e064e7dd09ee19caaeaed7468f78532b560bbb4c7ca
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 425f1540437a66a6ee76f52567d76bec234a333018892c6130bba2c31f00f15910262ea1a7d5d3a0668d0c6afa79b09bbe701517bc0203eb148ac7fb738a39d0
|
|
7
|
+
data.tar.gz: 16b177a50261419abd8efd23b45971d2f7b5978b8a9df7a1085f17054c894a4b079bc4783bdb9fb480f1d7365d9ca16087c82589e147a5d65b9f4f716c64ad24
|
data/README.md
CHANGED
|
@@ -63,7 +63,7 @@ backoff with jitter rather than from the headers.
|
|
|
63
63
|
See https://docs.snaptrade.com/docs/ratelimiting.
|
|
64
64
|
|
|
65
65
|
|
|
66
|
-
[](https://rubygems.org/gems/snaptrade/versions/3.0.39)
|
|
67
67
|
[](https://snaptrade.com/)
|
|
68
68
|
|
|
69
69
|
</div>
|
|
@@ -112,6 +112,7 @@ See https://docs.snaptrade.com/docs/ratelimiting.
|
|
|
112
112
|
* [`snaptrade.experimental_endpoints.get_user_account_recent_orders_v2`](#snaptradeexperimental_endpointsget_user_account_recent_orders_v2)
|
|
113
113
|
* [`snaptrade.experimental_endpoints.list_subscriptions`](#snaptradeexperimental_endpointslist_subscriptions)
|
|
114
114
|
* [`snaptrade.experimental_endpoints.place_simple_order`](#snaptradeexperimental_endpointsplace_simple_order)
|
|
115
|
+
* [`snaptrade.management.get_stats`](#snaptrademanagementget_stats)
|
|
115
116
|
* [`snaptrade.reference_data.get_partner_info`](#snaptradereference_dataget_partner_info)
|
|
116
117
|
* [`snaptrade.reference_data.get_stock_exchanges`](#snaptradereference_dataget_stock_exchanges)
|
|
117
118
|
* [`snaptrade.reference_data.get_symbols`](#snaptradereference_dataget_symbols)
|
|
@@ -143,7 +144,7 @@ See https://docs.snaptrade.com/docs/ratelimiting.
|
|
|
143
144
|
Add to Gemfile:
|
|
144
145
|
|
|
145
146
|
```ruby
|
|
146
|
-
gem 'snaptrade', '~> 3.0.
|
|
147
|
+
gem 'snaptrade', '~> 3.0.39'
|
|
147
148
|
```
|
|
148
149
|
|
|
149
150
|
## Getting Started<a id="getting-started"></a>
|
|
@@ -1730,6 +1731,40 @@ extended-hours enablement. Futures and multi-leg orders only accept regular.
|
|
|
1730
1731
|
---
|
|
1731
1732
|
|
|
1732
1733
|
|
|
1734
|
+
### `snaptrade.management.get_stats`<a id="snaptrademanagementget_stats"></a>
|
|
1735
|
+
|
|
1736
|
+
Returns user, connection, and connected asset totals for your SnapTrade Client ID. These are the same numbers shown on the Users & Connections page of the SnapTrade Dashboard.
|
|
1737
|
+
|
|
1738
|
+
User and connection counts are cached for up to 5 minutes. Connected asset values come from a snapshot calculated once a day; `assets_under_management_calculated_at` indicates when it was last calculated.
|
|
1739
|
+
|
|
1740
|
+
|
|
1741
|
+
#### 🛠️ Usage<a id="🛠️-usage"></a>
|
|
1742
|
+
|
|
1743
|
+
```ruby
|
|
1744
|
+
result = snaptrade.management.get_stats(
|
|
1745
|
+
currency: "USD",
|
|
1746
|
+
)
|
|
1747
|
+
p result
|
|
1748
|
+
```
|
|
1749
|
+
|
|
1750
|
+
#### ⚙️ Parameters<a id="⚙️-parameters"></a>
|
|
1751
|
+
|
|
1752
|
+
##### currency: `String`<a id="currency-string"></a>
|
|
1753
|
+
ISO 4217 currency code to express connected asset values in. Defaults to `USD`.
|
|
1754
|
+
|
|
1755
|
+
#### 🔄 Return<a id="🔄-return"></a>
|
|
1756
|
+
|
|
1757
|
+
[PartnerStats](./lib/snaptrade/models/partner_stats.rb)
|
|
1758
|
+
|
|
1759
|
+
#### 🌐 Endpoint<a id="🌐-endpoint"></a>
|
|
1760
|
+
|
|
1761
|
+
`/snapTrade/stats` `GET`
|
|
1762
|
+
|
|
1763
|
+
[🔙 **Back to Table of Contents**](#table-of-contents)
|
|
1764
|
+
|
|
1765
|
+
---
|
|
1766
|
+
|
|
1767
|
+
|
|
1733
1768
|
### `snaptrade.reference_data.get_partner_info`<a id="snaptradereference_dataget_partner_info"></a>
|
|
1734
1769
|
|
|
1735
1770
|
Returns configurations for your SnapTrade Client ID, including allowed brokerages and data access.
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
#SnapTrade
|
|
3
|
+
|
|
4
|
+
#Connect brokerage accounts to your app for live positions and trading. ## Rate limiting Two limits apply to requests signed with your `clientId`. The stricter one wins, and exceeding either returns `429 Too Many Requests`. - **Customer-level** — 250 requests/minute by default, scoped to your `clientId` and applied across all endpoints. Reported in `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset`. - **Account-level** — 10 requests/minute per account, scoped to (`clientId`, `accountId`). All covered operations for one account draw on the same bucket — reading balances and reading positions share it — and enforcement does not depend on the HTTP method, so updating an account consumes the same bucket as reading it. Only enforced for Personal users, and only for integrations it has been rolled out to — it is not yet in force for every Personal integration. It also does not apply on every operation that documents a 429 below. Where it applies it is reported in `X-RateLimit-Account-Limit`, `X-RateLimit-Account-Remaining` and `X-RateLimit-Account-Reset`. Do not read the absence of those headers as proof the limit is off — some configurations omit the rate limit headers while still enforcing the limit, so header absence tells you nothing about your allowance. On a 429, `X-RateLimit-Remaining: 0` means you hit the customer-level limit and `X-RateLimit-Account-Remaining: 0` means the account-level one. Wait for the corresponding `*-Reset` value (seconds) before retrying, or fall back to exponential backoff with jitter. Not every 429 is explained by those headers. A separate per-authenticated-user limit, reported in no `X-RateLimit-*` header, covers OAuth-authenticated requests and signed requests in configurations where the customer-level limit is not in effect — on the operations that use the default throttles. A few operations override those and are governed by the customer-level limit alone. The two do not stack: a signed request governed by the customer-level limit above is not additionally subject to the per-user one. If a 429 arrives with no header at zero — or with no `X-RateLimit-*` headers at all — honour `Retry-After` and back off. Treat the remaining counts as a hint, not a guarantee that the next request will succeed. Because the customer-level limit applies everywhere, any signed request can return 429. **OAuth-authenticated requests are an exception.** They are not subject to the customer-level limit and do not receive `X-RateLimit-Limit`, `X-RateLimit-Remaining` or `X-RateLimit-Reset` — do not wait on those headers or design around a customer-level allowance on this path. The account-level limit still applies to them on the account-data endpoints above, reported in the `X-RateLimit-Account-*` headers. On operations using the default throttles the per-user limit above applies to them as well, so an OAuth request can be rejected while the account headers still show capacity; on the few operations that override those throttles, OAuth callers have no per-user ceiling at all. Drive retries from `Retry-After` and exponential backoff with jitter rather than from the headers. See https://docs.snaptrade.com/docs/ratelimiting.
|
|
5
|
+
|
|
6
|
+
The version of the OpenAPI document: 1.0.0
|
|
7
|
+
Contact: api@snaptrade.com
|
|
8
|
+
=end
|
|
9
|
+
|
|
10
|
+
require 'cgi'
|
|
11
|
+
|
|
12
|
+
module SnapTrade
|
|
13
|
+
class ManagementApi
|
|
14
|
+
attr_accessor :api_client
|
|
15
|
+
|
|
16
|
+
def initialize(api_client = ApiClient.default)
|
|
17
|
+
@api_client = api_client
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Get usage stats
|
|
21
|
+
#
|
|
22
|
+
# Returns user, connection, and connected asset totals for your SnapTrade Client ID. These are the same numbers shown on the Users & Connections page of the SnapTrade Dashboard.
|
|
23
|
+
#
|
|
24
|
+
# User and connection counts are cached for up to 5 minutes. Connected asset values come from a snapshot calculated once a day; `assets_under_management_calculated_at` indicates when it was last calculated.
|
|
25
|
+
#
|
|
26
|
+
# @param currency [String] ISO 4217 currency code to express connected asset values in. Defaults to `USD`.
|
|
27
|
+
# @param [Hash] extra additional parameters to pass along through :header_params, :query_params, or parameter name
|
|
28
|
+
def get_stats(currency: SENTINEL, extra: {})
|
|
29
|
+
extra[:currency] = currency if currency != SENTINEL
|
|
30
|
+
data, _status_code, _headers = get_stats_with_http_info_impl(extra)
|
|
31
|
+
data
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Get usage stats
|
|
35
|
+
#
|
|
36
|
+
# Returns user, connection, and connected asset totals for your SnapTrade Client ID. These are the same numbers shown on the Users & Connections page of the SnapTrade Dashboard.
|
|
37
|
+
#
|
|
38
|
+
# User and connection counts are cached for up to 5 minutes. Connected asset values come from a snapshot calculated once a day; `assets_under_management_calculated_at` indicates when it was last calculated.
|
|
39
|
+
#
|
|
40
|
+
# @param currency [String] ISO 4217 currency code to express connected asset values in. Defaults to `USD`.
|
|
41
|
+
# @param [Hash] extra additional parameters to pass along through :header_params, :query_params, or parameter name
|
|
42
|
+
def get_stats_with_http_info(currency: SENTINEL, extra: {})
|
|
43
|
+
extra[:currency] = currency if currency != SENTINEL
|
|
44
|
+
get_stats_with_http_info_impl(extra)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Get usage stats
|
|
48
|
+
# Returns user, connection, and connected asset totals for your SnapTrade Client ID. These are the same numbers shown on the Users & Connections page of the SnapTrade Dashboard. User and connection counts are cached for up to 5 minutes. Connected asset values come from a snapshot calculated once a day; `assets_under_management_calculated_at` indicates when it was last calculated.
|
|
49
|
+
# @param [Hash] opts the optional parameters
|
|
50
|
+
# @option opts [String] :currency ISO 4217 currency code to express connected asset values in. Defaults to `USD`.
|
|
51
|
+
# @return [PartnerStats]
|
|
52
|
+
private def get_stats_impl(opts = {})
|
|
53
|
+
data, _status_code, _headers = get_stats_with_http_info(opts)
|
|
54
|
+
data
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Get usage stats
|
|
58
|
+
# Returns user, connection, and connected asset totals for your SnapTrade Client ID. These are the same numbers shown on the Users & Connections page of the SnapTrade Dashboard. User and connection counts are cached for up to 5 minutes. Connected asset values come from a snapshot calculated once a day; `assets_under_management_calculated_at` indicates when it was last calculated.
|
|
59
|
+
# @param [Hash] opts the optional parameters
|
|
60
|
+
# @option opts [String] :currency ISO 4217 currency code to express connected asset values in. Defaults to `USD`.
|
|
61
|
+
# @return [Array<(PartnerStats, Integer, Hash)>] PartnerStats data, response status code and response headers
|
|
62
|
+
private def get_stats_with_http_info_impl(opts = {})
|
|
63
|
+
if @api_client.config.debugging
|
|
64
|
+
@api_client.config.logger.debug 'Calling API: ManagementApi.get_stats ...'
|
|
65
|
+
end
|
|
66
|
+
# resource path
|
|
67
|
+
local_var_path = '/snapTrade/stats'
|
|
68
|
+
|
|
69
|
+
# query parameters
|
|
70
|
+
query_params = opts[:query_params] || {}
|
|
71
|
+
query_params[:'currency'] = opts[:'currency'] if !opts[:'currency'].nil?
|
|
72
|
+
|
|
73
|
+
# header parameters
|
|
74
|
+
header_params = opts[:header_params] || {}
|
|
75
|
+
# HTTP header 'Accept' (if needed)
|
|
76
|
+
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
|
77
|
+
|
|
78
|
+
# form parameters
|
|
79
|
+
form_params = opts[:form_params] || {}
|
|
80
|
+
|
|
81
|
+
# http body (model)
|
|
82
|
+
post_body = opts[:debug_body]
|
|
83
|
+
|
|
84
|
+
# return_type
|
|
85
|
+
return_type = opts[:debug_return_type] || 'PartnerStats'
|
|
86
|
+
|
|
87
|
+
# auth_names
|
|
88
|
+
auth_names = opts[:debug_auth_names] || ['PartnerClientId', 'PartnerSignature', 'PartnerTimestamp']
|
|
89
|
+
|
|
90
|
+
new_options = opts.merge(
|
|
91
|
+
:operation => :"ManagementApi.get_stats",
|
|
92
|
+
:header_params => header_params,
|
|
93
|
+
:query_params => query_params,
|
|
94
|
+
:form_params => form_params,
|
|
95
|
+
:body => post_body,
|
|
96
|
+
:auth_names => auth_names,
|
|
97
|
+
:return_type => return_type
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
data, status_code, headers, response = @api_client.call_api(:GET, local_var_path, new_options)
|
|
101
|
+
if @api_client.config.debugging
|
|
102
|
+
@api_client.config.logger.debug "API called: ManagementApi#get_stats\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
|
103
|
+
end
|
|
104
|
+
return data, status_code, headers, response
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# top-level client access to avoid having the user to insantiate their own API instances
|
|
109
|
+
Management = ManagementApi::new
|
|
110
|
+
end
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
=begin
|
|
2
|
+
#SnapTrade
|
|
3
|
+
|
|
4
|
+
#Connect brokerage accounts to your app for live positions and trading. ## Rate limiting Two limits apply to requests signed with your `clientId`. The stricter one wins, and exceeding either returns `429 Too Many Requests`. - **Customer-level** — 250 requests/minute by default, scoped to your `clientId` and applied across all endpoints. Reported in `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset`. - **Account-level** — 10 requests/minute per account, scoped to (`clientId`, `accountId`). All covered operations for one account draw on the same bucket — reading balances and reading positions share it — and enforcement does not depend on the HTTP method, so updating an account consumes the same bucket as reading it. Only enforced for Personal users, and only for integrations it has been rolled out to — it is not yet in force for every Personal integration. It also does not apply on every operation that documents a 429 below. Where it applies it is reported in `X-RateLimit-Account-Limit`, `X-RateLimit-Account-Remaining` and `X-RateLimit-Account-Reset`. Do not read the absence of those headers as proof the limit is off — some configurations omit the rate limit headers while still enforcing the limit, so header absence tells you nothing about your allowance. On a 429, `X-RateLimit-Remaining: 0` means you hit the customer-level limit and `X-RateLimit-Account-Remaining: 0` means the account-level one. Wait for the corresponding `*-Reset` value (seconds) before retrying, or fall back to exponential backoff with jitter. Not every 429 is explained by those headers. A separate per-authenticated-user limit, reported in no `X-RateLimit-*` header, covers OAuth-authenticated requests and signed requests in configurations where the customer-level limit is not in effect — on the operations that use the default throttles. A few operations override those and are governed by the customer-level limit alone. The two do not stack: a signed request governed by the customer-level limit above is not additionally subject to the per-user one. If a 429 arrives with no header at zero — or with no `X-RateLimit-*` headers at all — honour `Retry-After` and back off. Treat the remaining counts as a hint, not a guarantee that the next request will succeed. Because the customer-level limit applies everywhere, any signed request can return 429. **OAuth-authenticated requests are an exception.** They are not subject to the customer-level limit and do not receive `X-RateLimit-Limit`, `X-RateLimit-Remaining` or `X-RateLimit-Reset` — do not wait on those headers or design around a customer-level allowance on this path. The account-level limit still applies to them on the account-data endpoints above, reported in the `X-RateLimit-Account-*` headers. On operations using the default throttles the per-user limit above applies to them as well, so an OAuth request can be rejected while the account headers still show capacity; on the few operations that override those throttles, OAuth callers have no per-user ceiling at all. Drive retries from `Retry-After` and exponential backoff with jitter rather than from the headers. See https://docs.snaptrade.com/docs/ratelimiting.
|
|
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
|
+
# Example for a response that failed because exchange rates for the requested currency are unavailable
|
|
15
|
+
class Model503CurrencyConversionUnavailableResponse
|
|
16
|
+
attr_accessor :detail
|
|
17
|
+
|
|
18
|
+
attr_accessor :status_code
|
|
19
|
+
|
|
20
|
+
attr_accessor :code
|
|
21
|
+
|
|
22
|
+
# Attribute mapping from ruby-style variable name to JSON key.
|
|
23
|
+
def self.attribute_map
|
|
24
|
+
{
|
|
25
|
+
:'detail' => :'detail',
|
|
26
|
+
:'status_code' => :'status_code',
|
|
27
|
+
:'code' => :'code'
|
|
28
|
+
}
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Returns all the JSON keys this model knows about
|
|
32
|
+
def self.acceptable_attributes
|
|
33
|
+
attribute_map.values
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Attribute type mapping.
|
|
37
|
+
def self.openapi_types
|
|
38
|
+
{
|
|
39
|
+
:'detail' => :'Object',
|
|
40
|
+
:'status_code' => :'Object',
|
|
41
|
+
:'code' => :'Object'
|
|
42
|
+
}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# List of attributes with nullable: true
|
|
46
|
+
def self.openapi_nullable
|
|
47
|
+
Set.new([
|
|
48
|
+
:'detail',
|
|
49
|
+
:'status_code',
|
|
50
|
+
:'code'
|
|
51
|
+
])
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Initializes the object
|
|
55
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
|
56
|
+
def initialize(attributes = {})
|
|
57
|
+
if (!attributes.is_a?(Hash))
|
|
58
|
+
fail ArgumentError, "The input argument (attributes) must be a hash in `SnapTrade::Model503CurrencyConversionUnavailableResponse` initialize method"
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# check to see if the attribute exists and convert string to symbol for hash key
|
|
62
|
+
attributes = attributes.each_with_object({}) { |(k, v), h|
|
|
63
|
+
if (!self.class.attribute_map.key?(k.to_sym))
|
|
64
|
+
fail ArgumentError, "`#{k}` is not a valid attribute in `SnapTrade::Model503CurrencyConversionUnavailableResponse`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
|
|
65
|
+
end
|
|
66
|
+
h[k.to_sym] = v
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if attributes.key?(:'detail')
|
|
70
|
+
self.detail = attributes[:'detail']
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
if attributes.key?(:'status_code')
|
|
74
|
+
self.status_code = attributes[:'status_code']
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
if attributes.key?(:'code')
|
|
78
|
+
self.code = attributes[:'code']
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Show invalid properties with the reasons. Usually used together with valid?
|
|
83
|
+
# @return Array for valid properties with the reasons
|
|
84
|
+
def list_invalid_properties
|
|
85
|
+
invalid_properties = Array.new
|
|
86
|
+
invalid_properties
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Check to see if the all the properties in the model are valid
|
|
90
|
+
# @return true if the model is valid
|
|
91
|
+
def valid?
|
|
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
|
+
detail == o.detail &&
|
|
101
|
+
status_code == o.status_code &&
|
|
102
|
+
code == o.code
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# @see the `==` method
|
|
106
|
+
# @param [Object] Object to be compared
|
|
107
|
+
def eql?(o)
|
|
108
|
+
self == o
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Calculates hash code according to all attributes.
|
|
112
|
+
# @return [Integer] Hash code
|
|
113
|
+
def hash
|
|
114
|
+
[detail, status_code, code].hash
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Builds the object from hash
|
|
118
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
|
119
|
+
# @return [Object] Returns the model itself
|
|
120
|
+
def self.build_from_hash(attributes)
|
|
121
|
+
new.build_from_hash(attributes)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
# Builds the object from hash
|
|
125
|
+
# @param [Hash] attributes Model attributes in the form of hash
|
|
126
|
+
# @return [Object] Returns the model itself
|
|
127
|
+
def build_from_hash(attributes)
|
|
128
|
+
return nil unless attributes.is_a?(Hash)
|
|
129
|
+
attributes = attributes.transform_keys(&:to_sym)
|
|
130
|
+
self.class.openapi_types.each_pair do |key, type|
|
|
131
|
+
if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
|
|
132
|
+
self.send("#{key}=", nil)
|
|
133
|
+
elsif type =~ /\AArray<(.*)>/i
|
|
134
|
+
# check to ensure the input is an array given that the attribute
|
|
135
|
+
# is documented as an array but the input is not
|
|
136
|
+
if attributes[self.class.attribute_map[key]].is_a?(Array)
|
|
137
|
+
self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
|
|
138
|
+
end
|
|
139
|
+
elsif !attributes[self.class.attribute_map[key]].nil?
|
|
140
|
+
self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
self
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
# Deserializes the data based on type
|
|
148
|
+
# @param string type Data type
|
|
149
|
+
# @param string value Value to be deserialized
|
|
150
|
+
# @return [Object] Deserialized data
|
|
151
|
+
def _deserialize(type, value)
|
|
152
|
+
case type.to_sym
|
|
153
|
+
when :Time
|
|
154
|
+
Time.parse(value)
|
|
155
|
+
when :Date
|
|
156
|
+
Date.parse(value)
|
|
157
|
+
when :String
|
|
158
|
+
value.to_s
|
|
159
|
+
when :Integer
|
|
160
|
+
value.to_i
|
|
161
|
+
when :Float
|
|
162
|
+
value.to_f
|
|
163
|
+
when :Boolean
|
|
164
|
+
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
|
|
165
|
+
true
|
|
166
|
+
else
|
|
167
|
+
false
|
|
168
|
+
end
|
|
169
|
+
when :Object
|
|
170
|
+
# generic object (usually a Hash), return directly
|
|
171
|
+
value
|
|
172
|
+
when /\AArray<(?<inner_type>.+)>\z/
|
|
173
|
+
inner_type = Regexp.last_match[:inner_type]
|
|
174
|
+
value.map { |v| _deserialize(inner_type, v) }
|
|
175
|
+
when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
|
|
176
|
+
k_type = Regexp.last_match[:k_type]
|
|
177
|
+
v_type = Regexp.last_match[:v_type]
|
|
178
|
+
{}.tap do |hash|
|
|
179
|
+
value.each do |k, v|
|
|
180
|
+
hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
else # model
|
|
184
|
+
# models (e.g. Pet) or oneOf
|
|
185
|
+
klass = SnapTrade.const_get(type)
|
|
186
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Returns the string representation of the object
|
|
191
|
+
# @return [String] String presentation of the object
|
|
192
|
+
def to_s
|
|
193
|
+
to_hash.to_s
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# to_body is an alias to to_hash (backward compatibility)
|
|
197
|
+
# @return [Hash] Returns the object in the form of hash
|
|
198
|
+
def to_body
|
|
199
|
+
to_hash
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# Returns the object in the form of hash
|
|
203
|
+
# @return [Hash] Returns the object in the form of hash
|
|
204
|
+
def to_hash
|
|
205
|
+
hash = {}
|
|
206
|
+
self.class.attribute_map.each_pair do |attr, param|
|
|
207
|
+
value = self.send(attr)
|
|
208
|
+
if value.nil?
|
|
209
|
+
is_nullable = self.class.openapi_nullable.include?(attr)
|
|
210
|
+
next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
hash[param] = _to_hash(value)
|
|
214
|
+
end
|
|
215
|
+
hash
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# Outputs non-array value in the form of hash
|
|
219
|
+
# For object, use to_hash. Otherwise, just return the value
|
|
220
|
+
# @param [Object] value Any valid value
|
|
221
|
+
# @return [Hash] Returns the value in the form of hash
|
|
222
|
+
def _to_hash(value)
|
|
223
|
+
if value.is_a?(Array)
|
|
224
|
+
value.compact.map { |v| _to_hash(v) }
|
|
225
|
+
elsif value.is_a?(Hash)
|
|
226
|
+
{}.tap do |hash|
|
|
227
|
+
value.each { |k, v| hash[k] = _to_hash(v) }
|
|
228
|
+
end
|
|
229
|
+
elsif value.respond_to? :to_hash
|
|
230
|
+
value.to_hash
|
|
231
|
+
else
|
|
232
|
+
value
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
end
|