moneykit 0.0.2 → 0.0.5
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 +2 -2
- data/lib/moneykit/api/access_token_api.rb +53 -55
- data/lib/moneykit/api/account_numbers_api.rb +26 -26
- data/lib/moneykit/api/accounts_api.rb +88 -82
- data/lib/moneykit/api/identity_api.rb +31 -30
- data/lib/moneykit/api/institutions_api.rb +50 -48
- data/lib/moneykit/api/link_session_api.rb +47 -50
- data/lib/moneykit/api/links_api.rb +137 -81
- data/lib/moneykit/api/products_api.rb +33 -35
- data/lib/moneykit/api/transactions_api.rb +126 -101
- data/lib/moneykit/api/users_api.rb +100 -83
- data/lib/moneykit/api/webhooks_api.rb +97 -0
- data/lib/moneykit/api_client.rb +100 -103
- data/lib/moneykit/api_error.rb +14 -16
- data/lib/moneykit/configuration.rb +52 -65
- data/lib/moneykit/models/account.rb +69 -112
- data/lib/moneykit/models/account_balances.rb +64 -78
- data/lib/moneykit/models/account_group.rb +58 -61
- data/lib/moneykit/models/account_identity.rb +79 -124
- data/lib/moneykit/models/account_numbers.rb +96 -71
- data/lib/moneykit/models/account_numbers_link_product.rb +57 -69
- data/lib/moneykit/models/account_numbers_product_settings.rb +59 -63
- data/lib/moneykit/models/account_type.rb +23 -23
- data/lib/moneykit/models/account_with_account_numbers.rb +76 -124
- data/lib/moneykit/models/accounts_link_product.rb +53 -61
- data/lib/moneykit/models/ach_number.rb +57 -65
- data/lib/moneykit/models/address.rb +70 -90
- data/lib/moneykit/models/api_error_auth_expired_access_token_response.rb +72 -78
- data/lib/moneykit/models/api_error_auth_unauthorized_response.rb +69 -78
- data/lib/moneykit/models/api_error_rate_limit_exceeded_response.rb +72 -78
- data/lib/moneykit/models/app.rb +46 -50
- data/lib/moneykit/models/bacs_number.rb +53 -61
- data/lib/moneykit/models/balances.rb +58 -64
- data/lib/moneykit/models/basic_account_details.rb +62 -77
- data/lib/moneykit/models/country.rb +13 -14
- data/lib/moneykit/models/create_link_session_request.rb +109 -119
- data/lib/moneykit/models/create_link_session_response.rb +48 -52
- data/lib/moneykit/models/currency.rb +193 -193
- data/lib/moneykit/models/cursor.rb +40 -39
- data/lib/moneykit/models/cursor_pagination.rb +49 -54
- data/lib/moneykit/models/cursors.rb +40 -39
- data/lib/moneykit/models/customer_app.rb +54 -64
- data/lib/moneykit/models/customer_user.rb +59 -69
- data/lib/moneykit/models/eft_number.rb +56 -67
- data/lib/moneykit/models/email.rb +56 -63
- data/lib/moneykit/models/email1.rb +50 -53
- data/lib/moneykit/models/exchange_token_request.rb +48 -52
- data/lib/moneykit/models/exchange_token_response.rb +54 -64
- data/lib/moneykit/models/generate_access_token_response.rb +59 -73
- data/lib/moneykit/models/get_account_numbers_response.rb +58 -66
- data/lib/moneykit/models/get_account_response.rb +55 -67
- data/lib/moneykit/models/get_accounts_response.rb +58 -67
- data/lib/moneykit/models/get_institutions_response.rb +58 -67
- data/lib/moneykit/models/get_transactions_response.rb +81 -105
- data/lib/moneykit/models/get_user_accounts_response.rb +50 -58
- data/lib/moneykit/models/get_user_links_response.rb +50 -58
- data/lib/moneykit/models/get_user_transactions_response.rb +75 -95
- data/lib/moneykit/models/http_validation_error.rb +77 -84
- data/lib/moneykit/models/identity.rb +49 -49
- data/lib/moneykit/models/identity_link_product.rb +57 -69
- data/lib/moneykit/models/identity_product_settings.rb +59 -63
- data/lib/moneykit/models/identity_response.rb +58 -67
- data/lib/moneykit/models/institution.rb +85 -113
- data/lib/moneykit/models/institution_error_not_found_response.rb +72 -80
- data/lib/moneykit/models/institution_styling_response.rb +77 -93
- data/lib/moneykit/models/international_number.rb +54 -64
- data/lib/moneykit/models/introspect_client_response.rb +70 -89
- data/lib/moneykit/models/jwk_set.rb +51 -55
- data/lib/moneykit/models/link.rb +78 -100
- data/lib/moneykit/models/link1.rb +78 -100
- data/lib/moneykit/models/link2.rb +78 -100
- data/lib/moneykit/models/link3.rb +78 -100
- data/lib/moneykit/models/link4.rb +78 -100
- data/lib/moneykit/models/link_common.rb +82 -117
- data/lib/moneykit/models/link_error.rb +19 -19
- data/lib/moneykit/models/link_error_bad_config_response.rb +269 -0
- data/lib/moneykit/models/link_error_bad_state_response.rb +71 -88
- data/lib/moneykit/models/link_error_deleted_response.rb +72 -80
- data/lib/moneykit/models/link_error_forbidden_action_response.rb +69 -78
- data/lib/moneykit/models/link_error_not_found_response.rb +72 -80
- data/lib/moneykit/models/link_error_unauthorized_access_response.rb +72 -80
- data/lib/moneykit/models/link_permission_scope.rb +14 -15
- data/lib/moneykit/models/link_permissions.rb +52 -62
- data/lib/moneykit/models/link_products.rb +62 -78
- data/lib/moneykit/models/link_response.rb +95 -136
- data/lib/moneykit/models/link_session_customer_user.rb +65 -83
- data/lib/moneykit/models/link_session_customer_user_email.rb +59 -68
- data/lib/moneykit/models/link_session_customer_user_phone.rb +67 -82
- data/lib/moneykit/models/link_session_error_forbidden_config_response.rb +69 -78
- data/lib/moneykit/models/link_session_error_invalid_token_exchange.rb +69 -78
- data/lib/moneykit/models/link_session_setting_overrides.rb +64 -99
- data/lib/moneykit/models/link_state.rb +15 -16
- data/lib/moneykit/models/link_state_changed_webhook.rb +121 -148
- data/lib/moneykit/models/location_inner.rb +41 -46
- data/lib/moneykit/models/money_kit_env.rb +12 -13
- data/lib/moneykit/models/money_link_features.rb +62 -66
- data/lib/moneykit/models/moneylink_features.rb +50 -49
- data/lib/moneykit/models/numbers.rb +60 -73
- data/lib/moneykit/models/owner.rb +76 -89
- data/lib/moneykit/models/phone.rb +60 -68
- data/lib/moneykit/models/phone_number.rb +63 -74
- data/lib/moneykit/models/phone_number_type.rb +14 -15
- data/lib/moneykit/models/product.rb +14 -15
- data/lib/moneykit/models/products.rb +52 -64
- data/lib/moneykit/models/products1.rb +48 -56
- data/lib/moneykit/models/products_settings.rb +58 -70
- data/lib/moneykit/models/provider.rb +18 -17
- data/lib/moneykit/models/public_link_error.rb +43 -0
- data/lib/moneykit/models/refresh_products_request.rb +52 -65
- data/lib/moneykit/models/requested_link_permission.rb +60 -75
- data/lib/moneykit/models/response401_disconnect_links_id_delete.rb +83 -283
- data/lib/moneykit/models/response401_exchange_token_link_session_exchange_token_post.rb +82 -281
- data/lib/moneykit/models/response401_get_account_links_id_accounts_account_id_get.rb +83 -283
- data/lib/moneykit/models/response401_get_account_numbers_links_id_accounts_numbers_get.rb +83 -283
- data/lib/moneykit/models/response401_get_accounts_links_id_accounts_get.rb +83 -283
- data/lib/moneykit/models/response401_get_identities_links_id_identity_get.rb +83 -283
- data/lib/moneykit/models/response401_get_institution_institutions_institution_id_get.rb +82 -281
- data/lib/moneykit/models/response401_get_institution_styling_institutions_institution_id_styling_get.rb +66 -72
- data/lib/moneykit/models/response401_get_institutions_institutions_get.rb +82 -281
- data/lib/moneykit/models/response401_get_link_links_id_get.rb +83 -283
- data/lib/moneykit/models/response401_get_transactions_diff_links_id_transactions_sync_get.rb +83 -283
- data/lib/moneykit/models/response401_get_transactions_links_id_transactions_get.rb +83 -283
- data/lib/moneykit/models/response401_get_user_accounts_users_id_accounts_get.rb +82 -281
- data/lib/moneykit/models/response401_get_user_links_users_id_links_get.rb +82 -281
- data/lib/moneykit/models/response401_get_user_transactions_users_id_transactions_get.rb +82 -281
- data/lib/moneykit/models/response401_get_well_known_jwks_well_known_jwks_json_get.rb +82 -281
- data/lib/moneykit/models/response401_instrospect_client_auth_introspect_get.rb +82 -281
- data/lib/moneykit/models/response401_refresh_products_links_id_products_post.rb +83 -283
- data/lib/moneykit/models/response401_reset_login_links_id_reset_post.rb +102 -0
- data/lib/moneykit/models/response401_trigger_test_link_webhook_event_webhooks_test_link_id_post.rb +102 -0
- data/lib/moneykit/models/response401_update_link_links_id_patch.rb +83 -283
- data/lib/moneykit/models/settings.rb +61 -73
- data/lib/moneykit/models/supported_version.rb +11 -12
- data/lib/moneykit/models/transaction.rb +104 -131
- data/lib/moneykit/models/transaction_diff.rb +69 -78
- data/lib/moneykit/models/transaction_sync_response.rb +65 -87
- data/lib/moneykit/models/transaction_type.rb +12 -13
- data/lib/moneykit/models/transaction_type_filter.rb +12 -13
- data/lib/moneykit/models/transactions.rb +58 -57
- data/lib/moneykit/models/transactions1.rb +55 -63
- data/lib/moneykit/models/transactions_link_product.rb +57 -69
- data/lib/moneykit/models/transactions_product_settings.rb +67 -71
- data/lib/moneykit/models/update_link_request.rb +63 -69
- data/lib/moneykit/models/user_accounts_out.rb +40 -40
- data/lib/moneykit/models/user_links_out.rb +40 -40
- data/lib/moneykit/models/user_transactions_paged_response.rb +40 -40
- data/lib/moneykit/models/validation_error.rb +63 -77
- data/lib/moneykit/models/validation_error_location_inner.rb +101 -0
- data/lib/moneykit/models/webhook_link_test_event.rb +40 -0
- data/lib/moneykit/models/webhook_test_link_request.rb +252 -0
- data/lib/moneykit/models/webhook_test_link_response.rb +220 -0
- data/lib/moneykit/version.rb +10 -12
- data/lib/moneykit.rb +18 -39
- data/lib/plaid_compatible/money_kit_plaid_compatible/api/plaid_api.rb +738 -737
- data/lib/plaid_compatible/money_kit_plaid_compatible/api_client.rb +339 -340
- data/lib/plaid_compatible/money_kit_plaid_compatible/api_error.rb +47 -47
- data/lib/plaid_compatible/money_kit_plaid_compatible/configuration.rb +258 -260
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/account_balance.rb +210 -212
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/account_base.rb +221 -237
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/account_identity.rb +231 -252
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/account_subtype.rb +100 -101
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/account_type.rb +35 -36
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/accounts_get_request.rb +209 -211
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/accounts_get_request_options.rb +188 -185
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/accounts_get_response.rb +205 -210
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/address.rb +195 -193
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/address_data.rb +222 -226
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/auth_get_numbers.rb +218 -226
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/auth_get_request.rb +209 -211
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/auth_get_request_options.rb +188 -185
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/auth_get_response.rb +211 -222
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/country_code.rb +32 -33
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/email.rb +197 -198
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/http_validation_error.rb +183 -181
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/identity_get_request.rb +209 -211
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/identity_get_request_options.rb +188 -185
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/identity_get_response.rb +205 -210
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/institution.rb +228 -232
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/institutions_get_by_id_request.rb +216 -217
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/institutions_get_by_id_response.rb +195 -196
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/item.rb +251 -261
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/item_error_webhook.rb +217 -229
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/item_get_request.rb +205 -205
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/item_get_response.rb +201 -205
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/item_public_token_exchange_request.rb +205 -205
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/item_public_token_exchange_response.rb +206 -211
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/item_remove_request.rb +205 -205
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/item_remove_response.rb +188 -185
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/item_status_investments.rb +195 -193
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/item_status_last_webhook.rb +195 -193
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/item_status_nullable.rb +194 -198
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/item_status_transactions.rb +195 -193
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/link_token_create_request.rb +272 -291
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/link_token_create_request_user.rb +225 -225
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/link_token_create_response.rb +206 -211
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/numbers_ach.rb +215 -221
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/numbers_bacs.rb +206 -211
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/numbers_eft.rb +215 -224
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/numbers_international.rb +206 -211
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/owner.rb +218 -226
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/personal_finance_category.rb +197 -198
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/phone_number.rb +206 -211
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/plaid_error.rb +253 -266
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/plaid_error_type.rb +43 -44
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/products.rb +33 -34
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/removed_transaction.rb +187 -183
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/transaction.rb +288 -315
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/transactions_get_request.rb +225 -235
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/transactions_get_request_options.rb +222 -224
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/transactions_get_response.rb +225 -236
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/transactions_refresh_request.rb +205 -205
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/transactions_refresh_response.rb +188 -185
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/transactions_sync_request.rb +223 -229
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/transactions_sync_request_options.rb +197 -193
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/transactions_sync_response.rb +235 -252
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/validation_error.rb +198 -207
- data/lib/plaid_compatible/money_kit_plaid_compatible/models/webhook_environment_values.rb +32 -33
- data/lib/plaid_compatible/money_kit_plaid_compatible/version.rb +14 -14
- data/lib/plaid_compatible/money_kit_plaid_compatible.rb +24 -24
- data/moneykit.gemspec +22 -25
- metadata +14 -5
data/lib/moneykit/api_client.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
=end
|
1
|
+
# #MoneyKit API
|
2
|
+
#
|
3
|
+
# No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
4
|
+
#
|
5
|
+
# The version of the OpenAPI document: 0.1.0
|
6
|
+
#
|
7
|
+
# Generated by: https://openapi-generator.tech
|
8
|
+
# OpenAPI Generator version: 7.1.0
|
9
|
+
#
|
12
10
|
|
13
11
|
require 'date'
|
14
12
|
require 'json'
|
@@ -48,39 +46,39 @@ module MoneyKit
|
|
48
46
|
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
|
49
47
|
# the data deserialized from response body (could be nil), response status code and response headers.
|
50
48
|
def call_api(http_method, path, opts = {})
|
49
|
+
stream = nil
|
51
50
|
begin
|
52
51
|
response = connection(opts).public_send(http_method.to_sym.downcase) do |req|
|
53
52
|
build_request(http_method, path, req, opts)
|
53
|
+
stream = download_file(request) if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
|
54
54
|
end
|
55
55
|
|
56
|
-
if config.debugging
|
57
|
-
config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
58
|
-
end
|
56
|
+
config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n" if config.debugging
|
59
57
|
|
60
58
|
unless response.success?
|
61
59
|
if response.status == 0 && response.respond_to?(:return_message)
|
62
60
|
# Errors from libcurl will be made visible here
|
63
|
-
|
64
|
-
|
61
|
+
raise ApiError.new(code: 0,
|
62
|
+
message: response.return_message)
|
65
63
|
else
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
64
|
+
raise ApiError.new(code: response.status,
|
65
|
+
response_headers: response.headers,
|
66
|
+
response_body: response.body),
|
67
|
+
response.reason_phrase
|
70
68
|
end
|
71
69
|
end
|
72
70
|
rescue Faraday::TimeoutError
|
73
|
-
|
71
|
+
raise ApiError, 'Connection timed out'
|
74
72
|
rescue Faraday::ConnectionFailed
|
75
|
-
|
73
|
+
raise ApiError, 'Connection failed'
|
76
74
|
end
|
77
75
|
|
78
|
-
if opts[:return_type]
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
76
|
+
data = if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
|
77
|
+
deserialize_file(stream)
|
78
|
+
elsif opts[:return_type]
|
79
|
+
deserialize(response, opts[:return_type])
|
80
|
+
end
|
81
|
+
[data, response.status, response.headers]
|
84
82
|
end
|
85
83
|
|
86
84
|
# Builds the HTTP request
|
@@ -102,11 +100,9 @@ module MoneyKit
|
|
102
100
|
|
103
101
|
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
104
102
|
|
105
|
-
if [
|
103
|
+
if %i[post patch put delete].include?(http_method)
|
106
104
|
req_body = build_request_body(header_params, form_params, opts[:body])
|
107
|
-
if config.debugging
|
108
|
-
config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
109
|
-
end
|
105
|
+
config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n" if config.debugging
|
110
106
|
end
|
111
107
|
request.headers = header_params
|
112
108
|
request.body = req_body
|
@@ -117,7 +113,6 @@ module MoneyKit
|
|
117
113
|
|
118
114
|
request.url url
|
119
115
|
request.params = query_params
|
120
|
-
download_file(request) if opts[:return_type] == 'File' || opts[:return_type] == 'Binary'
|
121
116
|
request
|
122
117
|
end
|
123
118
|
|
@@ -134,16 +129,16 @@ module MoneyKit
|
|
134
129
|
elsif header_params['Content-Type'] == 'multipart/form-data'
|
135
130
|
data = {}
|
136
131
|
form_params.each do |key, value|
|
137
|
-
case value
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
132
|
+
data[key] = case value
|
133
|
+
when ::File, ::Tempfile
|
134
|
+
# TODO: hardcode to application/octet-stream, need better way to detect content type
|
135
|
+
Faraday::FilePart.new(value.path, 'application/octet-stream', value.path)
|
136
|
+
when ::Array, nil
|
137
|
+
# let Faraday handle Array and nil parameters
|
138
|
+
value
|
139
|
+
else
|
140
|
+
value.to_s
|
141
|
+
end
|
147
142
|
end
|
148
143
|
elsif body
|
149
144
|
data = body.is_a?(String) ? body : body.to_json
|
@@ -154,11 +149,40 @@ module MoneyKit
|
|
154
149
|
end
|
155
150
|
|
156
151
|
def download_file(request)
|
157
|
-
|
152
|
+
stream = []
|
158
153
|
|
159
154
|
# handle streaming Responses
|
160
|
-
request.options.on_data =
|
161
|
-
|
155
|
+
request.options.on_data = proc do |chunk, _overall_received_bytes|
|
156
|
+
stream << chunk
|
157
|
+
end
|
158
|
+
stream
|
159
|
+
end
|
160
|
+
|
161
|
+
def deserialize_file(response, stream)
|
162
|
+
body = response.body
|
163
|
+
if @config.return_binary_data == true
|
164
|
+
# return byte stream
|
165
|
+
encoding = body.encoding
|
166
|
+
stream.join.force_encoding(encoding)
|
167
|
+
else
|
168
|
+
# return file instead of binary data
|
169
|
+
content_disposition = response.headers['Content-Disposition']
|
170
|
+
if content_disposition && content_disposition =~ /filename=/i
|
171
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
172
|
+
prefix = sanitize_filename(filename)
|
173
|
+
else
|
174
|
+
prefix = 'download-'
|
175
|
+
end
|
176
|
+
prefix += '-' unless prefix.end_with?('-')
|
177
|
+
encoding = body.encoding
|
178
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
179
|
+
tempfile.write(stream.join.force_encoding(encoding))
|
180
|
+
tempfile.close
|
181
|
+
config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
182
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
183
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
184
|
+
'explicitly with `tempfile.delete`'
|
185
|
+
tempfile
|
162
186
|
end
|
163
187
|
end
|
164
188
|
|
@@ -198,12 +222,12 @@ module MoneyKit
|
|
198
222
|
end
|
199
223
|
|
200
224
|
def basic_auth(conn)
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
225
|
+
return unless config.username && config.password
|
226
|
+
|
227
|
+
if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
|
228
|
+
conn.request(:authorization, :basic, config.username, config.password)
|
229
|
+
else
|
230
|
+
conn.request(:basic_auth, config.username, config.password)
|
207
231
|
end
|
208
232
|
end
|
209
233
|
|
@@ -216,7 +240,7 @@ module MoneyKit
|
|
216
240
|
# @param [String] mime MIME
|
217
241
|
# @return [Boolean] True if the MIME is application/json
|
218
242
|
def json_mime?(mime)
|
219
|
-
(mime == '*/*') || !(mime =~
|
243
|
+
(mime == '*/*') || !(mime =~ %r{Application/.*json(?!p)(;.*)?}i).nil?
|
220
244
|
end
|
221
245
|
|
222
246
|
# Deserialize the response to the given return type.
|
@@ -225,54 +249,22 @@ module MoneyKit
|
|
225
249
|
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
226
250
|
def deserialize(response, return_type)
|
227
251
|
body = response.body
|
228
|
-
|
229
|
-
# handle file downloading - return the File instance processed in request callbacks
|
230
|
-
# note that response body is empty when the file is written in chunks in request on_body callback
|
231
|
-
if return_type == 'File'
|
232
|
-
if @config.return_binary_data == true
|
233
|
-
# return byte stream
|
234
|
-
encoding = body.encoding
|
235
|
-
return @stream.join.force_encoding(encoding)
|
236
|
-
else
|
237
|
-
# return file instead of binary data
|
238
|
-
content_disposition = response.headers['Content-Disposition']
|
239
|
-
if content_disposition && content_disposition =~ /filename=/i
|
240
|
-
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
241
|
-
prefix = sanitize_filename(filename)
|
242
|
-
else
|
243
|
-
prefix = 'download-'
|
244
|
-
end
|
245
|
-
prefix = prefix + '-' unless prefix.end_with?('-')
|
246
|
-
encoding = body.encoding
|
247
|
-
@tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
248
|
-
@tempfile.write(@stream.join.force_encoding(encoding))
|
249
|
-
@tempfile.close
|
250
|
-
@config.logger.info "Temp file written to #{@tempfile.path}, please copy the file to a proper folder "\
|
251
|
-
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
252
|
-
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
253
|
-
"explicitly with `tempfile.delete`"
|
254
|
-
return @tempfile
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
252
|
return nil if body.nil? || body.empty?
|
259
253
|
|
260
254
|
# return response body directly for String return type
|
261
|
-
return body if return_type == 'String'
|
255
|
+
return body.to_s if return_type == 'String'
|
262
256
|
|
263
257
|
# ensuring a default content type
|
264
258
|
content_type = response.headers['Content-Type'] || 'application/json'
|
265
259
|
|
266
|
-
|
260
|
+
raise "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
267
261
|
|
268
262
|
begin
|
269
|
-
data = JSON.parse("[#{body}]", :
|
263
|
+
data = JSON.parse("[#{body}]", symbolize_names: true)[0]
|
270
264
|
rescue JSON::ParserError => e
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
raise e
|
275
|
-
end
|
265
|
+
raise e unless %w[String Date Time].include?(return_type)
|
266
|
+
|
267
|
+
data = body
|
276
268
|
end
|
277
269
|
|
278
270
|
convert_to_type data, return_type
|
@@ -284,6 +276,7 @@ module MoneyKit
|
|
284
276
|
# @return [Mixed] Data in a particular type
|
285
277
|
def convert_to_type(data, return_type)
|
286
278
|
return nil if data.nil?
|
279
|
+
|
287
280
|
case return_type
|
288
281
|
when 'String'
|
289
282
|
data.to_s
|
@@ -304,11 +297,11 @@ module MoneyKit
|
|
304
297
|
data
|
305
298
|
when /\AArray<(.+)>\z/
|
306
299
|
# e.g. Array<Pet>
|
307
|
-
sub_type =
|
300
|
+
sub_type = ::Regexp.last_match(1)
|
308
301
|
data.map { |item| convert_to_type(item, sub_type) }
|
309
|
-
when /\AHash
|
302
|
+
when /\AHash<String, (.+)>\z/
|
310
303
|
# e.g. Hash<String, Integer>
|
311
|
-
sub_type =
|
304
|
+
sub_type = ::Regexp.last_match(1)
|
312
305
|
{}.tap do |hash|
|
313
306
|
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
314
307
|
end
|
@@ -325,12 +318,12 @@ module MoneyKit
|
|
325
318
|
# @param [String] filename the filename to be sanitized
|
326
319
|
# @return [String] the sanitized filename
|
327
320
|
def sanitize_filename(filename)
|
328
|
-
filename.gsub(
|
321
|
+
filename.gsub(%r{.*[/\\]}, '')
|
329
322
|
end
|
330
323
|
|
331
324
|
def build_request_url(path, opts = {})
|
332
325
|
# Add leading and trailing slashes to path
|
333
|
-
path = "/#{path}".gsub(
|
326
|
+
path = "/#{path}".gsub(%r{/+}, '/')
|
334
327
|
@config.base_url(opts[:operation]) + path
|
335
328
|
end
|
336
329
|
|
@@ -343,10 +336,11 @@ module MoneyKit
|
|
343
336
|
Array(auth_names).each do |auth_name|
|
344
337
|
auth_setting = @config.auth_settings[auth_name]
|
345
338
|
next unless auth_setting
|
339
|
+
|
346
340
|
case auth_setting[:in]
|
347
341
|
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
348
342
|
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
349
|
-
else
|
343
|
+
else raise ArgumentError, 'Authentication token must be in `query` or `header`'
|
350
344
|
end
|
351
345
|
end
|
352
346
|
end
|
@@ -364,6 +358,7 @@ module MoneyKit
|
|
364
358
|
# @return [String] the Accept header (e.g. application/json)
|
365
359
|
def select_header_accept(accepts)
|
366
360
|
return nil if accepts.nil? || accepts.empty?
|
361
|
+
|
367
362
|
# use JSON when present, otherwise use all of the provided
|
368
363
|
json_accept = accepts.find { |s| json_mime?(s) }
|
369
364
|
json_accept || accepts.join(',')
|
@@ -375,6 +370,7 @@ module MoneyKit
|
|
375
370
|
def select_header_content_type(content_types)
|
376
371
|
# return nil by default
|
377
372
|
return if content_types.nil? || content_types.empty?
|
373
|
+
|
378
374
|
# use JSON when present, otherwise use the first one
|
379
375
|
json_content_type = content_types.find { |s| json_mime?(s) }
|
380
376
|
json_content_type || content_types.first
|
@@ -385,12 +381,13 @@ module MoneyKit
|
|
385
381
|
# @return [String] JSON string representation of the object
|
386
382
|
def object_to_http_body(model)
|
387
383
|
return model if model.nil? || model.is_a?(String)
|
384
|
+
|
388
385
|
local_body = nil
|
389
|
-
if model.is_a?(Array)
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
386
|
+
local_body = if model.is_a?(Array)
|
387
|
+
model.map { |m| object_to_hash(m) }
|
388
|
+
else
|
389
|
+
object_to_hash(model)
|
390
|
+
end
|
394
391
|
local_body.to_json
|
395
392
|
end
|
396
393
|
|
@@ -421,7 +418,7 @@ module MoneyKit
|
|
421
418
|
# return the array directly as typhoeus will handle it as expected
|
422
419
|
param
|
423
420
|
else
|
424
|
-
|
421
|
+
raise "unknown collection format: #{collection_format.inspect}"
|
425
422
|
end
|
426
423
|
end
|
427
424
|
end
|
data/lib/moneykit/api_error.rb
CHANGED
@@ -1,14 +1,12 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
=end
|
1
|
+
# #MoneyKit API
|
2
|
+
#
|
3
|
+
# No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
4
|
+
#
|
5
|
+
# The version of the OpenAPI document: 0.1.0
|
6
|
+
#
|
7
|
+
# Generated by: https://openapi-generator.tech
|
8
|
+
# OpenAPI Generator version: 7.1.0
|
9
|
+
#
|
12
10
|
|
13
11
|
module MoneyKit
|
14
12
|
class ApiError < StandardError
|
@@ -42,11 +40,11 @@ module MoneyKit
|
|
42
40
|
end
|
43
41
|
|
44
42
|
def message
|
45
|
-
if @message.nil?
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
43
|
+
msg = if @message.nil?
|
44
|
+
'Error message: the server returns an error'
|
45
|
+
else
|
46
|
+
@message
|
47
|
+
end
|
50
48
|
|
51
49
|
msg += "\nHTTP status code: #{code}" if code
|
52
50
|
msg += "\nResponse headers: #{response_headers}" if response_headers
|
@@ -1,14 +1,12 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
=end
|
1
|
+
# #MoneyKit API
|
2
|
+
#
|
3
|
+
# No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
|
4
|
+
#
|
5
|
+
# The version of the OpenAPI document: 0.1.0
|
6
|
+
#
|
7
|
+
# Generated by: https://openapi-generator.tech
|
8
|
+
# OpenAPI Generator version: 7.1.0
|
9
|
+
#
|
12
10
|
|
13
11
|
module MoneyKit
|
14
12
|
class Configuration
|
@@ -142,16 +140,13 @@ module MoneyKit
|
|
142
140
|
# https://github.com/lostisland/faraday/tree/main/lib/faraday/encoders
|
143
141
|
attr_accessor :params_encoder
|
144
142
|
|
145
|
-
|
146
|
-
attr_accessor :inject_format
|
147
|
-
|
148
|
-
attr_accessor :force_ending_format
|
143
|
+
attr_accessor :inject_format, :force_ending_format
|
149
144
|
|
150
145
|
def initialize
|
151
146
|
@scheme = 'https'
|
152
|
-
@host = '
|
147
|
+
@host = 'api.moneykit.com'
|
153
148
|
@base_path = ''
|
154
|
-
@server_index =
|
149
|
+
@server_index = nil
|
155
150
|
@server_operation_index = {}
|
156
151
|
@server_variables = {}
|
157
152
|
@server_operation_variables = {}
|
@@ -188,26 +183,34 @@ module MoneyKit
|
|
188
183
|
|
189
184
|
def scheme=(scheme)
|
190
185
|
# remove :// from scheme
|
191
|
-
@scheme = scheme.sub(
|
186
|
+
@scheme = scheme.sub(%r{://}, '')
|
192
187
|
end
|
193
188
|
|
194
189
|
def host=(host)
|
195
190
|
# remove http(s):// and anything after a slash
|
196
|
-
@host = host.sub(
|
191
|
+
@host = host.sub(%r{https?://}, '').split('/').first
|
197
192
|
end
|
198
193
|
|
199
194
|
def base_path=(base_path)
|
200
195
|
# Add leading and trailing slashes to base_path
|
201
|
-
@base_path = "/#{base_path}".gsub(
|
196
|
+
@base_path = "/#{base_path}".gsub(%r{/+}, '/')
|
202
197
|
@base_path = '' if @base_path == '/'
|
203
198
|
end
|
204
199
|
|
205
200
|
# Returns base URL for specified operation based on server settings
|
206
201
|
def base_url(operation = nil)
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
202
|
+
if operation_server_settings.key?(operation)
|
203
|
+
index = server_operation_index.fetch(operation, server_index)
|
204
|
+
server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables),
|
205
|
+
operation_server_settings[operation])
|
206
|
+
elsif server_index.nil?
|
207
|
+
"#{scheme}://#{[host, base_path].join('/').gsub(%r{/+}, '/')}".sub(%r{/+\z},
|
208
|
+
'')
|
209
|
+
else
|
210
|
+
server_url(
|
211
|
+
server_index, server_variables, nil
|
212
|
+
)
|
213
|
+
end
|
211
214
|
end
|
212
215
|
|
213
216
|
# Gets API key (with prefix if set).
|
@@ -224,8 +227,9 @@ module MoneyKit
|
|
224
227
|
|
225
228
|
# Gets access_token using access_token_getter or uses the static access_token
|
226
229
|
def access_token_with_refresh
|
227
|
-
|
228
|
-
|
230
|
+
return access_token if access_token_getter.nil?
|
231
|
+
|
232
|
+
access_token_getter.call
|
229
233
|
end
|
230
234
|
|
231
235
|
# Gets Basic Auth token string
|
@@ -243,27 +247,13 @@ module MoneyKit
|
|
243
247
|
key: 'Authorization',
|
244
248
|
value: "Bearer #{access_token_with_refresh}"
|
245
249
|
},
|
246
|
-
'clientId' =>
|
247
|
-
{
|
248
|
-
type: 'api_key',
|
249
|
-
in: 'header',
|
250
|
-
key: 'Client-Id',
|
251
|
-
value: api_key_with_prefix('clientId')
|
252
|
-
},
|
253
|
-
'clientSecret' =>
|
254
|
-
{
|
255
|
-
type: 'api_key',
|
256
|
-
in: 'header',
|
257
|
-
key: 'Client-Secret',
|
258
|
-
value: api_key_with_prefix('clientSecret')
|
259
|
-
},
|
260
250
|
'HTTPBasic' =>
|
261
251
|
{
|
262
252
|
type: 'basic',
|
263
253
|
in: 'header',
|
264
254
|
key: 'Authorization',
|
265
255
|
value: basic_auth_token
|
266
|
-
}
|
256
|
+
}
|
267
257
|
}
|
268
258
|
end
|
269
259
|
|
@@ -271,19 +261,14 @@ module MoneyKit
|
|
271
261
|
def server_settings
|
272
262
|
[
|
273
263
|
{
|
274
|
-
url:
|
275
|
-
description:
|
276
|
-
},
|
277
|
-
{
|
278
|
-
url: "https://sandbox.moneykit.com",
|
279
|
-
description: "MoneyKit sandbox environment (Unrestricted environment with fake institution data)",
|
264
|
+
url: 'https://api.moneykit.com',
|
265
|
+
description: 'No description provided'
|
280
266
|
}
|
281
267
|
]
|
282
268
|
end
|
283
269
|
|
284
270
|
def operation_server_settings
|
285
|
-
{
|
286
|
-
}
|
271
|
+
{}
|
287
272
|
end
|
288
273
|
|
289
274
|
# Returns URL based on server settings
|
@@ -291,11 +276,12 @@ module MoneyKit
|
|
291
276
|
# @param index array index of the server settings
|
292
277
|
# @param variables hash of variable and the corresponding value
|
293
278
|
def server_url(index, variables = {}, servers = nil)
|
294
|
-
servers = server_settings if servers
|
279
|
+
servers = server_settings if servers.nil?
|
295
280
|
|
296
281
|
# check array index out of bound
|
297
|
-
if
|
298
|
-
|
282
|
+
if index.nil? || index < 0 || index >= servers.size
|
283
|
+
raise ArgumentError,
|
284
|
+
"Invalid index #{index} when selecting the server. Must not be nil and must be less than #{servers.size}"
|
299
285
|
end
|
300
286
|
|
301
287
|
server = servers[index]
|
@@ -304,16 +290,17 @@ module MoneyKit
|
|
304
290
|
return url unless server.key? :variables
|
305
291
|
|
306
292
|
# go through variable and assign a value
|
307
|
-
server[:variables].each do |name,
|
293
|
+
server[:variables].each do |name, _variable|
|
308
294
|
if variables.key?(name)
|
309
|
-
if
|
310
|
-
url.gsub!
|
295
|
+
if !server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name])
|
296
|
+
url.gsub! '{' + name.to_s + '}', variables[name]
|
311
297
|
else
|
312
|
-
|
298
|
+
raise ArgumentError,
|
299
|
+
"The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
|
313
300
|
end
|
314
301
|
else
|
315
302
|
# use default value
|
316
|
-
url.gsub!
|
303
|
+
url.gsub! '{' + name.to_s + '}', server[:variables][name][:default_value]
|
317
304
|
end
|
318
305
|
end
|
319
306
|
|
@@ -373,9 +360,9 @@ module MoneyKit
|
|
373
360
|
#
|
374
361
|
# @see https://github.com/lostisland/faraday/blob/v2.3.0/lib/faraday/rack_builder.rb#L92-L143
|
375
362
|
def set_faraday_middleware(operation, key, *args, &block)
|
376
|
-
unless [
|
377
|
-
|
378
|
-
|
363
|
+
unless %i[request response use insert insert_before insert_after swap delete].include?(operation)
|
364
|
+
raise ArgumentError, "Invalid faraday middleware operation #{operation}. Must be" \
|
365
|
+
' :request, :response, :use, :insert, :insert_before, :insert_after, :swap or :delete.'
|
379
366
|
end
|
380
367
|
|
381
368
|
@middlewares[operation] << [key, args, block]
|
@@ -386,7 +373,7 @@ module MoneyKit
|
|
386
373
|
def configure_middleware(connection)
|
387
374
|
return if @middlewares.empty?
|
388
375
|
|
389
|
-
[
|
376
|
+
%i[request response use insert insert_before insert_after swap].each do |operation|
|
390
377
|
next unless @middlewares.key?(operation)
|
391
378
|
|
392
379
|
@middlewares[operation].each do |key, args, block|
|
@@ -394,10 +381,10 @@ module MoneyKit
|
|
394
381
|
end
|
395
382
|
end
|
396
383
|
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
384
|
+
return unless @middlewares.key?(:delete)
|
385
|
+
|
386
|
+
@middlewares[:delete].each do |key, _args, _block|
|
387
|
+
connection.builder.delete(key)
|
401
388
|
end
|
402
389
|
end
|
403
390
|
end
|