ynab 1.31.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 +3 -3
- 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 +78 -41
- data/lib/ynab/api/budgets_api.rb +68 -36
- data/lib/ynab/api/categories_api.rb +108 -60
- data/lib/ynab/api/deprecated_api.rb +32 -17
- data/lib/ynab/api/months_api.rb +49 -28
- data/lib/ynab/api/payee_locations_api.rb +73 -41
- data/lib/ynab/api/payees_api.rb +49 -28
- data/lib/ynab/api/scheduled_transactions_api.rb +49 -28
- data/lib/ynab/api/transactions_api.rb +268 -140
- data/lib/ynab/api/user_api.rb +22 -12
- data/lib/ynab/api_client.rb +97 -95
- data/lib/ynab/configuration.rb +101 -14
- data/lib/ynab/models/account.rb +117 -55
- data/lib/ynab/models/account_response.rb +53 -18
- data/lib/ynab/models/account_response_data.rb +53 -18
- data/lib/ynab/models/account_type.rb +30 -20
- data/lib/ynab/models/accounts_response.rb +53 -18
- data/lib/ynab/models/accounts_response_data.rb +54 -19
- data/lib/ynab/models/budget_detail.rb +80 -35
- data/lib/ynab/models/budget_detail_all_of.rb +320 -0
- data/lib/ynab/models/budget_detail_response.rb +53 -18
- data/lib/ynab/models/budget_detail_response_data.rb +54 -19
- data/lib/ynab/models/budget_settings.rb +56 -29
- data/lib/ynab/models/budget_settings_response.rb +53 -18
- data/lib/ynab/models/budget_settings_response_data.rb +53 -18
- data/lib/ynab/models/budget_summary.rb +63 -26
- data/lib/ynab/models/budget_summary_response.rb +53 -18
- data/lib/ynab/models/budget_summary_response_data.rb +54 -20
- data/lib/ynab/models/bulk_response.rb +53 -18
- data/lib/ynab/models/bulk_response_data.rb +53 -18
- data/lib/ynab/models/bulk_response_data_bulk.rb +54 -19
- data/lib/ynab/models/bulk_transactions.rb +53 -18
- data/lib/ynab/models/categories_response.rb +53 -18
- data/lib/ynab/models/categories_response_data.rb +54 -19
- data/lib/ynab/models/category.rb +110 -48
- data/lib/ynab/models/category_group.rb +58 -23
- data/lib/ynab/models/category_group_with_categories.rb +67 -24
- 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 +53 -18
- data/lib/ynab/models/category_response_data.rb +53 -18
- data/lib/ynab/models/currency_format.rb +62 -27
- data/lib/ynab/models/date_format.rb +53 -18
- data/lib/ynab/models/error_detail.rb +55 -20
- data/lib/ynab/models/error_response.rb +53 -18
- data/lib/ynab/models/hybrid_transaction.rb +118 -46
- data/lib/ynab/models/hybrid_transaction_all_of.rb +304 -0
- data/lib/ynab/models/hybrid_transactions_response.rb +53 -18
- data/lib/ynab/models/hybrid_transactions_response_data.rb +54 -19
- data/lib/ynab/models/month_detail.rb +72 -27
- data/lib/ynab/models/{update_transactions_wrapper.rb → month_detail_all_of.rb} +66 -30
- data/lib/ynab/models/month_detail_response.rb +53 -18
- data/lib/ynab/models/month_detail_response_data.rb +53 -18
- data/lib/ynab/models/month_summaries_response.rb +53 -18
- data/lib/ynab/models/month_summaries_response_data.rb +54 -19
- data/lib/ynab/models/month_summary.rb +63 -26
- data/lib/ynab/models/patch_month_category_wrapper.rb +53 -18
- data/lib/ynab/models/patch_transactions_wrapper.rb +53 -18
- data/lib/ynab/models/payee.rb +58 -22
- data/lib/ynab/models/payee_location.rb +58 -23
- data/lib/ynab/models/payee_location_response.rb +53 -18
- data/lib/ynab/models/payee_location_response_data.rb +53 -18
- data/lib/ynab/models/payee_locations_response.rb +53 -18
- data/lib/ynab/models/payee_locations_response_data.rb +53 -18
- data/lib/ynab/models/payee_response.rb +53 -18
- data/lib/ynab/models/payee_response_data.rb +53 -18
- data/lib/ynab/models/payees_response.rb +53 -18
- data/lib/ynab/models/payees_response_data.rb +54 -19
- data/lib/ynab/models/post_account_wrapper.rb +53 -18
- data/lib/ynab/models/post_transactions_wrapper.rb +54 -19
- data/lib/ynab/models/put_transaction_wrapper.rb +53 -18
- data/lib/ynab/models/save_account.rb +77 -20
- data/lib/ynab/models/save_category_response.rb +53 -18
- data/lib/ynab/models/save_category_response_data.rb +54 -19
- data/lib/ynab/models/save_month_category.rb +53 -18
- data/lib/ynab/models/save_sub_transaction.rb +61 -22
- data/lib/ynab/models/save_transaction.rb +88 -33
- data/lib/ynab/models/save_transaction_with_id.rb +102 -46
- 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 +81 -33
- data/lib/ynab/models/save_transactions_response.rb +53 -18
- data/lib/ynab/models/save_transactions_response_data.rb +57 -23
- data/lib/ynab/models/scheduled_sub_transaction.rb +66 -27
- data/lib/ynab/models/scheduled_transaction_detail.rb +94 -36
- data/lib/ynab/models/scheduled_transaction_detail_all_of.rb +262 -0
- data/lib/ynab/models/scheduled_transaction_response.rb +53 -18
- data/lib/ynab/models/scheduled_transaction_response_data.rb +53 -18
- data/lib/ynab/models/scheduled_transaction_summary.rb +80 -32
- data/lib/ynab/models/scheduled_transactions_response.rb +53 -18
- data/lib/ynab/models/scheduled_transactions_response_data.rb +54 -19
- data/lib/ynab/models/sub_transaction.rb +71 -29
- data/lib/ynab/models/transaction_detail.rb +112 -44
- data/lib/ynab/models/{save_transaction_wrapper.rb → transaction_detail_all_of.rb} +102 -29
- data/lib/ynab/models/transaction_response.rb +53 -18
- data/lib/ynab/models/transaction_response_data.rb +53 -18
- data/lib/ynab/models/transaction_summary.rb +98 -40
- data/lib/ynab/models/transactions_import_response.rb +53 -18
- data/lib/ynab/models/transactions_import_response_data.rb +53 -18
- data/lib/ynab/models/transactions_response.rb +53 -18
- data/lib/ynab/models/transactions_response_data.rb +54 -19
- data/lib/ynab/models/user.rb +53 -18
- data/lib/ynab/models/user_response.rb +53 -18
- data/lib/ynab/models/user_response_data.rb +53 -18
- data/lib/ynab/version.rb +1 -1
- data/lib/ynab.rb +19 -14
- 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 +194 -87
- 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
@@ -0,0 +1,274 @@
|
|
1
|
+
=begin
|
2
|
+
{{> api_info}}
|
3
|
+
=end
|
4
|
+
|
5
|
+
require 'date'
|
6
|
+
require 'json'
|
7
|
+
require 'logger'
|
8
|
+
require 'tempfile'
|
9
|
+
require 'time'
|
10
|
+
{{^isFaraday}}
|
11
|
+
require 'typhoeus'
|
12
|
+
{{/isFaraday}}
|
13
|
+
{{#isFaraday}}
|
14
|
+
require 'faraday'
|
15
|
+
require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0')
|
16
|
+
{{/isFaraday}}
|
17
|
+
|
18
|
+
module {{moduleName}}
|
19
|
+
class ApiClient
|
20
|
+
# The Configuration object holding settings to be used in the API client.
|
21
|
+
attr_accessor :config
|
22
|
+
|
23
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
24
|
+
#
|
25
|
+
# @return [Hash]
|
26
|
+
attr_accessor :default_headers
|
27
|
+
|
28
|
+
attr_accessor :last_request
|
29
|
+
|
30
|
+
# Initializes the ApiClient
|
31
|
+
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
32
|
+
def initialize(config = Configuration.default)
|
33
|
+
@config = config
|
34
|
+
@user_agent = "{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}api_client/ruby/#{VERSION}{{/httpUserAgent}}"
|
35
|
+
@default_headers = {
|
36
|
+
'Content-Type' => 'application/json',
|
37
|
+
'User-Agent' => @user_agent
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.default
|
42
|
+
@@default ||= ApiClient.new
|
43
|
+
end
|
44
|
+
|
45
|
+
{{^isFaraday}}
|
46
|
+
{{> api_client_typhoeus_partial}}
|
47
|
+
{{/isFaraday}}
|
48
|
+
{{#isFaraday}}
|
49
|
+
{{> api_client_faraday_partial}}
|
50
|
+
{{/isFaraday}}
|
51
|
+
# Check if the given MIME is a JSON MIME.
|
52
|
+
# JSON MIME examples:
|
53
|
+
# application/json
|
54
|
+
# application/json; charset=UTF8
|
55
|
+
# APPLICATION/JSON
|
56
|
+
# */*
|
57
|
+
# @param [String] mime MIME
|
58
|
+
# @return [Boolean] True if the MIME is application/json
|
59
|
+
def json_mime?(mime)
|
60
|
+
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
61
|
+
end
|
62
|
+
|
63
|
+
# Deserialize the response to the given return type.
|
64
|
+
#
|
65
|
+
# @param [Response] response HTTP response
|
66
|
+
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
67
|
+
def deserialize(response, return_type)
|
68
|
+
body = response.body
|
69
|
+
|
70
|
+
# handle file downloading - return the File instance processed in request callbacks
|
71
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
72
|
+
{{^isFaraday}}
|
73
|
+
return @tempfile if return_type == 'File'
|
74
|
+
{{/isFaraday}}
|
75
|
+
{{#isFaraday}}
|
76
|
+
if return_type == 'File'
|
77
|
+
if @config.return_binary_data == true
|
78
|
+
# return byte stream
|
79
|
+
encoding = body.encoding
|
80
|
+
return @stream.join.force_encoding(encoding)
|
81
|
+
else
|
82
|
+
# return file instead of binary data
|
83
|
+
content_disposition = response.headers['Content-Disposition']
|
84
|
+
if content_disposition && content_disposition =~ /filename=/i
|
85
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
86
|
+
prefix = sanitize_filename(filename)
|
87
|
+
else
|
88
|
+
prefix = 'download-'
|
89
|
+
end
|
90
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
91
|
+
encoding = body.encoding
|
92
|
+
@tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
93
|
+
@tempfile.write(@stream.join.force_encoding(encoding))
|
94
|
+
@tempfile.close
|
95
|
+
@config.logger.info "Temp file written to #{@tempfile.path}, please copy the file to a proper folder "\
|
96
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
97
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
98
|
+
"explicitly with `tempfile.delete`"
|
99
|
+
return @tempfile
|
100
|
+
end
|
101
|
+
end
|
102
|
+
{{/isFaraday}}
|
103
|
+
|
104
|
+
return nil if body.nil? || body.empty?
|
105
|
+
|
106
|
+
# return response body directly for String return type
|
107
|
+
return body if return_type == 'String'
|
108
|
+
|
109
|
+
# ensuring a default content type
|
110
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
111
|
+
|
112
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
113
|
+
|
114
|
+
begin
|
115
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
116
|
+
rescue JSON::ParserError => e
|
117
|
+
if %w(String Date Time).include?(return_type)
|
118
|
+
data = body
|
119
|
+
else
|
120
|
+
raise e
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
convert_to_type data, return_type
|
125
|
+
end
|
126
|
+
|
127
|
+
# Convert data to the given return type.
|
128
|
+
# @param [Object] data Data to be converted
|
129
|
+
# @param [String] return_type Return type
|
130
|
+
# @return [Mixed] Data in a particular type
|
131
|
+
def convert_to_type(data, return_type)
|
132
|
+
return nil if data.nil?
|
133
|
+
case return_type
|
134
|
+
when 'String'
|
135
|
+
data.to_s
|
136
|
+
when 'Integer'
|
137
|
+
data.to_i
|
138
|
+
when 'Float'
|
139
|
+
data.to_f
|
140
|
+
when 'Boolean'
|
141
|
+
data == true
|
142
|
+
when 'Time'
|
143
|
+
# parse date time (expecting ISO 8601 format)
|
144
|
+
Time.parse data
|
145
|
+
when 'Date'
|
146
|
+
# parse date time (expecting ISO 8601 format)
|
147
|
+
Date.parse data
|
148
|
+
when 'Object'
|
149
|
+
# generic object (usually a Hash), return directly
|
150
|
+
data
|
151
|
+
when /\AArray<(.+)>\z/
|
152
|
+
# e.g. Array<Pet>
|
153
|
+
sub_type = $1
|
154
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
155
|
+
when /\AHash\<String, (.+)\>\z/
|
156
|
+
# e.g. Hash<String, Integer>
|
157
|
+
sub_type = $1
|
158
|
+
{}.tap do |hash|
|
159
|
+
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
160
|
+
end
|
161
|
+
else
|
162
|
+
# models (e.g. Pet) or oneOf
|
163
|
+
klass = {{moduleName}}.const_get(return_type)
|
164
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# Sanitize filename by removing path.
|
169
|
+
# e.g. ../../sun.gif becomes sun.gif
|
170
|
+
#
|
171
|
+
# @param [String] filename the filename to be sanitized
|
172
|
+
# @return [String] the sanitized filename
|
173
|
+
def sanitize_filename(filename)
|
174
|
+
filename.gsub(/.*[\/\\]/, '')
|
175
|
+
end
|
176
|
+
|
177
|
+
def build_request_url(path, opts = {})
|
178
|
+
# Add leading and trailing slashes to path
|
179
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
180
|
+
@config.base_url(opts[:operation]) + path
|
181
|
+
end
|
182
|
+
|
183
|
+
# Update header and query params based on authentication settings.
|
184
|
+
#
|
185
|
+
# @param [Hash] header_params Header parameters
|
186
|
+
# @param [Hash] query_params Query parameters
|
187
|
+
# @param [String] auth_names Authentication scheme name
|
188
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
189
|
+
Array(auth_names).each do |auth_name|
|
190
|
+
auth_setting = @config.auth_settings[auth_name]
|
191
|
+
next unless auth_setting
|
192
|
+
case auth_setting[:in]
|
193
|
+
when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
|
194
|
+
when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
|
195
|
+
else fail ArgumentError, 'Authentication token must be in `query` or `header`'
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
# Sets user agent in HTTP header
|
201
|
+
#
|
202
|
+
# @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
|
203
|
+
def user_agent=(user_agent)
|
204
|
+
@user_agent = user_agent
|
205
|
+
@default_headers['User-Agent'] = @user_agent
|
206
|
+
end
|
207
|
+
|
208
|
+
# Return Accept header based on an array of accepts provided.
|
209
|
+
# @param [Array] accepts array for Accept
|
210
|
+
# @return [String] the Accept header (e.g. application/json)
|
211
|
+
def select_header_accept(accepts)
|
212
|
+
return nil if accepts.nil? || accepts.empty?
|
213
|
+
# use JSON when present, otherwise use all of the provided
|
214
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
215
|
+
json_accept || accepts.join(',')
|
216
|
+
end
|
217
|
+
|
218
|
+
# Return Content-Type header based on an array of content types provided.
|
219
|
+
# @param [Array] content_types array for Content-Type
|
220
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
221
|
+
def select_header_content_type(content_types)
|
222
|
+
# return nil by default
|
223
|
+
return if content_types.nil? || content_types.empty?
|
224
|
+
# use JSON when present, otherwise use the first one
|
225
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
226
|
+
json_content_type || content_types.first
|
227
|
+
end
|
228
|
+
|
229
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
230
|
+
# @param [Object] model object to be converted into JSON string
|
231
|
+
# @return [String] JSON string representation of the object
|
232
|
+
def object_to_http_body(model)
|
233
|
+
return model if model.nil? || model.is_a?(String)
|
234
|
+
local_body = nil
|
235
|
+
if model.is_a?(Array)
|
236
|
+
local_body = model.map { |m| object_to_hash(m) }
|
237
|
+
else
|
238
|
+
local_body = object_to_hash(model)
|
239
|
+
end
|
240
|
+
local_body.to_json
|
241
|
+
end
|
242
|
+
|
243
|
+
# Convert object(non-array) to hash.
|
244
|
+
# @param [Object] obj object to be converted into JSON string
|
245
|
+
# @return [String] JSON string representation of the object
|
246
|
+
def object_to_hash(obj)
|
247
|
+
if obj.respond_to?(:to_hash)
|
248
|
+
obj.to_hash
|
249
|
+
else
|
250
|
+
obj
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
# Build parameter value according to the given collection format.
|
255
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
256
|
+
def build_collection_param(param, collection_format)
|
257
|
+
case collection_format
|
258
|
+
when :csv
|
259
|
+
param.join(',')
|
260
|
+
when :ssv
|
261
|
+
param.join(' ')
|
262
|
+
when :tsv
|
263
|
+
param.join("\t")
|
264
|
+
when :pipes
|
265
|
+
param.join('|')
|
266
|
+
when :multi
|
267
|
+
# return the array directly as typhoeus will handle it as expected
|
268
|
+
param
|
269
|
+
else
|
270
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
271
|
+
end
|
272
|
+
end
|
273
|
+
end
|
274
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# Call an API with given options.
|
2
|
+
#
|
3
|
+
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
|
4
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
5
|
+
def call_api(http_method, path, opts = {})
|
6
|
+
request = build_request(http_method, path, opts)
|
7
|
+
@last_request = request
|
8
|
+
response = request.run
|
9
|
+
|
10
|
+
if @config.debugging
|
11
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
12
|
+
end
|
13
|
+
|
14
|
+
unless response.success?
|
15
|
+
if response.timed_out?
|
16
|
+
fail ApiError.new('Connection timed out')
|
17
|
+
elsif response.code == 0
|
18
|
+
# Errors from libcurl will be made visible here
|
19
|
+
fail ApiError.new(:code => 0,
|
20
|
+
:message => response.return_message)
|
21
|
+
else
|
22
|
+
fail ApiError.new(:code => response.code,
|
23
|
+
:response_headers => response.headers,
|
24
|
+
:response_body => response.body),
|
25
|
+
response.status_message
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if opts[:return_type]
|
30
|
+
data = deserialize(response, opts[:return_type])
|
31
|
+
else
|
32
|
+
data = nil
|
33
|
+
end
|
34
|
+
return data, response.code, response.headers
|
35
|
+
end
|
36
|
+
|
37
|
+
# Builds the HTTP request
|
38
|
+
#
|
39
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
40
|
+
# @param [String] path URL path (e.g. /account/new)
|
41
|
+
# @option opts [Hash] :header_params Header parameters
|
42
|
+
# @option opts [Hash] :query_params Query parameters
|
43
|
+
# @option opts [Hash] :form_params Query parameters
|
44
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
45
|
+
# @return [Typhoeus::Request] A Typhoeus Request
|
46
|
+
def build_request(http_method, path, opts = {})
|
47
|
+
url = build_request_url(path, opts)
|
48
|
+
http_method = http_method.to_sym.downcase
|
49
|
+
|
50
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
51
|
+
query_params = opts[:query_params] || {}
|
52
|
+
form_params = opts[:form_params] || {}
|
53
|
+
follow_location = opts[:follow_location] || true
|
54
|
+
|
55
|
+
{{#hasAuthMethods}}
|
56
|
+
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
57
|
+
{{/hasAuthMethods}}
|
58
|
+
|
59
|
+
# set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
|
60
|
+
_verify_ssl_host = @config.verify_ssl_host ? 2 : 0
|
61
|
+
|
62
|
+
req_opts = {
|
63
|
+
:method => http_method,
|
64
|
+
:headers => header_params,
|
65
|
+
:params => query_params,
|
66
|
+
:params_encoding => @config.params_encoding,
|
67
|
+
:timeout => @config.timeout,
|
68
|
+
:ssl_verifypeer => @config.verify_ssl,
|
69
|
+
:ssl_verifyhost => _verify_ssl_host,
|
70
|
+
:sslcert => @config.cert_file,
|
71
|
+
:sslkey => @config.key_file,
|
72
|
+
:verbose => @config.debugging,
|
73
|
+
:followlocation => follow_location
|
74
|
+
}
|
75
|
+
|
76
|
+
# set custom cert, if provided
|
77
|
+
req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
|
78
|
+
|
79
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
80
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
81
|
+
req_opts.update :body => req_body
|
82
|
+
if @config.debugging
|
83
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
request = Typhoeus::Request.new(url, req_opts)
|
88
|
+
download_file(request) if opts[:return_type] == 'File'
|
89
|
+
request
|
90
|
+
end
|
91
|
+
|
92
|
+
# Builds the HTTP request body
|
93
|
+
#
|
94
|
+
# @param [Hash] header_params Header parameters
|
95
|
+
# @param [Hash] form_params Query parameters
|
96
|
+
# @param [Object] body HTTP body (JSON/XML)
|
97
|
+
# @return [String] HTTP body data in the form of string
|
98
|
+
def build_request_body(header_params, form_params, body)
|
99
|
+
# http form
|
100
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
101
|
+
header_params['Content-Type'] == 'multipart/form-data'
|
102
|
+
data = {}
|
103
|
+
form_params.each do |key, value|
|
104
|
+
case value
|
105
|
+
when ::File, ::Array, nil
|
106
|
+
# let typhoeus handle File, Array and nil parameters
|
107
|
+
data[key] = value
|
108
|
+
else
|
109
|
+
data[key] = value.to_s
|
110
|
+
end
|
111
|
+
end
|
112
|
+
elsif body
|
113
|
+
data = body.is_a?(String) ? body : body.to_json
|
114
|
+
else
|
115
|
+
data = nil
|
116
|
+
end
|
117
|
+
data
|
118
|
+
end
|
119
|
+
|
120
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
121
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
122
|
+
# The response body is written to the file in chunks in order to handle files which
|
123
|
+
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
124
|
+
# process can use.
|
125
|
+
#
|
126
|
+
# @see Configuration#temp_folder_path
|
127
|
+
def download_file(request)
|
128
|
+
tempfile = nil
|
129
|
+
encoding = nil
|
130
|
+
request.on_headers do |response|
|
131
|
+
content_disposition = response.headers['Content-Disposition']
|
132
|
+
if content_disposition && content_disposition =~ /filename=/i
|
133
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
134
|
+
prefix = sanitize_filename(filename)
|
135
|
+
else
|
136
|
+
prefix = 'download-'
|
137
|
+
end
|
138
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
139
|
+
encoding = response.body.encoding
|
140
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
141
|
+
@tempfile = tempfile
|
142
|
+
end
|
143
|
+
request.on_body do |chunk|
|
144
|
+
chunk.force_encoding(encoding)
|
145
|
+
tempfile.write(chunk)
|
146
|
+
end
|
147
|
+
request.on_complete do |response|
|
148
|
+
if tempfile
|
149
|
+
tempfile.close
|
150
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
151
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
152
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
153
|
+
"explicitly with `tempfile.delete`"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# {{moduleName}}::{{classname}}{{#description}}
|
2
|
+
|
3
|
+
{{.}}{{/description}}
|
4
|
+
|
5
|
+
All URIs are relative to *{{basePath}}*
|
6
|
+
|
7
|
+
| Method | HTTP request | Description |
|
8
|
+
| ------ | ------------ | ----------- |
|
9
|
+
{{#operations}}
|
10
|
+
{{#operation}}
|
11
|
+
| [**{{operationId}}**]({{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{path}} | {{summary}} |
|
12
|
+
{{/operation}}
|
13
|
+
{{/operations}}
|
14
|
+
|
15
|
+
{{#operations}}
|
16
|
+
{{#operation}}
|
17
|
+
|
18
|
+
## {{operationId}}
|
19
|
+
|
20
|
+
> {{#returnType}}{{#returnTypeIsPrimitive}}{{returnType}}{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}<{{{returnType}}}>{{/returnTypeIsPrimitive}} {{/returnType}}{{operationId}}{{#hasParams}}({{^vendorExtensions.x-group-parameters}}{{#requiredParams}}{{{paramName}}}{{^-last}}, {{/-last}}{{/requiredParams}}{{#optionalParams}}{{#-last}}{{#hasRequiredParams}}, {{/hasRequiredParams}}opts{{/-last}}{{/optionalParams}}{{/vendorExtensions.x-group-parameters}}{{#vendorExtensions.x-group-parameters}}opts{{/vendorExtensions.x-group-parameters}}){{/hasParams}}
|
21
|
+
|
22
|
+
{{{summary}}}{{#notes}}
|
23
|
+
|
24
|
+
{{{.}}}{{/notes}}
|
25
|
+
|
26
|
+
### Parameters
|
27
|
+
|
28
|
+
{{^allParams}}
|
29
|
+
This endpoint does not need any parameter.
|
30
|
+
{{/allParams}}
|
31
|
+
{{#allParams}}
|
32
|
+
{{#-first}}
|
33
|
+
| Name | Type | Description | Notes |
|
34
|
+
| ---- | ---- | ----------- | ----- |
|
35
|
+
{{/-first}}
|
36
|
+
| **{{paramName}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isFile}}**{{dataType}}**{{/isFile}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}} | {{description}} | {{^required}}[optional]{{/required}}{{#defaultValue}}[default to {{.}}]{{/defaultValue}} |
|
37
|
+
{{/allParams}}
|
38
|
+
|
39
|
+
### Return type
|
40
|
+
|
41
|
+
{{#returnType}}{{#returnTypeIsPrimitive}}**{{returnType}}**{{/returnTypeIsPrimitive}}{{^returnTypeIsPrimitive}}[**{{returnType}}**]({{returnBaseType}}.md){{/returnTypeIsPrimitive}}{{/returnType}}{{^returnType}}nil (empty response body){{/returnType}}
|
42
|
+
|
43
|
+
{{/operation}}
|
44
|
+
{{/operations}}
|
@@ -0,0 +1,84 @@
|
|
1
|
+
=begin
|
2
|
+
{{> api_info}}
|
3
|
+
=end
|
4
|
+
|
5
|
+
# Common files
|
6
|
+
require '{{gemName}}/api_client'
|
7
|
+
require '{{gemName}}/api_error'
|
8
|
+
require '{{gemName}}/version'
|
9
|
+
require '{{gemName}}/configuration'
|
10
|
+
|
11
|
+
# Models
|
12
|
+
{{#models}}
|
13
|
+
{{#model}}
|
14
|
+
require '{{gemName}}/{{modelPackage}}/{{classFilename}}'{{/model}}
|
15
|
+
{{/models}}
|
16
|
+
|
17
|
+
# APIs
|
18
|
+
{{#apiInfo}}
|
19
|
+
{{#apis}}
|
20
|
+
require '{{importPath}}'
|
21
|
+
{{/apis}}
|
22
|
+
{{/apiInfo}}
|
23
|
+
|
24
|
+
require 'ynab/overrides/transactions_api'
|
25
|
+
|
26
|
+
module {{moduleName}}
|
27
|
+
class API
|
28
|
+
def initialize(access_token, host = 'api.ynab.com', useHttps = true)
|
29
|
+
config = Configuration.default
|
30
|
+
config.access_token = access_token
|
31
|
+
config.scheme = useHttps ? 'https' : 'http'
|
32
|
+
config.host = host
|
33
|
+
config.base_path = '/v1'
|
34
|
+
|
35
|
+
@client = ApiClient.new(config)
|
36
|
+
end
|
37
|
+
|
38
|
+
def user
|
39
|
+
UserApi.new(@client)
|
40
|
+
end
|
41
|
+
|
42
|
+
def budgets
|
43
|
+
BudgetsApi.new(@client)
|
44
|
+
end
|
45
|
+
|
46
|
+
def accounts
|
47
|
+
AccountsApi.new(@client)
|
48
|
+
end
|
49
|
+
|
50
|
+
def categories
|
51
|
+
CategoriesApi.new(@client)
|
52
|
+
end
|
53
|
+
|
54
|
+
def months
|
55
|
+
MonthsApi.new(@client)
|
56
|
+
end
|
57
|
+
|
58
|
+
def payees
|
59
|
+
PayeesApi.new(@client)
|
60
|
+
end
|
61
|
+
|
62
|
+
def payee_locations
|
63
|
+
PayeeLocationsApi.new(@client)
|
64
|
+
end
|
65
|
+
|
66
|
+
def transactions
|
67
|
+
YNAB::Overrides::TransactionsApi.new(@client)
|
68
|
+
end
|
69
|
+
|
70
|
+
def scheduled_transactions
|
71
|
+
ScheduledTransactionsApi.new(@client)
|
72
|
+
end
|
73
|
+
|
74
|
+
def last_request
|
75
|
+
@client.last_request
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Support old interface: YnabApi::Client
|
81
|
+
module YnabApi
|
82
|
+
class Client < {{moduleName}}::API
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# {{moduleName}}::{{classname}}
|
2
|
+
|
3
|
+
## Properties
|
4
|
+
|
5
|
+
| Name | Type | Description | Notes |
|
6
|
+
| ---- | ---- | ----------- | ----- |
|
7
|
+
{{#vars}}
|
8
|
+
| **{{name}}** | {{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}[**{{dataType}}**]({{complexType}}.md){{/isPrimitiveType}} | {{description}} | {{^required}}[optional]{{/required}}{{#isReadOnly}}[readonly]{{/isReadOnly}}{{#defaultValue}}[default to {{.}}]{{/defaultValue}} |
|
9
|
+
{{/vars}}
|
data/ynab.gemspec
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
=begin
|
4
|
+
#YNAB API Endpoints
|
5
|
+
|
6
|
+
#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
|
7
|
+
|
8
|
+
The version of the OpenAPI document: 1.0.0
|
9
|
+
|
10
|
+
Generated by: https://openapi-generator.tech
|
11
|
+
OpenAPI Generator version: 6.6.0
|
12
|
+
|
13
|
+
=end
|
14
|
+
|
15
|
+
$:.push File.expand_path("../lib", __FILE__)
|
16
|
+
require "ynab/version"
|
17
|
+
|
18
|
+
Gem::Specification.new do |s|
|
19
|
+
s.name = "ynab"
|
20
|
+
s.version = YNAB::VERSION
|
21
|
+
s.platform = Gem::Platform::RUBY
|
22
|
+
s.authors = ["YNAB"]
|
23
|
+
s.email = ["api@ynab.com"]
|
24
|
+
s.homepage = "https://github.com/ynab/ynab-sdk-ruby"
|
25
|
+
s.summary = "YNAB API Endpoints Ruby Gem"
|
26
|
+
s.description = "Ruby gem wrapper for the YNAB API. Read the documentation at https://api.ynab.com"
|
27
|
+
s.license = "Apache-2.0"
|
28
|
+
s.required_ruby_version = ">= 2.7"
|
29
|
+
|
30
|
+
s.add_runtime_dependency 'typhoeus', '~> 1.0', '>= 1.0.1'
|
31
|
+
|
32
|
+
s.add_development_dependency 'rspec', '~> 3.6', '>= 3.6.0'
|
33
|
+
|
34
|
+
s.files = `find *`.split("\n").uniq.sort.select { |f| !f.empty? }
|
35
|
+
s.test_files = `find spec/*`.split("\n")
|
36
|
+
s.executables = []
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
end
|