ynab 1.29.0 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/DEVELOPMENT.md +11 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +42 -0
- data/README.md +6 -6
- data/Rakefile +58 -0
- data/config.json +9 -0
- data/docs/Account.md +25 -0
- data/docs/AccountResponse.md +8 -0
- data/docs/AccountResponseData.md +8 -0
- data/docs/AccountType.md +7 -0
- data/docs/AccountWrapper.md +8 -0
- data/docs/AccountsApi.md +70 -0
- data/docs/AccountsResponse.md +8 -0
- data/docs/AccountsResponseData.md +9 -0
- data/docs/AccountsWrapper.md +9 -0
- data/docs/BudgetDetail.md +24 -0
- data/docs/BudgetDetailAllOf.md +17 -0
- data/docs/BudgetDetailResponse.md +8 -0
- data/docs/BudgetDetailResponseData.md +9 -0
- data/docs/BudgetDetailWrapper.md +9 -0
- data/docs/BudgetSettings.md +9 -0
- data/docs/BudgetSettingsResponse.md +8 -0
- data/docs/BudgetSettingsResponseData.md +8 -0
- data/docs/BudgetSettingsWrapper.md +8 -0
- data/docs/BudgetSummary.md +15 -0
- data/docs/BudgetSummaryResponse.md +8 -0
- data/docs/BudgetSummaryResponseData.md +9 -0
- data/docs/BudgetSummaryWrapper.md +9 -0
- data/docs/BudgetsApi.md +68 -0
- data/docs/BulkIdWrapper.md +8 -0
- data/docs/BulkIds.md +9 -0
- data/docs/BulkResponse.md +8 -0
- data/docs/BulkResponseData.md +8 -0
- data/docs/BulkResponseDataBulk.md +9 -0
- data/docs/BulkTransactionCreateResponse.md +8 -0
- data/docs/BulkTransactionIds.md +8 -0
- data/docs/BulkTransactions.md +8 -0
- data/docs/CategoriesApi.md +94 -0
- data/docs/CategoriesResponse.md +8 -0
- data/docs/CategoriesResponseData.md +9 -0
- data/docs/Category.md +30 -0
- data/docs/CategoryGroup.md +11 -0
- data/docs/CategoryGroupWithCategories.md +12 -0
- data/docs/CategoryGroupWithCategoriesAllOf.md +8 -0
- data/docs/CategoryGroupsWrapper.md +9 -0
- data/docs/CategoryResponse.md +8 -0
- data/docs/CategoryResponseData.md +8 -0
- data/docs/CategoryWrapper.md +9 -0
- data/docs/CurrencyFormat.md +15 -0
- data/docs/DateFormat.md +8 -0
- data/docs/DeprecatedApi.md +28 -0
- data/docs/ErrorDetail.md +10 -0
- data/docs/ErrorResponse.md +8 -0
- data/docs/HybridTransaction.md +30 -0
- data/docs/HybridTransactionAllOf.md +12 -0
- data/docs/HybridTransactionsResponse.md +8 -0
- data/docs/HybridTransactionsResponseData.md +9 -0
- data/docs/HybridTransactionsWrapper.md +8 -0
- data/docs/LoanAccountPeriodicValue.md +7 -0
- data/docs/MonthDetail.md +16 -0
- data/docs/MonthDetailAllOf.md +8 -0
- data/docs/MonthDetailResponse.md +8 -0
- data/docs/MonthDetailResponseData.md +8 -0
- data/docs/MonthDetailWrapper.md +8 -0
- data/docs/MonthSummariesResponse.md +8 -0
- data/docs/MonthSummariesResponseData.md +9 -0
- data/docs/MonthSummariesWrapper.md +9 -0
- data/docs/MonthSummary.md +15 -0
- data/docs/MonthsApi.md +49 -0
- data/docs/PatchMonthCategoryWrapper.md +8 -0
- data/docs/PatchTransactionsWrapper.md +8 -0
- data/docs/Payee.md +11 -0
- data/docs/PayeeLocation.md +12 -0
- data/docs/PayeeLocationResponse.md +8 -0
- data/docs/PayeeLocationResponseData.md +8 -0
- data/docs/PayeeLocationWrapper.md +8 -0
- data/docs/PayeeLocationsApi.md +69 -0
- data/docs/PayeeLocationsResponse.md +8 -0
- data/docs/PayeeLocationsResponseData.md +8 -0
- data/docs/PayeeLocationsWrapper.md +8 -0
- data/docs/PayeeResponse.md +8 -0
- data/docs/PayeeResponseData.md +8 -0
- data/docs/PayeeWrapper.md +8 -0
- data/docs/PayeesApi.md +49 -0
- data/docs/PayeesResponse.md +8 -0
- data/docs/PayeesResponseData.md +9 -0
- data/docs/PayeesWrapper.md +9 -0
- data/docs/PostAccountWrapper.md +8 -0
- data/docs/PostTransactionsWrapper.md +9 -0
- data/docs/PutTransactionWrapper.md +8 -0
- data/docs/SaveAccount.md +10 -0
- data/docs/SaveAccountWrapper.md +8 -0
- data/docs/SaveCategoryResponse.md +8 -0
- data/docs/SaveCategoryResponseData.md +9 -0
- data/docs/SaveMonthCategory.md +8 -0
- data/docs/SaveMonthCategoryWrapper.md +8 -0
- data/docs/SaveSubTransaction.md +12 -0
- data/docs/SaveTransaction.md +19 -0
- data/docs/SaveTransactionWithId.md +20 -0
- data/docs/SaveTransactionWithIdAllOf.md +8 -0
- data/docs/SaveTransactionWithOptionalFields.md +19 -0
- data/docs/SaveTransactionWrapper.md +8 -0
- data/docs/SaveTransactionsResponse.md +8 -0
- data/docs/SaveTransactionsResponseData.md +12 -0
- data/docs/SaveTransactionsWrapper.md +9 -0
- data/docs/ScheduledSubTransaction.md +15 -0
- data/docs/ScheduledTransactionDetail.md +23 -0
- data/docs/ScheduledTransactionDetailAllOf.md +11 -0
- data/docs/ScheduledTransactionResponse.md +8 -0
- data/docs/ScheduledTransactionResponseData.md +8 -0
- data/docs/ScheduledTransactionSummary.md +19 -0
- data/docs/ScheduledTransactionWrapper.md +8 -0
- data/docs/ScheduledTransactionsApi.md +49 -0
- data/docs/ScheduledTransactionsResponse.md +8 -0
- data/docs/ScheduledTransactionsResponseData.md +9 -0
- data/docs/ScheduledTransactionsWrapper.md +8 -0
- data/docs/SubTransaction.md +18 -0
- data/docs/TransactionDetail.md +29 -0
- data/docs/TransactionDetailAllOf.md +11 -0
- data/docs/TransactionResponse.md +8 -0
- data/docs/TransactionResponseData.md +8 -0
- data/docs/TransactionSummary.md +25 -0
- data/docs/TransactionWrapper.md +8 -0
- data/docs/TransactionsApi.md +228 -0
- data/docs/TransactionsImportResponse.md +8 -0
- data/docs/TransactionsImportResponseData.md +8 -0
- data/docs/TransactionsResponse.md +8 -0
- data/docs/TransactionsResponseData.md +9 -0
- data/docs/TransactionsWrapper.md +9 -0
- data/docs/UpdateTransaction.md +20 -0
- data/docs/UpdateTransactionsWrapper.md +8 -0
- data/docs/User.md +8 -0
- data/docs/UserApi.md +25 -0
- data/docs/UserResponse.md +8 -0
- data/docs/UserResponseData.md +8 -0
- data/docs/UserWrapper.md +8 -0
- data/examples/budget-list.rb +21 -0
- data/examples/budget-month.rb +33 -0
- data/examples/category-balance.rb +23 -0
- data/examples/create-multiple-transactions.rb +42 -0
- data/examples/create-transaction.rb +30 -0
- data/examples/update-category-budgeted.rb +25 -0
- data/examples/update-multiple-transactions.rb +20 -0
- data/lib/ynab/api/accounts_api.rb +79 -42
- data/lib/ynab/api/budgets_api.rb +69 -37
- data/lib/ynab/api/categories_api.rb +109 -61
- data/lib/ynab/api/deprecated_api.rb +33 -18
- data/lib/ynab/api/months_api.rb +50 -29
- data/lib/ynab/api/payee_locations_api.rb +74 -42
- data/lib/ynab/api/payees_api.rb +50 -29
- data/lib/ynab/api/scheduled_transactions_api.rb +50 -29
- data/lib/ynab/api/transactions_api.rb +269 -141
- data/lib/ynab/api/user_api.rb +23 -13
- data/lib/ynab/api_client.rb +98 -96
- data/lib/ynab/configuration.rb +103 -16
- data/lib/ynab/models/account.rb +118 -56
- data/lib/ynab/models/account_response.rb +54 -19
- data/lib/ynab/models/account_response_data.rb +54 -19
- data/lib/ynab/models/account_type.rb +31 -21
- data/lib/ynab/models/accounts_response.rb +54 -19
- data/lib/ynab/models/accounts_response_data.rb +55 -20
- data/lib/ynab/models/budget_detail.rb +81 -36
- data/lib/ynab/models/budget_detail_all_of.rb +320 -0
- data/lib/ynab/models/budget_detail_response.rb +54 -19
- data/lib/ynab/models/budget_detail_response_data.rb +55 -20
- data/lib/ynab/models/budget_settings.rb +57 -30
- data/lib/ynab/models/budget_settings_response.rb +54 -19
- data/lib/ynab/models/budget_settings_response_data.rb +54 -19
- data/lib/ynab/models/budget_summary.rb +64 -27
- data/lib/ynab/models/budget_summary_response.rb +54 -19
- data/lib/ynab/models/budget_summary_response_data.rb +55 -21
- data/lib/ynab/models/bulk_response.rb +54 -19
- data/lib/ynab/models/bulk_response_data.rb +54 -19
- data/lib/ynab/models/bulk_response_data_bulk.rb +55 -20
- data/lib/ynab/models/bulk_transactions.rb +54 -19
- data/lib/ynab/models/categories_response.rb +54 -19
- data/lib/ynab/models/categories_response_data.rb +55 -20
- data/lib/ynab/models/category.rb +111 -49
- data/lib/ynab/models/category_group.rb +59 -24
- data/lib/ynab/models/category_group_with_categories.rb +68 -25
- data/lib/ynab/models/{save_month_category_wrapper.rb → category_group_with_categories_all_of.rb} +67 -29
- data/lib/ynab/models/category_response.rb +54 -19
- data/lib/ynab/models/category_response_data.rb +54 -19
- data/lib/ynab/models/currency_format.rb +63 -28
- data/lib/ynab/models/date_format.rb +54 -19
- data/lib/ynab/models/error_detail.rb +56 -21
- data/lib/ynab/models/error_response.rb +54 -19
- data/lib/ynab/models/hybrid_transaction.rb +120 -47
- data/lib/ynab/models/hybrid_transaction_all_of.rb +304 -0
- data/lib/ynab/models/hybrid_transactions_response.rb +54 -19
- data/lib/ynab/models/hybrid_transactions_response_data.rb +55 -20
- data/lib/ynab/models/month_detail.rb +73 -28
- data/lib/ynab/models/{update_transactions_wrapper.rb → month_detail_all_of.rb} +66 -30
- data/lib/ynab/models/month_detail_response.rb +54 -19
- data/lib/ynab/models/month_detail_response_data.rb +54 -19
- data/lib/ynab/models/month_summaries_response.rb +54 -19
- data/lib/ynab/models/month_summaries_response_data.rb +55 -20
- data/lib/ynab/models/month_summary.rb +64 -27
- data/lib/ynab/models/patch_month_category_wrapper.rb +54 -19
- data/lib/ynab/models/patch_transactions_wrapper.rb +54 -19
- data/lib/ynab/models/payee.rb +59 -23
- data/lib/ynab/models/payee_location.rb +59 -24
- data/lib/ynab/models/payee_location_response.rb +54 -19
- data/lib/ynab/models/payee_location_response_data.rb +54 -19
- data/lib/ynab/models/payee_locations_response.rb +54 -19
- data/lib/ynab/models/payee_locations_response_data.rb +54 -19
- data/lib/ynab/models/payee_response.rb +54 -19
- data/lib/ynab/models/payee_response_data.rb +54 -19
- data/lib/ynab/models/payees_response.rb +54 -19
- data/lib/ynab/models/payees_response_data.rb +55 -20
- data/lib/ynab/models/post_account_wrapper.rb +54 -19
- data/lib/ynab/models/post_transactions_wrapper.rb +55 -20
- data/lib/ynab/models/put_transaction_wrapper.rb +54 -19
- data/lib/ynab/models/save_account.rb +78 -21
- data/lib/ynab/models/save_category_response.rb +54 -19
- data/lib/ynab/models/save_category_response_data.rb +55 -20
- data/lib/ynab/models/save_month_category.rb +54 -19
- data/lib/ynab/models/save_sub_transaction.rb +62 -23
- data/lib/ynab/models/save_transaction.rb +89 -34
- data/lib/ynab/models/save_transaction_with_id.rb +103 -47
- data/lib/ynab/models/{save_transactions_wrapper.rb → save_transaction_with_id_all_of.rb} +60 -36
- data/lib/ynab/models/save_transaction_with_optional_fields.rb +82 -34
- data/lib/ynab/models/save_transactions_response.rb +54 -19
- data/lib/ynab/models/save_transactions_response_data.rb +58 -24
- data/lib/ynab/models/scheduled_sub_transaction.rb +67 -28
- data/lib/ynab/models/scheduled_transaction_detail.rb +96 -37
- data/lib/ynab/models/scheduled_transaction_detail_all_of.rb +262 -0
- data/lib/ynab/models/scheduled_transaction_response.rb +54 -19
- data/lib/ynab/models/scheduled_transaction_response_data.rb +54 -19
- data/lib/ynab/models/scheduled_transaction_summary.rb +81 -33
- data/lib/ynab/models/scheduled_transactions_response.rb +54 -19
- data/lib/ynab/models/scheduled_transactions_response_data.rb +55 -20
- data/lib/ynab/models/sub_transaction.rb +72 -30
- data/lib/ynab/models/transaction_detail.rb +114 -45
- data/lib/ynab/models/{save_transaction_wrapper.rb → transaction_detail_all_of.rb} +102 -29
- data/lib/ynab/models/transaction_response.rb +54 -19
- data/lib/ynab/models/transaction_response_data.rb +54 -19
- data/lib/ynab/models/transaction_summary.rb +99 -41
- data/lib/ynab/models/transactions_import_response.rb +54 -19
- data/lib/ynab/models/transactions_import_response_data.rb +54 -19
- data/lib/ynab/models/transactions_response.rb +54 -19
- data/lib/ynab/models/transactions_response_data.rb +55 -20
- data/lib/ynab/models/user.rb +54 -19
- data/lib/ynab/models/user_response.rb +54 -19
- data/lib/ynab/models/user_response_data.rb +54 -19
- data/lib/ynab/version.rb +1 -1
- data/lib/ynab.rb +21 -16
- data/open_api_spec.yaml +3012 -0
- data/templates/api_client.mustache +274 -0
- data/templates/api_client_typhoeus_partial.mustache +156 -0
- data/templates/api_doc.mustache +44 -0
- data/templates/gem.mustache +84 -0
- data/templates/partial_model_generic_doc.mustache +9 -0
- data/ynab.gemspec +38 -0
- metadata +197 -90
- data/lib/ynab/models/loan_account_periodic_value.rb +0 -175
- data/lib/ynab/models/save_account_wrapper.rb +0 -189
- data/lib/ynab/models/update_transaction.rb +0 -407
- data/spec/models/transaction_detail_spec.rb +0 -11
data/lib/ynab/api/user_api.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
=begin
|
2
2
|
#YNAB API Endpoints
|
3
3
|
|
4
|
-
#Our API uses a REST based design, leverages the JSON data format, and relies upon HTTPS for transport. We respond with meaningful HTTP response codes and if an error occurs, we include error details in the response body. API Documentation is at https://api.
|
4
|
+
#Our API uses a REST based design, leverages the JSON data format, and relies upon HTTPS for transport. We respond with meaningful HTTP response codes and if an error occurs, we include error details in the response body. API Documentation is at https://api.ynab.com
|
5
5
|
|
6
|
-
OpenAPI
|
6
|
+
The version of the OpenAPI document: 1.0.0
|
7
7
|
|
8
|
-
Generated by: https://
|
9
|
-
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 6.6.0
|
10
10
|
|
11
11
|
=end
|
12
12
|
|
13
|
-
require '
|
13
|
+
require 'cgi'
|
14
14
|
|
15
15
|
module YNAB
|
16
16
|
class UserApi
|
@@ -31,7 +31,7 @@ module YNAB
|
|
31
31
|
# User info
|
32
32
|
# Returns authenticated user information
|
33
33
|
# @param [Hash] opts the optional parameters
|
34
|
-
# @return [Array<(UserResponse,
|
34
|
+
# @return [Array<(UserResponse, Integer, Hash)>] UserResponse data, response status code and response headers
|
35
35
|
def get_user_with_http_info(opts = {})
|
36
36
|
if @api_client.config.debugging
|
37
37
|
@api_client.config.logger.debug 'Calling API: UserApi.get_user ...'
|
@@ -40,26 +40,36 @@ module YNAB
|
|
40
40
|
local_var_path = '/user'
|
41
41
|
|
42
42
|
# query parameters
|
43
|
-
query_params = {}
|
43
|
+
query_params = opts[:query_params] || {}
|
44
44
|
|
45
45
|
# header parameters
|
46
|
-
header_params = {}
|
46
|
+
header_params = opts[:header_params] || {}
|
47
47
|
# HTTP header 'Accept' (if needed)
|
48
48
|
header_params['Accept'] = @api_client.select_header_accept(['application/json'])
|
49
49
|
|
50
50
|
# form parameters
|
51
|
-
form_params = {}
|
51
|
+
form_params = opts[:form_params] || {}
|
52
52
|
|
53
53
|
# http body (model)
|
54
|
-
post_body =
|
55
|
-
|
56
|
-
|
54
|
+
post_body = opts[:debug_body]
|
55
|
+
|
56
|
+
# return_type
|
57
|
+
return_type = opts[:debug_return_type] || 'UserResponse'
|
58
|
+
|
59
|
+
# auth_names
|
60
|
+
auth_names = opts[:debug_auth_names] || ['bearer']
|
61
|
+
|
62
|
+
new_options = opts.merge(
|
63
|
+
:operation => :"UserApi.get_user",
|
57
64
|
:header_params => header_params,
|
58
65
|
:query_params => query_params,
|
59
66
|
:form_params => form_params,
|
60
67
|
:body => post_body,
|
61
68
|
:auth_names => auth_names,
|
62
|
-
:return_type =>
|
69
|
+
:return_type => return_type
|
70
|
+
)
|
71
|
+
|
72
|
+
data, status_code, headers = @api_client.call_api(:GET, local_var_path, new_options)
|
63
73
|
if @api_client.config.debugging
|
64
74
|
@api_client.config.logger.debug "API called: UserApi#get_user\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
|
65
75
|
end
|
data/lib/ynab/api_client.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
=begin
|
2
2
|
#YNAB API Endpoints
|
3
3
|
|
4
|
-
#Our API uses a REST based design, leverages the JSON data format, and relies upon HTTPS for transport. We respond with meaningful HTTP response codes and if an error occurs, we include error details in the response body. API Documentation is at https://api.
|
4
|
+
#Our API uses a REST based design, leverages the JSON data format, and relies upon HTTPS for transport. We respond with meaningful HTTP response codes and if an error occurs, we include error details in the response body. API Documentation is at https://api.ynab.com
|
5
5
|
|
6
|
-
OpenAPI
|
6
|
+
The version of the OpenAPI document: 1.0.0
|
7
7
|
|
8
|
-
Generated by: https://
|
9
|
-
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 6.6.0
|
10
10
|
|
11
11
|
=end
|
12
12
|
|
@@ -14,8 +14,8 @@ require 'date'
|
|
14
14
|
require 'json'
|
15
15
|
require 'logger'
|
16
16
|
require 'tempfile'
|
17
|
+
require 'time'
|
17
18
|
require 'typhoeus'
|
18
|
-
require 'uri'
|
19
19
|
|
20
20
|
module YNAB
|
21
21
|
class ApiClient
|
@@ -35,7 +35,7 @@ module YNAB
|
|
35
35
|
@config = config
|
36
36
|
@user_agent = "api_client/ruby/#{VERSION}"
|
37
37
|
@default_headers = {
|
38
|
-
'Content-Type' =>
|
38
|
+
'Content-Type' => 'application/json',
|
39
39
|
'User-Agent' => @user_agent
|
40
40
|
}
|
41
41
|
end
|
@@ -46,7 +46,7 @@ module YNAB
|
|
46
46
|
|
47
47
|
# Call an API with given options.
|
48
48
|
#
|
49
|
-
# @return [Array<(Object,
|
49
|
+
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
|
50
50
|
# the data deserialized from response body (could be nil), response status code and response headers.
|
51
51
|
def call_api(http_method, path, opts = {})
|
52
52
|
request = build_request(http_method, path, opts)
|
@@ -90,12 +90,13 @@ module YNAB
|
|
90
90
|
# @option opts [Object] :body HTTP body (JSON/XML)
|
91
91
|
# @return [Typhoeus::Request] A Typhoeus Request
|
92
92
|
def build_request(http_method, path, opts = {})
|
93
|
-
url = build_request_url(path)
|
93
|
+
url = build_request_url(path, opts)
|
94
94
|
http_method = http_method.to_sym.downcase
|
95
95
|
|
96
96
|
header_params = @default_headers.merge(opts[:header_params] || {})
|
97
97
|
query_params = opts[:query_params] || {}
|
98
98
|
form_params = opts[:form_params] || {}
|
99
|
+
follow_location = opts[:follow_location] || true
|
99
100
|
|
100
101
|
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
101
102
|
|
@@ -112,7 +113,8 @@ module YNAB
|
|
112
113
|
:ssl_verifyhost => _verify_ssl_host,
|
113
114
|
:sslcert => @config.cert_file,
|
114
115
|
:sslkey => @config.key_file,
|
115
|
-
:verbose => @config.debugging
|
116
|
+
:verbose => @config.debugging,
|
117
|
+
:followlocation => follow_location
|
116
118
|
}
|
117
119
|
|
118
120
|
# set custom cert, if provided
|
@@ -131,6 +133,72 @@ module YNAB
|
|
131
133
|
request
|
132
134
|
end
|
133
135
|
|
136
|
+
# Builds the HTTP request body
|
137
|
+
#
|
138
|
+
# @param [Hash] header_params Header parameters
|
139
|
+
# @param [Hash] form_params Query parameters
|
140
|
+
# @param [Object] body HTTP body (JSON/XML)
|
141
|
+
# @return [String] HTTP body data in the form of string
|
142
|
+
def build_request_body(header_params, form_params, body)
|
143
|
+
# http form
|
144
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
145
|
+
header_params['Content-Type'] == 'multipart/form-data'
|
146
|
+
data = {}
|
147
|
+
form_params.each do |key, value|
|
148
|
+
case value
|
149
|
+
when ::File, ::Array, nil
|
150
|
+
# let typhoeus handle File, Array and nil parameters
|
151
|
+
data[key] = value
|
152
|
+
else
|
153
|
+
data[key] = value.to_s
|
154
|
+
end
|
155
|
+
end
|
156
|
+
elsif body
|
157
|
+
data = body.is_a?(String) ? body : body.to_json
|
158
|
+
else
|
159
|
+
data = nil
|
160
|
+
end
|
161
|
+
data
|
162
|
+
end
|
163
|
+
|
164
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
165
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
166
|
+
# The response body is written to the file in chunks in order to handle files which
|
167
|
+
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
168
|
+
# process can use.
|
169
|
+
#
|
170
|
+
# @see Configuration#temp_folder_path
|
171
|
+
def download_file(request)
|
172
|
+
tempfile = nil
|
173
|
+
encoding = nil
|
174
|
+
request.on_headers do |response|
|
175
|
+
content_disposition = response.headers['Content-Disposition']
|
176
|
+
if content_disposition && content_disposition =~ /filename=/i
|
177
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
178
|
+
prefix = sanitize_filename(filename)
|
179
|
+
else
|
180
|
+
prefix = 'download-'
|
181
|
+
end
|
182
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
183
|
+
encoding = response.body.encoding
|
184
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
185
|
+
@tempfile = tempfile
|
186
|
+
end
|
187
|
+
request.on_body do |chunk|
|
188
|
+
chunk.force_encoding(encoding)
|
189
|
+
tempfile.write(chunk)
|
190
|
+
end
|
191
|
+
request.on_complete do |response|
|
192
|
+
if tempfile
|
193
|
+
tempfile.close
|
194
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
195
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
196
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
197
|
+
"explicitly with `tempfile.delete`"
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
134
202
|
# Check if the given MIME is a JSON MIME.
|
135
203
|
# JSON MIME examples:
|
136
204
|
# application/json
|
@@ -140,13 +208,13 @@ module YNAB
|
|
140
208
|
# @param [String] mime MIME
|
141
209
|
# @return [Boolean] True if the MIME is application/json
|
142
210
|
def json_mime?(mime)
|
143
|
-
|
211
|
+
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
144
212
|
end
|
145
213
|
|
146
214
|
# Deserialize the response to the given return type.
|
147
215
|
#
|
148
216
|
# @param [Response] response HTTP response
|
149
|
-
# @param [String] return_type some examples: "User", "Array
|
217
|
+
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
150
218
|
def deserialize(response, return_type)
|
151
219
|
body = response.body
|
152
220
|
|
@@ -167,7 +235,7 @@ module YNAB
|
|
167
235
|
begin
|
168
236
|
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
169
237
|
rescue JSON::ParserError => e
|
170
|
-
if %w(String Date
|
238
|
+
if %w(String Date Time).include?(return_type)
|
171
239
|
data = body
|
172
240
|
else
|
173
241
|
raise e
|
@@ -190,11 +258,11 @@ module YNAB
|
|
190
258
|
data.to_i
|
191
259
|
when 'Float'
|
192
260
|
data.to_f
|
193
|
-
when '
|
261
|
+
when 'Boolean'
|
194
262
|
data == true
|
195
|
-
when '
|
263
|
+
when 'Time'
|
196
264
|
# parse date time (expecting ISO 8601 format)
|
197
|
-
|
265
|
+
Time.parse data
|
198
266
|
when 'Date'
|
199
267
|
# parse date time (expecting ISO 8601 format)
|
200
268
|
Date.parse data
|
@@ -204,54 +272,17 @@ module YNAB
|
|
204
272
|
when /\AArray<(.+)>\z/
|
205
273
|
# e.g. Array<Pet>
|
206
274
|
sub_type = $1
|
207
|
-
data.map {|item| convert_to_type(item, sub_type) }
|
275
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
208
276
|
when /\AHash\<String, (.+)\>\z/
|
209
277
|
# e.g. Hash<String, Integer>
|
210
278
|
sub_type = $1
|
211
279
|
{}.tap do |hash|
|
212
|
-
data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
|
280
|
+
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
213
281
|
end
|
214
282
|
else
|
215
|
-
# models
|
216
|
-
YNAB.const_get(return_type)
|
217
|
-
|
218
|
-
end
|
219
|
-
end
|
220
|
-
end
|
221
|
-
|
222
|
-
# Save response body into a file in (the defined) temporary folder, using the filename
|
223
|
-
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
224
|
-
# The response body is written to the file in chunks in order to handle files which
|
225
|
-
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
226
|
-
# process can use.
|
227
|
-
#
|
228
|
-
# @see Configuration#temp_folder_path
|
229
|
-
def download_file(request)
|
230
|
-
tempfile = nil
|
231
|
-
encoding = nil
|
232
|
-
request.on_headers do |response|
|
233
|
-
content_disposition = response.headers['Content-Disposition']
|
234
|
-
if content_disposition and content_disposition =~ /filename=/i
|
235
|
-
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
236
|
-
prefix = sanitize_filename(filename)
|
237
|
-
else
|
238
|
-
prefix = 'download-'
|
239
|
-
end
|
240
|
-
prefix = prefix + '-' unless prefix.end_with?('-')
|
241
|
-
encoding = response.body.encoding
|
242
|
-
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
243
|
-
@tempfile = tempfile
|
244
|
-
end
|
245
|
-
request.on_body do |chunk|
|
246
|
-
chunk.force_encoding(encoding)
|
247
|
-
tempfile.write(chunk)
|
248
|
-
end
|
249
|
-
request.on_complete do |response|
|
250
|
-
tempfile.close
|
251
|
-
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
252
|
-
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
253
|
-
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
254
|
-
"explicitly with `tempfile.delete`"
|
283
|
+
# models (e.g. Pet) or oneOf
|
284
|
+
klass = YNAB.const_get(return_type)
|
285
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
|
255
286
|
end
|
256
287
|
end
|
257
288
|
|
@@ -264,42 +295,13 @@ module YNAB
|
|
264
295
|
filename.gsub(/.*[\/\\]/, '')
|
265
296
|
end
|
266
297
|
|
267
|
-
def build_request_url(path)
|
298
|
+
def build_request_url(path, opts = {})
|
268
299
|
# Add leading and trailing slashes to path
|
269
300
|
path = "/#{path}".gsub(/\/+/, '/')
|
270
|
-
|
271
|
-
@config.base_url + path
|
272
|
-
end
|
273
|
-
|
274
|
-
# Builds the HTTP request body
|
275
|
-
#
|
276
|
-
# @param [Hash] header_params Header parameters
|
277
|
-
# @param [Hash] form_params Query parameters
|
278
|
-
# @param [Object] body HTTP body (JSON/XML)
|
279
|
-
# @return [String] HTTP body data in the form of string
|
280
|
-
def build_request_body(header_params, form_params, body)
|
281
|
-
# http form
|
282
|
-
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
283
|
-
header_params['Content-Type'] == 'multipart/form-data'
|
284
|
-
data = {}
|
285
|
-
form_params.each do |key, value|
|
286
|
-
case value
|
287
|
-
when ::File, ::Array, nil
|
288
|
-
# let typhoeus handle File, Array and nil parameters
|
289
|
-
data[key] = value
|
290
|
-
else
|
291
|
-
data[key] = value.to_s
|
292
|
-
end
|
293
|
-
end
|
294
|
-
elsif body
|
295
|
-
data = body.is_a?(String) ? body : body.to_json
|
296
|
-
else
|
297
|
-
data = nil
|
298
|
-
end
|
299
|
-
data
|
301
|
+
@config.base_url(opts[:operation]) + path
|
300
302
|
end
|
301
303
|
|
302
|
-
# Update
|
304
|
+
# Update header and query params based on authentication settings.
|
303
305
|
#
|
304
306
|
# @param [Hash] header_params Header parameters
|
305
307
|
# @param [Hash] query_params Query parameters
|
@@ -311,14 +313,14 @@ module YNAB
|
|
311
313
|
case auth_setting[:in]
|
312
314
|
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
313
315
|
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
314
|
-
else fail ArgumentError, 'Authentication token must be in `query`
|
316
|
+
else fail ArgumentError, 'Authentication token must be in `query` or `header`'
|
315
317
|
end
|
316
318
|
end
|
317
319
|
end
|
318
320
|
|
319
321
|
# Sets user agent in HTTP header
|
320
322
|
#
|
321
|
-
# @param [String] user_agent User agent (e.g.
|
323
|
+
# @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
|
322
324
|
def user_agent=(user_agent)
|
323
325
|
@user_agent = user_agent
|
324
326
|
@default_headers['User-Agent'] = @user_agent
|
@@ -331,18 +333,18 @@ module YNAB
|
|
331
333
|
return nil if accepts.nil? || accepts.empty?
|
332
334
|
# use JSON when present, otherwise use all of the provided
|
333
335
|
json_accept = accepts.find { |s| json_mime?(s) }
|
334
|
-
|
336
|
+
json_accept || accepts.join(',')
|
335
337
|
end
|
336
338
|
|
337
339
|
# Return Content-Type header based on an array of content types provided.
|
338
340
|
# @param [Array] content_types array for Content-Type
|
339
341
|
# @return [String] the Content-Type header (e.g. application/json)
|
340
342
|
def select_header_content_type(content_types)
|
341
|
-
#
|
342
|
-
return
|
343
|
+
# return nil by default
|
344
|
+
return if content_types.nil? || content_types.empty?
|
343
345
|
# use JSON when present, otherwise use the first one
|
344
346
|
json_content_type = content_types.find { |s| json_mime?(s) }
|
345
|
-
|
347
|
+
json_content_type || content_types.first
|
346
348
|
end
|
347
349
|
|
348
350
|
# Convert object (array, hash, object, etc) to JSON string.
|
@@ -352,7 +354,7 @@ module YNAB
|
|
352
354
|
return model if model.nil? || model.is_a?(String)
|
353
355
|
local_body = nil
|
354
356
|
if model.is_a?(Array)
|
355
|
-
local_body = model.map{|m| object_to_hash(m) }
|
357
|
+
local_body = model.map { |m| object_to_hash(m) }
|
356
358
|
else
|
357
359
|
local_body = object_to_hash(model)
|
358
360
|
end
|
data/lib/ynab/configuration.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
=begin
|
2
2
|
#YNAB API Endpoints
|
3
3
|
|
4
|
-
#Our API uses a REST based design, leverages the JSON data format, and relies upon HTTPS for transport. We respond with meaningful HTTP response codes and if an error occurs, we include error details in the response body. API Documentation is at https://api.
|
4
|
+
#Our API uses a REST based design, leverages the JSON data format, and relies upon HTTPS for transport. We respond with meaningful HTTP response codes and if an error occurs, we include error details in the response body. API Documentation is at https://api.ynab.com
|
5
5
|
|
6
|
-
OpenAPI
|
6
|
+
The version of the OpenAPI document: 1.0.0
|
7
7
|
|
8
|
-
Generated by: https://
|
9
|
-
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 6.6.0
|
10
10
|
|
11
11
|
=end
|
12
12
|
|
13
|
-
require 'uri'
|
14
|
-
|
15
13
|
module YNAB
|
16
14
|
class Configuration
|
17
15
|
# Defines url scheme
|
@@ -23,6 +21,18 @@ module YNAB
|
|
23
21
|
# Defines url base path
|
24
22
|
attr_accessor :base_path
|
25
23
|
|
24
|
+
# Define server configuration index
|
25
|
+
attr_accessor :server_index
|
26
|
+
|
27
|
+
# Define server operation configuration index
|
28
|
+
attr_accessor :server_operation_index
|
29
|
+
|
30
|
+
# Default server variables
|
31
|
+
attr_accessor :server_variables
|
32
|
+
|
33
|
+
# Default server operation variables
|
34
|
+
attr_accessor :server_operation_variables
|
35
|
+
|
26
36
|
# Defines API keys used with API Key authentications.
|
27
37
|
#
|
28
38
|
# @return [Hash] key: parameter name, value: parameter value (API key)
|
@@ -52,6 +62,16 @@ module YNAB
|
|
52
62
|
# Defines the access token (Bearer) used with OAuth2.
|
53
63
|
attr_accessor :access_token
|
54
64
|
|
65
|
+
# Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
|
66
|
+
# Overrides the access_token if set
|
67
|
+
# @return [Proc]
|
68
|
+
attr_accessor :access_token_getter
|
69
|
+
|
70
|
+
# Set this to return data as binary instead of downloading a temp file. When enabled (set to true)
|
71
|
+
# HTTP responses with return type `File` will be returned as a stream of binary data.
|
72
|
+
# Default to false.
|
73
|
+
attr_accessor :return_binary_data
|
74
|
+
|
55
75
|
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
56
76
|
# details will be logged with `logger.debug` (see the `logger` attribute).
|
57
77
|
# Default to false.
|
@@ -123,23 +143,28 @@ module YNAB
|
|
123
143
|
# https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
|
124
144
|
attr_accessor :params_encoding
|
125
145
|
|
146
|
+
|
126
147
|
attr_accessor :inject_format
|
127
148
|
|
128
149
|
attr_accessor :force_ending_format
|
129
150
|
|
130
151
|
def initialize
|
131
152
|
@scheme = 'https'
|
132
|
-
@host = 'api.
|
153
|
+
@host = 'api.ynab.com'
|
133
154
|
@base_path = '/v1'
|
155
|
+
@server_index = 0
|
156
|
+
@server_operation_index = {}
|
157
|
+
@server_variables = {}
|
158
|
+
@server_operation_variables = {}
|
134
159
|
@api_key = {}
|
135
160
|
@api_key_prefix = {}
|
136
|
-
@timeout = 0
|
137
161
|
@client_side_validation = true
|
138
162
|
@verify_ssl = true
|
139
163
|
@verify_ssl_host = true
|
140
|
-
@params_encoding = nil
|
141
164
|
@cert_file = nil
|
142
165
|
@key_file = nil
|
166
|
+
@timeout = 0
|
167
|
+
@params_encoding = nil
|
143
168
|
@debugging = false
|
144
169
|
@inject_format = false
|
145
170
|
@force_ending_format = false
|
@@ -173,20 +198,32 @@ module YNAB
|
|
173
198
|
@base_path = '' if @base_path == '/'
|
174
199
|
end
|
175
200
|
|
176
|
-
|
177
|
-
|
201
|
+
# Returns base URL for specified operation based on server settings
|
202
|
+
def base_url(operation = nil)
|
203
|
+
index = server_operation_index[operation]
|
204
|
+
return "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '') if index == nil
|
205
|
+
|
206
|
+
server_url(index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
|
178
207
|
end
|
179
208
|
|
180
209
|
# Gets API key (with prefix if set).
|
181
210
|
# @param [String] param_name the parameter name of API key auth
|
182
|
-
def api_key_with_prefix(param_name)
|
211
|
+
def api_key_with_prefix(param_name, param_alias = nil)
|
212
|
+
key = @api_key[param_name]
|
213
|
+
key = @api_key.fetch(param_alias, key) unless param_alias.nil?
|
183
214
|
if @api_key_prefix[param_name]
|
184
|
-
"#{@api_key_prefix[param_name]} #{
|
215
|
+
"#{@api_key_prefix[param_name]} #{key}"
|
185
216
|
else
|
186
|
-
|
217
|
+
key
|
187
218
|
end
|
188
219
|
end
|
189
220
|
|
221
|
+
# Gets access_token using access_token_getter or uses the static access_token
|
222
|
+
def access_token_with_refresh
|
223
|
+
return access_token if access_token_getter.nil?
|
224
|
+
access_token_getter.call
|
225
|
+
end
|
226
|
+
|
190
227
|
# Gets Basic Auth token string
|
191
228
|
def basic_auth_token
|
192
229
|
'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
|
@@ -197,12 +234,62 @@ module YNAB
|
|
197
234
|
{
|
198
235
|
'bearer' =>
|
199
236
|
{
|
200
|
-
type: '
|
237
|
+
type: 'bearer',
|
201
238
|
in: 'header',
|
202
239
|
key: 'Authorization',
|
203
|
-
value:
|
240
|
+
value: "Bearer #{access_token_with_refresh}"
|
204
241
|
},
|
205
242
|
}
|
206
243
|
end
|
244
|
+
|
245
|
+
# Returns an array of Server setting
|
246
|
+
def server_settings
|
247
|
+
[
|
248
|
+
{
|
249
|
+
url: "https://api.ynab.com/v1",
|
250
|
+
description: "No description provided",
|
251
|
+
}
|
252
|
+
]
|
253
|
+
end
|
254
|
+
|
255
|
+
def operation_server_settings
|
256
|
+
{
|
257
|
+
}
|
258
|
+
end
|
259
|
+
|
260
|
+
# Returns URL based on server settings
|
261
|
+
#
|
262
|
+
# @param index array index of the server settings
|
263
|
+
# @param variables hash of variable and the corresponding value
|
264
|
+
def server_url(index, variables = {}, servers = nil)
|
265
|
+
servers = server_settings if servers == nil
|
266
|
+
|
267
|
+
# check array index out of bound
|
268
|
+
if (index < 0 || index >= servers.size)
|
269
|
+
fail ArgumentError, "Invalid index #{index} when selecting the server. Must be less than #{servers.size}"
|
270
|
+
end
|
271
|
+
|
272
|
+
server = servers[index]
|
273
|
+
url = server[:url]
|
274
|
+
|
275
|
+
return url unless server.key? :variables
|
276
|
+
|
277
|
+
# go through variable and assign a value
|
278
|
+
server[:variables].each do |name, variable|
|
279
|
+
if variables.key?(name)
|
280
|
+
if (!server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name]))
|
281
|
+
url.gsub! "{" + name.to_s + "}", variables[name]
|
282
|
+
else
|
283
|
+
fail ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
|
284
|
+
end
|
285
|
+
else
|
286
|
+
# use default value
|
287
|
+
url.gsub! "{" + name.to_s + "}", server[:variables][name][:default_value]
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
url
|
292
|
+
end
|
293
|
+
|
207
294
|
end
|
208
295
|
end
|