mx-platform-ruby 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +6 -2
- data/Gemfile.lock +84 -0
- data/README.md +236 -33
- data/Rakefile +8 -9
- data/lib/mx-platform-ruby.rb +126 -35
- data/lib/mx-platform-ruby/api/mx_platform_api.rb +4917 -0
- data/lib/mx-platform-ruby/api_client.rb +395 -0
- data/lib/mx-platform-ruby/api_error.rb +57 -0
- data/lib/mx-platform-ruby/configuration.rb +276 -0
- data/lib/mx-platform-ruby/models/account.rb +569 -0
- data/lib/mx-platform-ruby/models/account_number.rb +281 -0
- data/lib/mx-platform-ruby/models/account_numbers_response_body.rb +229 -0
- data/lib/mx-platform-ruby/models/account_owner.rb +317 -0
- data/lib/mx-platform-ruby/models/account_owners_response_body.rb +229 -0
- data/lib/mx-platform-ruby/models/account_response_body.rb +218 -0
- data/lib/mx-platform-ruby/models/account_update_request.rb +218 -0
- data/lib/mx-platform-ruby/models/account_update_request_body.rb +218 -0
- data/lib/mx-platform-ruby/models/accounts_response_body.rb +229 -0
- data/lib/mx-platform-ruby/models/categories_response_body.rb +229 -0
- data/lib/mx-platform-ruby/models/category.rb +281 -0
- data/lib/mx-platform-ruby/models/category_create_request.rb +241 -0
- data/lib/mx-platform-ruby/models/category_create_request_body.rb +218 -0
- data/lib/mx-platform-ruby/models/category_response_body.rb +218 -0
- data/lib/mx-platform-ruby/models/category_update_request.rb +227 -0
- data/lib/mx-platform-ruby/models/category_update_request_body.rb +218 -0
- data/lib/mx-platform-ruby/models/challenge.rb +276 -0
- data/lib/mx-platform-ruby/models/challenge_image_options.rb +236 -0
- data/lib/mx-platform-ruby/models/challenge_options.rb +227 -0
- data/lib/mx-platform-ruby/models/challenges_response_body.rb +229 -0
- data/lib/mx-platform-ruby/models/connect_widget.rb +227 -0
- data/lib/mx-platform-ruby/models/connect_widget_request.rb +308 -0
- data/lib/mx-platform-ruby/models/connect_widget_request_body.rb +218 -0
- data/lib/mx-platform-ruby/models/connect_widget_response_body.rb +218 -0
- data/lib/mx-platform-ruby/models/credential.rb +254 -0
- data/lib/mx-platform-ruby/models/credential_request.rb +227 -0
- data/lib/mx-platform-ruby/models/credentials_response_body.rb +229 -0
- data/lib/mx-platform-ruby/models/enhance_transaction.rb +353 -0
- data/lib/mx-platform-ruby/models/enhance_transactions_request.rb +264 -0
- data/lib/mx-platform-ruby/models/enhance_transactions_request_body.rb +220 -0
- data/lib/mx-platform-ruby/models/enhance_transactions_response_body.rb +220 -0
- data/lib/mx-platform-ruby/models/holding.rb +371 -0
- data/lib/mx-platform-ruby/models/holding_response_body.rb +218 -0
- data/lib/mx-platform-ruby/models/holdings_response_body.rb +229 -0
- data/lib/mx-platform-ruby/models/inline_response200.rb +218 -0
- data/lib/mx-platform-ruby/models/institution.rb +299 -0
- data/lib/mx-platform-ruby/models/institution_response_body.rb +218 -0
- data/lib/mx-platform-ruby/models/institutions_response_body.rb +229 -0
- data/lib/mx-platform-ruby/models/member.rb +317 -0
- data/lib/mx-platform-ruby/models/member_create_request.rb +284 -0
- data/lib/mx-platform-ruby/models/member_create_request_body.rb +236 -0
- data/lib/mx-platform-ruby/models/member_response_body.rb +218 -0
- data/lib/mx-platform-ruby/models/member_resume_request.rb +220 -0
- data/lib/mx-platform-ruby/models/member_resume_request_body.rb +218 -0
- data/lib/mx-platform-ruby/models/member_status.rb +292 -0
- data/lib/mx-platform-ruby/models/member_status_response_body.rb +218 -0
- data/lib/mx-platform-ruby/models/member_update_request.rb +256 -0
- data/lib/mx-platform-ruby/models/member_update_request_body.rb +218 -0
- data/lib/mx-platform-ruby/models/members_response_body.rb +229 -0
- data/lib/mx-platform-ruby/models/merchant.rb +263 -0
- data/lib/mx-platform-ruby/models/merchant_response_body.rb +218 -0
- data/lib/mx-platform-ruby/models/merchants_response_body.rb +229 -0
- data/lib/mx-platform-ruby/models/o_auth_window.rb +227 -0
- data/lib/mx-platform-ruby/models/o_auth_window_response_body.rb +218 -0
- data/lib/mx-platform-ruby/models/pagination.rb +245 -0
- data/lib/mx-platform-ruby/models/statement.rb +281 -0
- data/lib/mx-platform-ruby/models/statement_response_body.rb +218 -0
- data/lib/mx-platform-ruby/models/statements_response_body.rb +229 -0
- data/lib/mx-platform-ruby/models/tag.rb +236 -0
- data/lib/mx-platform-ruby/models/tag_create_request.rb +223 -0
- data/lib/mx-platform-ruby/models/tag_create_request_body.rb +218 -0
- data/lib/mx-platform-ruby/models/tag_response_body.rb +218 -0
- data/lib/mx-platform-ruby/models/tag_update_request.rb +223 -0
- data/lib/mx-platform-ruby/models/tag_update_request_body.rb +218 -0
- data/lib/mx-platform-ruby/models/tagging.rb +254 -0
- data/lib/mx-platform-ruby/models/tagging_create_request.rb +237 -0
- data/lib/mx-platform-ruby/models/tagging_create_request_body.rb +218 -0
- data/lib/mx-platform-ruby/models/tagging_response_body.rb +218 -0
- data/lib/mx-platform-ruby/models/tagging_update_request.rb +223 -0
- data/lib/mx-platform-ruby/models/tagging_update_request_body.rb +218 -0
- data/lib/mx-platform-ruby/models/taggings_response_body.rb +229 -0
- data/lib/mx-platform-ruby/models/tags_response_body.rb +229 -0
- data/lib/mx-platform-ruby/models/transaction.rb +533 -0
- data/lib/mx-platform-ruby/models/transaction_response_body.rb +218 -0
- data/lib/mx-platform-ruby/models/transaction_rule.rb +272 -0
- data/lib/mx-platform-ruby/models/transaction_rule_create_request.rb +246 -0
- data/lib/mx-platform-ruby/models/transaction_rule_create_request_body.rb +218 -0
- data/lib/mx-platform-ruby/models/transaction_rule_response_body.rb +218 -0
- data/lib/mx-platform-ruby/models/transaction_rule_update_request.rb +236 -0
- data/lib/mx-platform-ruby/models/transaction_rule_update_request_body.rb +218 -0
- data/lib/mx-platform-ruby/models/transaction_rules_response_body.rb +229 -0
- data/lib/mx-platform-ruby/models/transaction_update_request.rb +223 -0
- data/lib/mx-platform-ruby/models/transaction_update_request_body.rb +218 -0
- data/lib/mx-platform-ruby/models/transactions_response_body.rb +229 -0
- data/lib/mx-platform-ruby/models/user.rb +254 -0
- data/lib/mx-platform-ruby/models/user_create_request.rb +245 -0
- data/lib/mx-platform-ruby/models/user_create_request_body.rb +218 -0
- data/lib/mx-platform-ruby/models/user_response_body.rb +218 -0
- data/lib/mx-platform-ruby/models/user_update_request.rb +245 -0
- data/lib/mx-platform-ruby/models/user_update_request_body.rb +218 -0
- data/lib/mx-platform-ruby/models/users_response_body.rb +229 -0
- data/lib/mx-platform-ruby/models/widget.rb +236 -0
- data/lib/mx-platform-ruby/models/widget_request.rb +331 -0
- data/lib/mx-platform-ruby/models/widget_request_body.rb +218 -0
- data/lib/mx-platform-ruby/models/widget_response_body.rb +218 -0
- data/lib/mx-platform-ruby/version.rb +13 -3
- data/mx-platform-ruby.gemspec +34 -27
- data/openapi/mx_platform_ruby.yml +11 -0
- data/spec/api/mx_platform_api_spec.rb +979 -0
- data/spec/api_client_spec.rb +188 -0
- data/spec/configuration_spec.rb +42 -0
- data/spec/models/account_number_spec.rb +76 -0
- data/spec/models/account_numbers_response_body_spec.rb +40 -0
- data/spec/models/account_owner_spec.rb +100 -0
- data/spec/models/account_owners_response_body_spec.rb +40 -0
- data/spec/models/account_response_body_spec.rb +34 -0
- data/spec/models/account_spec.rb +268 -0
- data/spec/models/account_update_request_body_spec.rb +34 -0
- data/spec/models/account_update_request_spec.rb +34 -0
- data/spec/models/accounts_response_body_spec.rb +40 -0
- data/spec/models/categories_response_body_spec.rb +40 -0
- data/spec/models/category_create_request_body_spec.rb +34 -0
- data/spec/models/category_create_request_spec.rb +46 -0
- data/spec/models/category_response_body_spec.rb +34 -0
- data/spec/models/category_spec.rb +76 -0
- data/spec/models/category_update_request_body_spec.rb +34 -0
- data/spec/models/category_update_request_spec.rb +40 -0
- data/spec/models/challenge_image_options_spec.rb +46 -0
- data/spec/models/challenge_options_spec.rb +40 -0
- data/spec/models/challenge_spec.rb +70 -0
- data/spec/models/challenges_response_body_spec.rb +40 -0
- data/spec/models/connect_widget_request_body_spec.rb +34 -0
- data/spec/models/connect_widget_request_spec.rb +94 -0
- data/spec/models/connect_widget_response_body_spec.rb +34 -0
- data/spec/models/connect_widget_spec.rb +40 -0
- data/spec/models/credential_request_spec.rb +40 -0
- data/spec/models/credential_spec.rb +58 -0
- data/spec/models/credentials_response_body_spec.rb +40 -0
- data/spec/models/enhance_transaction_spec.rb +124 -0
- data/spec/models/enhance_transactions_request_body_spec.rb +34 -0
- data/spec/models/enhance_transactions_request_spec.rb +58 -0
- data/spec/models/enhance_transactions_response_body_spec.rb +34 -0
- data/spec/models/holding_response_body_spec.rb +34 -0
- data/spec/models/holding_spec.rb +136 -0
- data/spec/models/holdings_response_body_spec.rb +40 -0
- data/spec/models/inline_response200_spec.rb +34 -0
- data/spec/models/institution_response_body_spec.rb +34 -0
- data/spec/models/institution_spec.rb +88 -0
- data/spec/models/institutions_response_body_spec.rb +40 -0
- data/spec/models/member_create_request_body_spec.rb +46 -0
- data/spec/models/member_create_request_spec.rb +70 -0
- data/spec/models/member_response_body_spec.rb +34 -0
- data/spec/models/member_resume_request_body_spec.rb +34 -0
- data/spec/models/member_resume_request_spec.rb +34 -0
- data/spec/models/member_spec.rb +100 -0
- data/spec/models/member_status_response_body_spec.rb +34 -0
- data/spec/models/member_status_spec.rb +82 -0
- data/spec/models/member_update_request_body_spec.rb +34 -0
- data/spec/models/member_update_request_spec.rb +58 -0
- data/spec/models/members_response_body_spec.rb +40 -0
- data/spec/models/merchant_response_body_spec.rb +34 -0
- data/spec/models/merchant_spec.rb +64 -0
- data/spec/models/merchants_response_body_spec.rb +40 -0
- data/spec/models/o_auth_window_response_body_spec.rb +34 -0
- data/spec/models/o_auth_window_spec.rb +40 -0
- data/spec/models/pagination_spec.rb +52 -0
- data/spec/models/statement_response_body_spec.rb +34 -0
- data/spec/models/statement_spec.rb +76 -0
- data/spec/models/statements_response_body_spec.rb +40 -0
- data/spec/models/tag_create_request_body_spec.rb +34 -0
- data/spec/models/tag_create_request_spec.rb +34 -0
- data/spec/models/tag_response_body_spec.rb +34 -0
- data/spec/models/tag_spec.rb +46 -0
- data/spec/models/tag_update_request_body_spec.rb +34 -0
- data/spec/models/tag_update_request_spec.rb +34 -0
- data/spec/models/tagging_create_request_body_spec.rb +34 -0
- data/spec/models/tagging_create_request_spec.rb +40 -0
- data/spec/models/tagging_response_body_spec.rb +34 -0
- data/spec/models/tagging_spec.rb +58 -0
- data/spec/models/tagging_update_request_body_spec.rb +34 -0
- data/spec/models/tagging_update_request_spec.rb +34 -0
- data/spec/models/taggings_response_body_spec.rb +40 -0
- data/spec/models/tags_response_body_spec.rb +40 -0
- data/spec/models/transaction_response_body_spec.rb +34 -0
- data/spec/models/transaction_rule_create_request_body_spec.rb +34 -0
- data/spec/models/transaction_rule_create_request_spec.rb +46 -0
- data/spec/models/transaction_rule_response_body_spec.rb +34 -0
- data/spec/models/transaction_rule_spec.rb +70 -0
- data/spec/models/transaction_rule_update_request_body_spec.rb +34 -0
- data/spec/models/transaction_rule_update_request_spec.rb +46 -0
- data/spec/models/transaction_rules_response_body_spec.rb +40 -0
- data/spec/models/transaction_spec.rb +244 -0
- data/spec/models/transaction_update_request_body_spec.rb +34 -0
- data/spec/models/transaction_update_request_spec.rb +34 -0
- data/spec/models/transactions_response_body_spec.rb +40 -0
- data/spec/models/user_create_request_body_spec.rb +34 -0
- data/spec/models/user_create_request_spec.rb +52 -0
- data/spec/models/user_response_body_spec.rb +34 -0
- data/spec/models/user_spec.rb +58 -0
- data/spec/models/user_update_request_body_spec.rb +34 -0
- data/spec/models/user_update_request_spec.rb +52 -0
- data/spec/models/users_response_body_spec.rb +40 -0
- data/spec/models/widget_request_body_spec.rb +34 -0
- data/spec/models/widget_request_spec.rb +106 -0
- data/spec/models/widget_response_body_spec.rb +34 -0
- data/spec/models/widget_spec.rb +46 -0
- data/spec/spec_helper.rb +100 -13
- metadata +317 -144
- data/.github/workflows/test.yml +0 -20
- data/.gitignore +0 -13
- data/.rubocop.yml +0 -44
- data/lib/mx-platform-ruby/account.rb +0 -107
- data/lib/mx-platform-ruby/account_number.rb +0 -57
- data/lib/mx-platform-ruby/account_owner.rb +0 -42
- data/lib/mx-platform-ruby/category.rb +0 -127
- data/lib/mx-platform-ruby/challenge.rb +0 -37
- data/lib/mx-platform-ruby/client.rb +0 -59
- data/lib/mx-platform-ruby/connect_widget.rb +0 -43
- data/lib/mx-platform-ruby/credential.rb +0 -54
- data/lib/mx-platform-ruby/enhanced_transaction.rb +0 -44
- data/lib/mx-platform-ruby/error.rb +0 -6
- data/lib/mx-platform-ruby/holding.rb +0 -87
- data/lib/mx-platform-ruby/institution.rb +0 -78
- data/lib/mx-platform-ruby/member.rb +0 -242
- data/lib/mx-platform-ruby/member_status.rb +0 -35
- data/lib/mx-platform-ruby/merchant.rb +0 -52
- data/lib/mx-platform-ruby/oauth_window.rb +0 -32
- data/lib/mx-platform-ruby/pageable.rb +0 -29
- data/lib/mx-platform-ruby/statement.rb +0 -70
- data/lib/mx-platform-ruby/tag.rb +0 -104
- data/lib/mx-platform-ruby/tagging.rb +0 -107
- data/lib/mx-platform-ruby/transaction.rb +0 -162
- data/lib/mx-platform-ruby/transaction_rule.rb +0 -112
- data/lib/mx-platform-ruby/user.rb +0 -112
- data/lib/mx-platform-ruby/widget.rb +0 -49
- data/spec/lib/mx-platform-ruby/account_number_spec.rb +0 -100
- data/spec/lib/mx-platform-ruby/account_owner_spec.rb +0 -71
- data/spec/lib/mx-platform-ruby/account_spec.rb +0 -267
- data/spec/lib/mx-platform-ruby/category_spec.rb +0 -244
- data/spec/lib/mx-platform-ruby/challenge_spec.rb +0 -72
- data/spec/lib/mx-platform-ruby/client_spec.rb +0 -101
- data/spec/lib/mx-platform-ruby/connect_widget_spec.rb +0 -66
- data/spec/lib/mx-platform-ruby/credential_spec.rb +0 -90
- data/spec/lib/mx-platform-ruby/enhanced_transaction_spec.rb +0 -89
- data/spec/lib/mx-platform-ruby/holding_spec.rb +0 -178
- data/spec/lib/mx-platform-ruby/institution_spec.rb +0 -141
- data/spec/lib/mx-platform-ruby/member_spec.rb +0 -557
- data/spec/lib/mx-platform-ruby/member_status_spec.rb +0 -76
- data/spec/lib/mx-platform-ruby/merchant_spec.rb +0 -89
- data/spec/lib/mx-platform-ruby/oauth_window_spec.rb +0 -47
- data/spec/lib/mx-platform-ruby/pageable_spec.rb +0 -75
- data/spec/lib/mx-platform-ruby/statement_spec.rb +0 -130
- data/spec/lib/mx-platform-ruby/tag_spec.rb +0 -179
- data/spec/lib/mx-platform-ruby/tagging_spec.rb +0 -191
- data/spec/lib/mx-platform-ruby/transaction_rule_spec.rb +0 -207
- data/spec/lib/mx-platform-ruby/transaction_spec.rb +0 -449
- data/spec/lib/mx-platform-ruby/user_spec.rb +0 -196
- data/spec/lib/mx-platform-ruby/widget_spec.rb +0 -76
- data/spec/lib/mx-platform-ruby_spec.rb +0 -15
- data/spec/sample.pdf +0 -0
@@ -0,0 +1,395 @@
|
|
1
|
+
=begin
|
2
|
+
#MX Platform API
|
3
|
+
|
4
|
+
#The MX Platform API is a powerful, fully-featured API designed to make aggregating and enhancing financial data easy and reliable. It can seamlessly connect your app or website to tens of thousands of financial institutions.
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 0.1.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 5.2.0
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
require 'date'
|
14
|
+
require 'json'
|
15
|
+
require 'logger'
|
16
|
+
require 'tempfile'
|
17
|
+
require 'time'
|
18
|
+
require 'faraday'
|
19
|
+
|
20
|
+
module MxPlatformRuby
|
21
|
+
class ApiClient
|
22
|
+
# The Configuration object holding settings to be used in the API client.
|
23
|
+
attr_accessor :config
|
24
|
+
|
25
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
26
|
+
#
|
27
|
+
# @return [Hash]
|
28
|
+
attr_accessor :default_headers
|
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 = "OpenAPI-Generator/#{VERSION}/ruby"
|
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
|
+
# Call an API with given options.
|
46
|
+
#
|
47
|
+
# @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
|
48
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
49
|
+
def call_api(http_method, path, opts = {})
|
50
|
+
ssl_options = {
|
51
|
+
:ca_file => @config.ssl_ca_file,
|
52
|
+
:verify => @config.ssl_verify,
|
53
|
+
:verify_mode => @config.ssl_verify_mode,
|
54
|
+
:client_cert => @config.ssl_client_cert,
|
55
|
+
:client_key => @config.ssl_client_key
|
56
|
+
}
|
57
|
+
|
58
|
+
connection = Faraday.new(:url => config.base_url, :ssl => ssl_options) do |conn|
|
59
|
+
conn.basic_auth(config.username, config.password)
|
60
|
+
if opts[:header_params]["Content-Type"] == "multipart/form-data"
|
61
|
+
conn.request :multipart
|
62
|
+
conn.request :url_encoded
|
63
|
+
end
|
64
|
+
conn.adapter(Faraday.default_adapter)
|
65
|
+
end
|
66
|
+
|
67
|
+
begin
|
68
|
+
response = connection.public_send(http_method.to_sym.downcase) do |req|
|
69
|
+
build_request(http_method, path, req, opts)
|
70
|
+
end
|
71
|
+
|
72
|
+
if @config.debugging
|
73
|
+
@config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
|
74
|
+
end
|
75
|
+
|
76
|
+
unless response.success?
|
77
|
+
if response.status == 0
|
78
|
+
# Errors from libcurl will be made visible here
|
79
|
+
fail ApiError.new(:code => 0,
|
80
|
+
:message => response.return_message)
|
81
|
+
else
|
82
|
+
fail ApiError.new(:code => response.status,
|
83
|
+
:response_headers => response.headers,
|
84
|
+
:response_body => response.body),
|
85
|
+
response.reason_phrase
|
86
|
+
end
|
87
|
+
end
|
88
|
+
rescue Faraday::TimeoutError
|
89
|
+
fail ApiError.new('Connection timed out')
|
90
|
+
end
|
91
|
+
|
92
|
+
if opts[:return_type]
|
93
|
+
data = deserialize(response, opts[:return_type])
|
94
|
+
else
|
95
|
+
data = nil
|
96
|
+
end
|
97
|
+
return data, response.status, response.headers
|
98
|
+
end
|
99
|
+
|
100
|
+
# Builds the HTTP request
|
101
|
+
#
|
102
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
103
|
+
# @param [String] path URL path (e.g. /account/new)
|
104
|
+
# @option opts [Hash] :header_params Header parameters
|
105
|
+
# @option opts [Hash] :query_params Query parameters
|
106
|
+
# @option opts [Hash] :form_params Query parameters
|
107
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
108
|
+
# @return [Typhoeus::Request] A Typhoeus Request
|
109
|
+
def build_request(http_method, path, request, opts = {})
|
110
|
+
url = build_request_url(path, opts)
|
111
|
+
http_method = http_method.to_sym.downcase
|
112
|
+
|
113
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
114
|
+
query_params = opts[:query_params] || {}
|
115
|
+
form_params = opts[:form_params] || {}
|
116
|
+
|
117
|
+
update_params_for_auth! header_params, query_params, opts[:auth_names]
|
118
|
+
|
119
|
+
req_opts = {
|
120
|
+
:method => http_method,
|
121
|
+
:headers => header_params,
|
122
|
+
:params => query_params,
|
123
|
+
:params_encoding => @config.params_encoding,
|
124
|
+
:timeout => @config.timeout,
|
125
|
+
:verbose => @config.debugging
|
126
|
+
}
|
127
|
+
|
128
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
129
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
130
|
+
req_opts.update :body => req_body
|
131
|
+
if @config.debugging
|
132
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
133
|
+
end
|
134
|
+
end
|
135
|
+
request.headers = header_params
|
136
|
+
request.body = req_body
|
137
|
+
request.url url
|
138
|
+
request.params = query_params
|
139
|
+
download_file(request) if opts[:return_type] == 'File'
|
140
|
+
request
|
141
|
+
end
|
142
|
+
|
143
|
+
# Builds the HTTP request body
|
144
|
+
#
|
145
|
+
# @param [Hash] header_params Header parameters
|
146
|
+
# @param [Hash] form_params Query parameters
|
147
|
+
# @param [Object] body HTTP body (JSON/XML)
|
148
|
+
# @return [String] HTTP body data in the form of string
|
149
|
+
def build_request_body(header_params, form_params, body)
|
150
|
+
# http form
|
151
|
+
if header_params['Content-Type'] == 'application/x-www-form-urlencoded'
|
152
|
+
data = URI.encode_www_form(form_params)
|
153
|
+
elsif header_params['Content-Type'] == 'multipart/form-data'
|
154
|
+
data = {}
|
155
|
+
form_params.each do |key, value|
|
156
|
+
case value
|
157
|
+
when ::File, ::Tempfile
|
158
|
+
# TODO hardcode to application/octet-stream, need better way to detect content type
|
159
|
+
data[key] = Faraday::UploadIO.new(value.path, 'application/octet-stream', value.path)
|
160
|
+
when ::Array, nil
|
161
|
+
# let Faraday handle Array and nil parameters
|
162
|
+
data[key] = value
|
163
|
+
else
|
164
|
+
data[key] = value.to_s
|
165
|
+
end
|
166
|
+
end
|
167
|
+
elsif body
|
168
|
+
data = body.is_a?(String) ? body : body.to_json
|
169
|
+
else
|
170
|
+
data = nil
|
171
|
+
end
|
172
|
+
data
|
173
|
+
end
|
174
|
+
|
175
|
+
def download_file(request)
|
176
|
+
@stream = []
|
177
|
+
|
178
|
+
# handle streaming Responses
|
179
|
+
request.options.on_data = Proc.new do |chunk, overall_received_bytes|
|
180
|
+
@stream << chunk
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
# Check if the given MIME is a JSON MIME.
|
185
|
+
# JSON MIME examples:
|
186
|
+
# application/json
|
187
|
+
# application/json; charset=UTF8
|
188
|
+
# APPLICATION/JSON
|
189
|
+
# */*
|
190
|
+
# @param [String] mime MIME
|
191
|
+
# @return [Boolean] True if the MIME is application/json
|
192
|
+
def json_mime?(mime)
|
193
|
+
(mime == '*/*') || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
194
|
+
end
|
195
|
+
|
196
|
+
# Deserialize the response to the given return type.
|
197
|
+
#
|
198
|
+
# @param [Response] response HTTP response
|
199
|
+
# @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
|
200
|
+
def deserialize(response, return_type)
|
201
|
+
body = response.body
|
202
|
+
|
203
|
+
# handle file downloading - return the File instance processed in request callbacks
|
204
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
205
|
+
if return_type == 'File'
|
206
|
+
content_disposition = response.headers['Content-Disposition']
|
207
|
+
if content_disposition && content_disposition =~ /filename=/i
|
208
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
209
|
+
prefix = sanitize_filename(filename)
|
210
|
+
else
|
211
|
+
prefix = 'download-'
|
212
|
+
end
|
213
|
+
prefix = prefix + '-' unless prefix.end_with?('-')
|
214
|
+
encoding = body.encoding
|
215
|
+
@tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
216
|
+
@tempfile.write(@stream.join.force_encoding(encoding))
|
217
|
+
@tempfile.close
|
218
|
+
@config.logger.info "Temp file written to #{@tempfile.path}, please copy the file to a proper folder "\
|
219
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
220
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
221
|
+
"explicitly with `tempfile.delete`"
|
222
|
+
return @tempfile
|
223
|
+
end
|
224
|
+
|
225
|
+
return nil if body.nil? || body.empty?
|
226
|
+
|
227
|
+
# return response body directly for String return type
|
228
|
+
return body if return_type == 'String'
|
229
|
+
|
230
|
+
# ensuring a default content type
|
231
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
232
|
+
|
233
|
+
fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
234
|
+
|
235
|
+
begin
|
236
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
237
|
+
rescue JSON::ParserError => e
|
238
|
+
if %w(String Date Time).include?(return_type)
|
239
|
+
data = body
|
240
|
+
else
|
241
|
+
raise e
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
convert_to_type data, return_type
|
246
|
+
end
|
247
|
+
|
248
|
+
# Convert data to the given return type.
|
249
|
+
# @param [Object] data Data to be converted
|
250
|
+
# @param [String] return_type Return type
|
251
|
+
# @return [Mixed] Data in a particular type
|
252
|
+
def convert_to_type(data, return_type)
|
253
|
+
return nil if data.nil?
|
254
|
+
case return_type
|
255
|
+
when 'String'
|
256
|
+
data.to_s
|
257
|
+
when 'Integer'
|
258
|
+
data.to_i
|
259
|
+
when 'Float'
|
260
|
+
data.to_f
|
261
|
+
when 'Boolean'
|
262
|
+
data == true
|
263
|
+
when 'Time'
|
264
|
+
# parse date time (expecting ISO 8601 format)
|
265
|
+
Time.parse data
|
266
|
+
when 'Date'
|
267
|
+
# parse date time (expecting ISO 8601 format)
|
268
|
+
Date.parse data
|
269
|
+
when 'Object'
|
270
|
+
# generic object (usually a Hash), return directly
|
271
|
+
data
|
272
|
+
when /\AArray<(.+)>\z/
|
273
|
+
# e.g. Array<Pet>
|
274
|
+
sub_type = $1
|
275
|
+
data.map { |item| convert_to_type(item, sub_type) }
|
276
|
+
when /\AHash\<String, (.+)\>\z/
|
277
|
+
# e.g. Hash<String, Integer>
|
278
|
+
sub_type = $1
|
279
|
+
{}.tap do |hash|
|
280
|
+
data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
|
281
|
+
end
|
282
|
+
else
|
283
|
+
# models (e.g. Pet) or oneOf
|
284
|
+
klass = MxPlatformRuby.const_get(return_type)
|
285
|
+
klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
|
286
|
+
end
|
287
|
+
end
|
288
|
+
|
289
|
+
# Sanitize filename by removing path.
|
290
|
+
# e.g. ../../sun.gif becomes sun.gif
|
291
|
+
#
|
292
|
+
# @param [String] filename the filename to be sanitized
|
293
|
+
# @return [String] the sanitized filename
|
294
|
+
def sanitize_filename(filename)
|
295
|
+
filename.gsub(/.*[\/\\]/, '')
|
296
|
+
end
|
297
|
+
|
298
|
+
def build_request_url(path, opts = {})
|
299
|
+
# Add leading and trailing slashes to path
|
300
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
301
|
+
@config.base_url(opts[:operation]) + path
|
302
|
+
end
|
303
|
+
|
304
|
+
# Update hearder and query params based on authentication settings.
|
305
|
+
#
|
306
|
+
# @param [Hash] header_params Header parameters
|
307
|
+
# @param [Hash] query_params Query parameters
|
308
|
+
# @param [String] auth_names Authentication scheme name
|
309
|
+
def update_params_for_auth!(header_params, query_params, auth_names)
|
310
|
+
Array(auth_names).each do |auth_name|
|
311
|
+
auth_setting = @config.auth_settings[auth_name]
|
312
|
+
next unless auth_setting
|
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 fail ArgumentError, 'Authentication token must be in `query` or `header`'
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
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
|
328
|
+
|
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?
|
334
|
+
# use JSON when present, otherwise use all of the provided
|
335
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
336
|
+
json_accept || accepts.join(',')
|
337
|
+
end
|
338
|
+
|
339
|
+
# Return Content-Type header based on an array of content types provided.
|
340
|
+
# @param [Array] content_types array for Content-Type
|
341
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
342
|
+
def select_header_content_type(content_types)
|
343
|
+
# use application/json by default
|
344
|
+
return 'application/json' if content_types.nil? || content_types.empty?
|
345
|
+
# use JSON when present, otherwise use the first one
|
346
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
347
|
+
json_content_type || content_types.first
|
348
|
+
end
|
349
|
+
|
350
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
351
|
+
# @param [Object] model object to be converted into JSON string
|
352
|
+
# @return [String] JSON string representation of the object
|
353
|
+
def object_to_http_body(model)
|
354
|
+
return model if model.nil? || model.is_a?(String)
|
355
|
+
local_body = nil
|
356
|
+
if model.is_a?(Array)
|
357
|
+
local_body = model.map { |m| object_to_hash(m) }
|
358
|
+
else
|
359
|
+
local_body = object_to_hash(model)
|
360
|
+
end
|
361
|
+
local_body.to_json
|
362
|
+
end
|
363
|
+
|
364
|
+
# Convert object(non-array) to hash.
|
365
|
+
# @param [Object] obj object to be converted into JSON string
|
366
|
+
# @return [String] JSON string representation of the object
|
367
|
+
def object_to_hash(obj)
|
368
|
+
if obj.respond_to?(:to_hash)
|
369
|
+
obj.to_hash
|
370
|
+
else
|
371
|
+
obj
|
372
|
+
end
|
373
|
+
end
|
374
|
+
|
375
|
+
# Build parameter value according to the given collection format.
|
376
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
377
|
+
def build_collection_param(param, collection_format)
|
378
|
+
case collection_format
|
379
|
+
when :csv
|
380
|
+
param.join(',')
|
381
|
+
when :ssv
|
382
|
+
param.join(' ')
|
383
|
+
when :tsv
|
384
|
+
param.join("\t")
|
385
|
+
when :pipes
|
386
|
+
param.join('|')
|
387
|
+
when :multi
|
388
|
+
# return the array directly as typhoeus will handle it as expected
|
389
|
+
param
|
390
|
+
else
|
391
|
+
fail "unknown collection format: #{collection_format.inspect}"
|
392
|
+
end
|
393
|
+
end
|
394
|
+
end
|
395
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
=begin
|
2
|
+
#MX Platform API
|
3
|
+
|
4
|
+
#The MX Platform API is a powerful, fully-featured API designed to make aggregating and enhancing financial data easy and reliable. It can seamlessly connect your app or website to tens of thousands of financial institutions.
|
5
|
+
|
6
|
+
The version of the OpenAPI document: 0.1.0
|
7
|
+
|
8
|
+
Generated by: https://openapi-generator.tech
|
9
|
+
OpenAPI Generator version: 5.2.0
|
10
|
+
|
11
|
+
=end
|
12
|
+
|
13
|
+
module MxPlatformRuby
|
14
|
+
class ApiError < StandardError
|
15
|
+
attr_reader :code, :response_headers, :response_body
|
16
|
+
|
17
|
+
# Usage examples:
|
18
|
+
# ApiError.new
|
19
|
+
# ApiError.new("message")
|
20
|
+
# ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
|
21
|
+
# ApiError.new(:code => 404, :message => "Not Found")
|
22
|
+
def initialize(arg = nil)
|
23
|
+
if arg.is_a? Hash
|
24
|
+
if arg.key?(:message) || arg.key?('message')
|
25
|
+
super(arg[:message] || arg['message'])
|
26
|
+
else
|
27
|
+
super arg
|
28
|
+
end
|
29
|
+
|
30
|
+
arg.each do |k, v|
|
31
|
+
instance_variable_set "@#{k}", v
|
32
|
+
end
|
33
|
+
else
|
34
|
+
super arg
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Override to_s to display a friendly error message
|
39
|
+
def to_s
|
40
|
+
message
|
41
|
+
end
|
42
|
+
|
43
|
+
def message
|
44
|
+
if @message.nil?
|
45
|
+
msg = "Error message: the server returns an error"
|
46
|
+
else
|
47
|
+
msg = @message
|
48
|
+
end
|
49
|
+
|
50
|
+
msg += "\nHTTP status code: #{code}" if code
|
51
|
+
msg += "\nResponse headers: #{response_headers}" if response_headers
|
52
|
+
msg += "\nResponse body: #{response_body}" if response_body
|
53
|
+
|
54
|
+
msg
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|