moneykit 0.0.2 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,14 +1,12 @@
|
|
1
|
-
|
2
|
-
#
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
=end
|
1
|
+
# #Plaid Compatibility Layer
|
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: 5.1.1
|
9
|
+
#
|
12
10
|
|
13
11
|
require 'date'
|
14
12
|
require 'json'
|
@@ -17,383 +15,384 @@ require 'tempfile'
|
|
17
15
|
require 'faraday'
|
18
16
|
require 'faraday/multipart'
|
19
17
|
|
20
|
-
module MoneyKit
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
def create_connection
|
46
|
-
@connection = Faraday.new(url: config.base_url) do |builder|
|
47
|
-
block_given? ? yield(builder) : builder.adapter(Faraday.default_adapter)
|
18
|
+
module MoneyKit
|
19
|
+
module PlaidCompatible
|
20
|
+
class ApiClient
|
21
|
+
# The Configuration object holding settings to be used in the API client.
|
22
|
+
attr_accessor :config
|
23
|
+
|
24
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
25
|
+
#
|
26
|
+
# @return [Hash]
|
27
|
+
attr_accessor :default_headers
|
28
|
+
|
29
|
+
# The Faraday::Connection object for fine tuning configuration options.
|
30
|
+
attr_reader :connection
|
31
|
+
|
32
|
+
# Initializes the ApiClient
|
33
|
+
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
34
|
+
def initialize(config = Configuration.default)
|
35
|
+
@config = config
|
36
|
+
@user_agent = 'Plaid Ruby v1.0.0'
|
37
|
+
@default_headers = {
|
38
|
+
'Content-Type' => 'application/json',
|
39
|
+
'User-Agent' => @user_agent
|
40
|
+
}
|
41
|
+
@connection = create_connection
|
48
42
|
end
|
49
|
-
end
|
50
43
|
|
51
|
-
|
52
|
-
|
53
|
-
|
44
|
+
def create_connection
|
45
|
+
@connection = Faraday.new(url: config.base_url) do |builder|
|
46
|
+
block_given? ? yield(builder) : builder.adapter(Faraday.default_adapter)
|
47
|
+
end
|
48
|
+
end
|
54
49
|
|
55
|
-
|
56
|
-
|
57
|
-
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
|
58
|
-
# the data deserialized from response body (could be nil), response status code and response headers.
|
59
|
-
def call_api(http_method, path, opts = {})
|
60
|
-
if opts[:header_params]["Content-Type"] == "multipart/form-data"
|
61
|
-
connection.request :multipart
|
62
|
-
connection.request :url_encoded
|
50
|
+
def self.default
|
51
|
+
@@default ||= ApiClient.new
|
63
52
|
end
|
64
53
|
|
65
|
-
|
66
|
-
|
67
|
-
|
54
|
+
# Call an API with given options.
|
55
|
+
#
|
56
|
+
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
|
57
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
58
|
+
def call_api(http_method, path, opts = {})
|
59
|
+
if opts[:header_params]['Content-Type'] == 'multipart/form-data'
|
60
|
+
connection.request :multipart
|
61
|
+
connection.request :url_encoded
|
68
62
|
end
|
69
63
|
|
70
|
-
|
71
|
-
|
72
|
-
|
64
|
+
begin
|
65
|
+
response = connection.public_send(http_method.to_sym.downcase) do |req|
|
66
|
+
build_request(http_method, path, req, opts)
|
67
|
+
end
|
73
68
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
69
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n" if @config.debugging
|
70
|
+
|
71
|
+
unless response.success?
|
72
|
+
if response.status == 0
|
73
|
+
# Errors from libcurl will be made visible here
|
74
|
+
raise ApiError.new(code: 0,
|
75
|
+
message: response.return_message)
|
76
|
+
else
|
77
|
+
raw_body = response.body
|
78
|
+
# Gracefully handle malformed body which is possible during API outage/maintanance
|
79
|
+
parsed_body = begin
|
80
|
+
JSON.parse(raw_body)
|
81
|
+
rescue JSON::ParserError
|
82
|
+
nil
|
83
|
+
end
|
84
|
+
raise ApiError.new(code: response.status,
|
85
|
+
response_headers: response.headers,
|
86
|
+
response_body: raw_body,
|
87
|
+
data: parsed_body),
|
88
|
+
response.reason_phrase
|
89
|
+
end
|
92
90
|
end
|
91
|
+
rescue Faraday::TimeoutError
|
92
|
+
raise ApiError, 'Connection timed out'
|
93
93
|
end
|
94
|
-
rescue Faraday::TimeoutError
|
95
|
-
fail ApiError.new('Connection timed out')
|
96
|
-
end
|
97
94
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
95
|
+
if opts[:return_type]
|
96
|
+
prepare_file(response) if opts[:return_type] == 'File'
|
97
|
+
data = deserialize(response, opts[:return_type])
|
98
|
+
else
|
99
|
+
data = nil
|
100
|
+
end
|
101
|
+
[data, response.status, response.headers]
|
103
102
|
end
|
104
|
-
return data, response.status, response.headers
|
105
|
-
end
|
106
103
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
104
|
+
# Builds the HTTP request
|
105
|
+
#
|
106
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
107
|
+
# @param [String] path URL path (e.g. /account/new)
|
108
|
+
# @option opts [Hash] :header_params Header parameters
|
109
|
+
# @option opts [Hash] :query_params Query parameters
|
110
|
+
# @option opts [Hash] :form_params Query parameters
|
111
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
112
|
+
# @return [Typhoeus::Request] A Typhoeus Request
|
113
|
+
def build_request(http_method, path, request, opts = {})
|
114
|
+
url = build_request_url(path)
|
115
|
+
http_method = http_method.to_sym.downcase
|
116
|
+
|
117
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
118
|
+
query_params = opts[:query_params] || {}
|
119
|
+
form_params = opts[:form_params] || {}
|
120
|
+
|
121
|
+
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
122
|
+
|
123
|
+
req_opts = {
|
124
|
+
method: http_method,
|
125
|
+
headers: header_params,
|
126
|
+
params: query_params,
|
127
|
+
params_encoding: @config.params_encoding,
|
128
|
+
timeout: @config.timeout,
|
129
|
+
verbose: @config.debugging
|
130
|
+
}
|
131
|
+
|
132
|
+
if %i[post patch put delete].include?(http_method)
|
133
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
134
|
+
req_opts.update body: req_body
|
135
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n" if @config.debugging
|
140
136
|
end
|
137
|
+
request.headers = header_params
|
138
|
+
request.body = req_body
|
139
|
+
request.url url
|
140
|
+
request.params = query_params
|
141
|
+
request
|
141
142
|
end
|
142
|
-
request.headers = header_params
|
143
|
-
request.body = req_body
|
144
|
-
request.url url
|
145
|
-
request.params = query_params
|
146
|
-
request
|
147
|
-
end
|
148
143
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
144
|
+
# Builds the HTTP request body
|
145
|
+
#
|
146
|
+
# @param [Hash] header_params Header parameters
|
147
|
+
# @param [Hash] form_params Query parameters
|
148
|
+
# @param [Object] body HTTP body (JSON/XML)
|
149
|
+
# @return [String] HTTP body data in the form of string
|
150
|
+
def build_request_body(header_params, form_params, body)
|
151
|
+
# http form
|
152
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
|
153
|
+
data = URI.encode_www_form(form_params)
|
154
|
+
elsif header_params['Content-Type'] == 'multipart/form-data'
|
155
|
+
data = {}
|
156
|
+
form_params.each do |key, value|
|
157
|
+
data[key] = case value
|
158
|
+
when ::File, ::Tempfile
|
159
|
+
# TODO: hardcode to application/octet-stream, need better way to detect content type
|
160
|
+
Faraday::Multipart::Post::UploadIO.new(value.path, 'application/octet-stream', value.path)
|
161
|
+
when ::Array, nil
|
162
|
+
# let Faraday handle Array and nil parameters
|
163
|
+
value
|
164
|
+
else
|
165
|
+
value.to_s
|
166
|
+
end
|
171
167
|
end
|
168
|
+
elsif body
|
169
|
+
data = body.is_a?(String) ? body : body.to_json
|
170
|
+
else
|
171
|
+
data = nil
|
172
172
|
end
|
173
|
-
|
174
|
-
data = body.is_a?(String) ? body : body.to_json
|
175
|
-
else
|
176
|
-
data = nil
|
173
|
+
data
|
177
174
|
end
|
178
|
-
data
|
179
|
-
end
|
180
175
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
176
|
+
# Check if the given MIME is a JSON MIME.
|
177
|
+
# JSON MIME examples:
|
178
|
+
# application/json
|
179
|
+
# application/json; charset=UTF8
|
180
|
+
# APPLICATION/JSON
|
181
|
+
# */*
|
182
|
+
# @param [String] mime MIME
|
183
|
+
# @return [Boolean] True if the MIME is application/json
|
184
|
+
def json_mime?(mime)
|
185
|
+
(mime == '*/*') || !(mime =~ %r{Application/.*json(?!p)(;.*)?}i).nil?
|
186
|
+
end
|
187
|
+
|
188
|
+
# Deserialize the response to the given return type.
|
189
|
+
#
|
190
|
+
# @param [Response] response HTTP response
|
191
|
+
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
192
|
+
def deserialize(response, return_type)
|
193
|
+
body = response.body
|
192
194
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
197
|
-
def deserialize(response, return_type)
|
198
|
-
body = response.body
|
195
|
+
# handle file downloading - return the File instance processed in request callbacks
|
196
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
197
|
+
return @tempfile if return_type == 'File'
|
199
198
|
|
200
|
-
|
201
|
-
# note that response body is empty when the file is written in chunks in request on_body callback
|
202
|
-
return @tempfile if return_type == 'File'
|
199
|
+
return nil if body.nil? || body.empty?
|
203
200
|
|
204
|
-
|
201
|
+
# return response body directly for String return type
|
202
|
+
return body if return_type == 'String'
|
205
203
|
|
206
|
-
|
207
|
-
|
204
|
+
# ensuring a default content type
|
205
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
208
206
|
|
209
|
-
|
210
|
-
content_type = response.headers['Content-Type'] || 'application/json'
|
207
|
+
raise "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
211
208
|
|
212
|
-
|
209
|
+
begin
|
210
|
+
data = JSON.parse("[#{body}]", symbolize_names: true)[0]
|
211
|
+
rescue JSON::ParserError => e
|
212
|
+
raise e unless %w[String Date DateTime].include?(return_type)
|
213
213
|
|
214
|
-
begin
|
215
|
-
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
216
|
-
rescue JSON::ParserError => e
|
217
|
-
if %w(String Date DateTime).include?(return_type)
|
218
214
|
data = body
|
219
|
-
else
|
220
|
-
raise e
|
221
215
|
end
|
222
|
-
end
|
223
216
|
|
224
|
-
|
225
|
-
|
217
|
+
convert_to_type data, return_type
|
218
|
+
end
|
226
219
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
220
|
+
# Convert data to the given return type.
|
221
|
+
# @param [Object] data Data to be converted
|
222
|
+
# @param [String] return_type Return type
|
223
|
+
# @return [Mixed] Data in a particular type
|
224
|
+
def convert_to_type(data, return_type)
|
225
|
+
return nil if data.nil?
|
226
|
+
|
227
|
+
case return_type
|
228
|
+
when 'String'
|
229
|
+
data.to_s
|
230
|
+
when 'Integer'
|
231
|
+
data.to_i
|
232
|
+
when 'Float'
|
233
|
+
data.to_f
|
234
|
+
when 'Boolean'
|
235
|
+
data == true
|
236
|
+
when 'DateTime'
|
237
|
+
# parse date time (expecting ISO 8601 format)
|
238
|
+
DateTime.parse data
|
239
|
+
when 'Date'
|
240
|
+
# parse date time (expecting ISO 8601 format)
|
241
|
+
Date.parse data
|
242
|
+
when 'Object'
|
243
|
+
# generic object (usually a Hash), return directly
|
244
|
+
data
|
245
|
+
when /\AArray<(.+)>\z/
|
246
|
+
# e.g. Array<Pet>
|
247
|
+
sub_type = ::Regexp.last_match(1)
|
248
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
249
|
+
when /\AHash<String, (.+)>\z/
|
250
|
+
# e.g. Hash<String, Integer>
|
251
|
+
sub_type = ::Regexp.last_match(1)
|
252
|
+
{}.tap do |hash|
|
253
|
+
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
254
|
+
end
|
255
|
+
else
|
256
|
+
# models, e.g. Pet
|
257
|
+
MoneyKit::PlaidCompatible.const_get(return_type).build_from_hash(data)
|
260
258
|
end
|
261
|
-
else
|
262
|
-
# models, e.g. Pet
|
263
|
-
MoneyKit::PlaidCompatible.const_get(return_type).build_from_hash(data)
|
264
259
|
end
|
265
|
-
end
|
266
260
|
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
261
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
262
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
263
|
+
# The response body is written to the file in chunks in order to handle files which
|
264
|
+
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
265
|
+
# process can use.
|
266
|
+
#
|
267
|
+
# @see Configuration#temp_folder_path
|
268
|
+
def prepare_file(response)
|
269
|
+
content_disposition = response.headers['Content-Disposition']
|
270
|
+
if content_disposition && content_disposition =~ /filename=/i
|
271
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
272
|
+
prefix = sanitize_filename(filename)
|
273
|
+
else
|
274
|
+
prefix = 'download-'
|
275
|
+
end
|
276
|
+
prefix += '-' unless prefix.end_with?('-')
|
277
|
+
encoding = response.body.encoding
|
278
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
279
|
+
@tempfile = tempfile
|
280
|
+
tempfile.write(response.body)
|
281
|
+
tempfile.close if tempfile
|
282
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder " \
|
283
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file " \
|
284
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file " \
|
285
|
+
'explicitly with `tempfile.delete`'
|
281
286
|
end
|
282
|
-
prefix = prefix + "-" unless prefix.end_with?("-")
|
283
|
-
encoding = response.body.encoding
|
284
|
-
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
285
|
-
@tempfile = tempfile
|
286
|
-
tempfile.write(response.body)
|
287
|
-
tempfile.close if tempfile
|
288
|
-
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder " \
|
289
|
-
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file " \
|
290
|
-
"will be deleted automatically with GC. It's also recommended to delete the temp file " \
|
291
|
-
"explicitly with `tempfile.delete`"
|
292
|
-
end
|
293
287
|
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
288
|
+
# Sanitize filename by removing path.
|
289
|
+
# e.g. ../../sun.gif becomes sun.gif
|
290
|
+
#
|
291
|
+
# @param [String] filename the filename to be sanitized
|
292
|
+
# @return [String] the sanitized filename
|
293
|
+
def sanitize_filename(filename)
|
294
|
+
filename.gsub(%r{.*[/\\]}, '')
|
295
|
+
end
|
302
296
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
297
|
+
def build_request_url(path)
|
298
|
+
# Add leading and trailing slashes to path
|
299
|
+
path = "/#{path}".gsub(%r{/+}, '/')
|
300
|
+
@config.base_url + path
|
301
|
+
end
|
308
302
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
303
|
+
# Update hearder and query params based on authentication settings.
|
304
|
+
#
|
305
|
+
# @param [Hash] header_params Header parameters
|
306
|
+
# @param [Hash] query_params Query parameters
|
307
|
+
# @param [String] auth_names Authentication scheme name
|
308
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
309
|
+
Array(auth_names).each do |auth_name|
|
310
|
+
auth_setting = @config.auth_settings[auth_name]
|
311
|
+
next unless auth_setting
|
312
|
+
|
313
|
+
case auth_setting[:in]
|
314
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
315
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
316
|
+
else raise ArgumentError, 'Authentication token must be in `query` of `header`'
|
317
|
+
end
|
322
318
|
end
|
323
319
|
end
|
324
|
-
end
|
325
320
|
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
321
|
+
# Sets user agent in HTTP header
|
322
|
+
#
|
323
|
+
# @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
|
324
|
+
def user_agent=(user_agent)
|
325
|
+
@user_agent = user_agent
|
326
|
+
@default_headers['User-Agent'] = @user_agent
|
327
|
+
end
|
333
328
|
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
# use JSON when present, otherwise use all of the provided
|
340
|
-
json_accept = accepts.find { |s| json_mime?(s) }
|
341
|
-
json_accept || accepts.join(',')
|
342
|
-
end
|
329
|
+
# Return Accept header based on an array of accepts provided.
|
330
|
+
# @param [Array] accepts array for Accept
|
331
|
+
# @return [String] the Accept header (e.g. application/json)
|
332
|
+
def select_header_accept(accepts)
|
333
|
+
return nil if accepts.nil? || accepts.empty?
|
343
334
|
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
# use application/json by default
|
349
|
-
return 'application/json' if content_types.nil? || content_types.empty?
|
350
|
-
# use JSON when present, otherwise use the first one
|
351
|
-
json_content_type = content_types.find { |s| json_mime?(s) }
|
352
|
-
json_content_type || content_types.first
|
353
|
-
end
|
335
|
+
# use JSON when present, otherwise use all of the provided
|
336
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
337
|
+
json_accept || accepts.join(',')
|
338
|
+
end
|
354
339
|
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
340
|
+
# Return Content-Type header based on an array of content types provided.
|
341
|
+
# @param [Array] content_types array for Content-Type
|
342
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
343
|
+
def select_header_content_type(content_types)
|
344
|
+
# use application/json by default
|
345
|
+
return 'application/json' if content_types.nil? || content_types.empty?
|
346
|
+
|
347
|
+
# use JSON when present, otherwise use the first one
|
348
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
349
|
+
json_content_type || content_types.first
|
365
350
|
end
|
366
|
-
local_body.to_json
|
367
|
-
end
|
368
351
|
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
352
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
353
|
+
# @param [Object] model object to be converted into JSON string
|
354
|
+
# @return [String] JSON string representation of the object
|
355
|
+
def object_to_http_body(model)
|
356
|
+
return model if model.nil? || model.is_a?(String)
|
357
|
+
|
358
|
+
local_body = nil
|
359
|
+
local_body = if model.is_a?(Array)
|
360
|
+
model.map { |m| object_to_hash(m) }
|
361
|
+
else
|
362
|
+
object_to_hash(model)
|
363
|
+
end
|
364
|
+
local_body.to_json
|
377
365
|
end
|
378
|
-
end
|
379
366
|
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
367
|
+
# Convert object(non-array) to hash.
|
368
|
+
# @param [Object] obj object to be converted into JSON string
|
369
|
+
# @return [String] JSON string representation of the object
|
370
|
+
def object_to_hash(obj)
|
371
|
+
if obj.respond_to?(:to_hash)
|
372
|
+
obj.to_hash
|
373
|
+
else
|
374
|
+
obj
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
# Build parameter value according to the given collection format.
|
379
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
380
|
+
def build_collection_param(param, collection_format)
|
381
|
+
case collection_format
|
382
|
+
when :csv
|
383
|
+
param.join(',')
|
384
|
+
when :ssv
|
385
|
+
param.join(' ')
|
386
|
+
when :tsv
|
387
|
+
param.join("\t")
|
388
|
+
when :pipes
|
389
|
+
param.join('|')
|
390
|
+
when :multi
|
391
|
+
# return the array directly as typhoeus will handle it as expected
|
392
|
+
param
|
393
|
+
else
|
394
|
+
raise "unknown collection format: #{collection_format.inspect}"
|
395
|
+
end
|
397
396
|
end
|
398
397
|
end
|
399
398
|
end
|