budgea_client 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +12 -0
  3. data/Gemfile.lock +89 -0
  4. data/README.md +619 -0
  5. data/Rakefile +13 -0
  6. data/budgea_client.gemspec +35 -0
  7. data/docs/Access.md +12 -0
  8. data/docs/Account.md +25 -0
  9. data/docs/AccountLog.md +15 -0
  10. data/docs/AccountType.md +15 -0
  11. data/docs/AdministrationApi.md +944 -0
  12. data/docs/Alert.md +15 -0
  13. data/docs/AuthenticationApi.md +398 -0
  14. data/docs/Bank.md +18 -0
  15. data/docs/BankCategory.md +9 -0
  16. data/docs/BanksApi.md +6558 -0
  17. data/docs/Category.md +17 -0
  18. data/docs/Client.md +18 -0
  19. data/docs/Connection.md +16 -0
  20. data/docs/ConnectionContact.md +17 -0
  21. data/docs/ConnectionLog.md +21 -0
  22. data/docs/ConnectionsApi.md +934 -0
  23. data/docs/ConnectorLogo.md +11 -0
  24. data/docs/Currency.md +10 -0
  25. data/docs/Device.md +14 -0
  26. data/docs/Document.md +29 -0
  27. data/docs/DocumentType.md +10 -0
  28. data/docs/DocumentsApi.md +5228 -0
  29. data/docs/Field.md +15 -0
  30. data/docs/File.md +11 -0
  31. data/docs/Group.md +15 -0
  32. data/docs/HashTable.md +11 -0
  33. data/docs/InlineResponse200.md +8 -0
  34. data/docs/InlineResponse2001.md +9 -0
  35. data/docs/InlineResponse20010.md +8 -0
  36. data/docs/InlineResponse20011.md +8 -0
  37. data/docs/InlineResponse20012.md +8 -0
  38. data/docs/InlineResponse20013.md +8 -0
  39. data/docs/InlineResponse20014.md +8 -0
  40. data/docs/InlineResponse20015.md +8 -0
  41. data/docs/InlineResponse20016.md +8 -0
  42. data/docs/InlineResponse20017.md +8 -0
  43. data/docs/InlineResponse20018.md +8 -0
  44. data/docs/InlineResponse20019.md +8 -0
  45. data/docs/InlineResponse2002.md +10 -0
  46. data/docs/InlineResponse20020.md +8 -0
  47. data/docs/InlineResponse20021.md +8 -0
  48. data/docs/InlineResponse20022.md +8 -0
  49. data/docs/InlineResponse20023.md +8 -0
  50. data/docs/InlineResponse20024.md +8 -0
  51. data/docs/InlineResponse20025.md +8 -0
  52. data/docs/InlineResponse20026.md +8 -0
  53. data/docs/InlineResponse20027.md +8 -0
  54. data/docs/InlineResponse20028.md +8 -0
  55. data/docs/InlineResponse20029.md +8 -0
  56. data/docs/InlineResponse2003.md +10 -0
  57. data/docs/InlineResponse20030.md +8 -0
  58. data/docs/InlineResponse20031.md +8 -0
  59. data/docs/InlineResponse20032.md +8 -0
  60. data/docs/InlineResponse20033.md +8 -0
  61. data/docs/InlineResponse2004.md +12 -0
  62. data/docs/InlineResponse2005.md +9 -0
  63. data/docs/InlineResponse2006.md +10 -0
  64. data/docs/InlineResponse2007.md +8 -0
  65. data/docs/InlineResponse2008.md +8 -0
  66. data/docs/InlineResponse2009.md +8 -0
  67. data/docs/Investment.md +32 -0
  68. data/docs/InvestmentValue.md +13 -0
  69. data/docs/Invite.md +13 -0
  70. data/docs/LockedUser.md +10 -0
  71. data/docs/OCRApi.md +117 -0
  72. data/docs/OIDCApi.md +167 -0
  73. data/docs/OidcWhitelist.md +9 -0
  74. data/docs/PFMApi.md +2204 -0
  75. data/docs/Pocket.md +17 -0
  76. data/docs/Profile.md +15 -0
  77. data/docs/Project.md +16 -0
  78. data/docs/ProjectType.md +10 -0
  79. data/docs/ProvidersApi.md +7014 -0
  80. data/docs/Recipient.md +22 -0
  81. data/docs/RecipientsApi.md +244 -0
  82. data/docs/Security.md +12 -0
  83. data/docs/Subscription.md +18 -0
  84. data/docs/TermsApi.md +218 -0
  85. data/docs/TermsOfService.md +12 -0
  86. data/docs/Transaction.md +33 -0
  87. data/docs/TransactionInformation.md +11 -0
  88. data/docs/TransactionsCluster.md +16 -0
  89. data/docs/Transfer.md +23 -0
  90. data/docs/TransfersApi.md +2404 -0
  91. data/docs/User.md +10 -0
  92. data/docs/UserAlert.md +21 -0
  93. data/docs/UsersManagementApi.md +608 -0
  94. data/docs/WealthApi.md +828 -0
  95. data/docs/Webhook.md +15 -0
  96. data/git_push.sh +55 -0
  97. data/lib/budgea_client.rb +118 -0
  98. data/lib/budgea_client/api/administration_api.rb +1059 -0
  99. data/lib/budgea_client/api/authentication_api.rb +467 -0
  100. data/lib/budgea_client/api/banks_api.rb +7837 -0
  101. data/lib/budgea_client/api/connections_api.rb +1088 -0
  102. data/lib/budgea_client/api/documents_api.rb +6637 -0
  103. data/lib/budgea_client/api/ocr_api.rb +141 -0
  104. data/lib/budgea_client/api/oidc_api.rb +195 -0
  105. data/lib/budgea_client/api/pfm_api.rb +2630 -0
  106. data/lib/budgea_client/api/providers_api.rb +8694 -0
  107. data/lib/budgea_client/api/recipients_api.rb +293 -0
  108. data/lib/budgea_client/api/terms_api.rb +245 -0
  109. data/lib/budgea_client/api/transfers_api.rb +2941 -0
  110. data/lib/budgea_client/api/users_management_api.rb +695 -0
  111. data/lib/budgea_client/api/wealth_api.rb +994 -0
  112. data/lib/budgea_client/api_client.rb +378 -0
  113. data/lib/budgea_client/api_error.rb +28 -0
  114. data/lib/budgea_client/configuration.rb +192 -0
  115. data/lib/budgea_client/models/access.rb +224 -0
  116. data/lib/budgea_client/models/account.rb +383 -0
  117. data/lib/budgea_client/models/account_log.rb +266 -0
  118. data/lib/budgea_client/models/account_type.rb +281 -0
  119. data/lib/budgea_client/models/alert.rb +273 -0
  120. data/lib/budgea_client/models/bank.rb +308 -0
  121. data/lib/budgea_client/models/bank_category.rb +201 -0
  122. data/lib/budgea_client/models/category.rb +299 -0
  123. data/lib/budgea_client/models/client.rb +305 -0
  124. data/lib/budgea_client/models/connection.rb +276 -0
  125. data/lib/budgea_client/models/connection_contact.rb +274 -0
  126. data/lib/budgea_client/models/connection_log.rb +324 -0
  127. data/lib/budgea_client/models/connector_logo.rb +223 -0
  128. data/lib/budgea_client/models/currency.rb +216 -0
  129. data/lib/budgea_client/models/device.rb +269 -0
  130. data/lib/budgea_client/models/document.rb +398 -0
  131. data/lib/budgea_client/models/document_type.rb +213 -0
  132. data/lib/budgea_client/models/field.rb +273 -0
  133. data/lib/budgea_client/models/file.rb +225 -0
  134. data/lib/budgea_client/models/group.rb +246 -0
  135. data/lib/budgea_client/models/hash_table.rb +227 -0
  136. data/lib/budgea_client/models/inline_response_200.rb +185 -0
  137. data/lib/budgea_client/models/inline_response_200_1.rb +199 -0
  138. data/lib/budgea_client/models/inline_response_200_10.rb +185 -0
  139. data/lib/budgea_client/models/inline_response_200_11.rb +185 -0
  140. data/lib/budgea_client/models/inline_response_200_12.rb +185 -0
  141. data/lib/budgea_client/models/inline_response_200_13.rb +185 -0
  142. data/lib/budgea_client/models/inline_response_200_14.rb +185 -0
  143. data/lib/budgea_client/models/inline_response_200_15.rb +185 -0
  144. data/lib/budgea_client/models/inline_response_200_16.rb +185 -0
  145. data/lib/budgea_client/models/inline_response_200_17.rb +185 -0
  146. data/lib/budgea_client/models/inline_response_200_18.rb +185 -0
  147. data/lib/budgea_client/models/inline_response_200_19.rb +185 -0
  148. data/lib/budgea_client/models/inline_response_200_2.rb +209 -0
  149. data/lib/budgea_client/models/inline_response_200_20.rb +185 -0
  150. data/lib/budgea_client/models/inline_response_200_21.rb +185 -0
  151. data/lib/budgea_client/models/inline_response_200_22.rb +185 -0
  152. data/lib/budgea_client/models/inline_response_200_23.rb +185 -0
  153. data/lib/budgea_client/models/inline_response_200_24.rb +185 -0
  154. data/lib/budgea_client/models/inline_response_200_25.rb +185 -0
  155. data/lib/budgea_client/models/inline_response_200_26.rb +185 -0
  156. data/lib/budgea_client/models/inline_response_200_27.rb +185 -0
  157. data/lib/budgea_client/models/inline_response_200_28.rb +185 -0
  158. data/lib/budgea_client/models/inline_response_200_29.rb +185 -0
  159. data/lib/budgea_client/models/inline_response_200_3.rb +214 -0
  160. data/lib/budgea_client/models/inline_response_200_30.rb +185 -0
  161. data/lib/budgea_client/models/inline_response_200_31.rb +185 -0
  162. data/lib/budgea_client/models/inline_response_200_32.rb +185 -0
  163. data/lib/budgea_client/models/inline_response_200_33.rb +185 -0
  164. data/lib/budgea_client/models/inline_response_200_4.rb +239 -0
  165. data/lib/budgea_client/models/inline_response_200_5.rb +199 -0
  166. data/lib/budgea_client/models/inline_response_200_6.rb +214 -0
  167. data/lib/budgea_client/models/inline_response_200_7.rb +185 -0
  168. data/lib/budgea_client/models/inline_response_200_8.rb +185 -0
  169. data/lib/budgea_client/models/inline_response_200_9.rb +185 -0
  170. data/lib/budgea_client/models/investment.rb +449 -0
  171. data/lib/budgea_client/models/investment_value.rb +249 -0
  172. data/lib/budgea_client/models/invite.rb +233 -0
  173. data/lib/budgea_client/models/locked_user.rb +206 -0
  174. data/lib/budgea_client/models/oidc_whitelist.rb +198 -0
  175. data/lib/budgea_client/models/pocket.rb +298 -0
  176. data/lib/budgea_client/models/profile.rb +308 -0
  177. data/lib/budgea_client/models/project.rb +301 -0
  178. data/lib/budgea_client/models/project_type.rb +206 -0
  179. data/lib/budgea_client/models/recipient.rb +343 -0
  180. data/lib/budgea_client/models/security.rb +229 -0
  181. data/lib/budgea_client/models/subscription.rb +299 -0
  182. data/lib/budgea_client/models/terms_of_service.rb +229 -0
  183. data/lib/budgea_client/models/transaction.rb +507 -0
  184. data/lib/budgea_client/models/transaction_information.rb +224 -0
  185. data/lib/budgea_client/models/transactions_cluster.rb +277 -0
  186. data/lib/budgea_client/models/transfer.rb +354 -0
  187. data/lib/budgea_client/models/user.rb +244 -0
  188. data/lib/budgea_client/models/user_alert.rb +333 -0
  189. data/lib/budgea_client/models/webhook.rb +264 -0
  190. data/lib/budgea_client/version.rb +5 -0
  191. data/pkg/budgea_client-1.0.0.gem +0 -0
  192. data/spec/api/administration_api_spec.rb +271 -0
  193. data/spec/api/authentication_api_spec.rb +126 -0
  194. data/spec/api/banks_api_spec.rb +1787 -0
  195. data/spec/api/connections_api_spec.rb +279 -0
  196. data/spec/api/documents_api_spec.rb +1557 -0
  197. data/spec/api/ocr_api_spec.rb +54 -0
  198. data/spec/api/oidc_api_spec.rb +65 -0
  199. data/spec/api/pfm_api_spec.rb +613 -0
  200. data/spec/api/providers_api_spec.rb +2029 -0
  201. data/spec/api/recipients_api_spec.rb +89 -0
  202. data/spec/api/terms_api_spec.rb +79 -0
  203. data/spec/api/transfers_api_spec.rb +661 -0
  204. data/spec/api/users_management_api_spec.rb +177 -0
  205. data/spec/api/wealth_api_spec.rb +246 -0
  206. data/spec/api_client_spec.rb +216 -0
  207. data/spec/configuration_spec.rb +32 -0
  208. data/spec/models/access_spec.rb +56 -0
  209. data/spec/models/account_log_spec.rb +74 -0
  210. data/spec/models/account_spec.rb +134 -0
  211. data/spec/models/account_type_spec.rb +74 -0
  212. data/spec/models/alert_spec.rb +74 -0
  213. data/spec/models/bank_category_spec.rb +38 -0
  214. data/spec/models/bank_spec.rb +92 -0
  215. data/spec/models/category_spec.rb +86 -0
  216. data/spec/models/client_spec.rb +92 -0
  217. data/spec/models/connection_contact_spec.rb +86 -0
  218. data/spec/models/connection_log_spec.rb +110 -0
  219. data/spec/models/connection_spec.rb +80 -0
  220. data/spec/models/connector_logo_spec.rb +50 -0
  221. data/spec/models/currency_spec.rb +44 -0
  222. data/spec/models/device_spec.rb +68 -0
  223. data/spec/models/document_spec.rb +158 -0
  224. data/spec/models/document_type_spec.rb +44 -0
  225. data/spec/models/field_spec.rb +74 -0
  226. data/spec/models/file_spec.rb +50 -0
  227. data/spec/models/group_spec.rb +74 -0
  228. data/spec/models/hash_table_spec.rb +50 -0
  229. data/spec/models/inline_response_200_10_spec.rb +32 -0
  230. data/spec/models/inline_response_200_11_spec.rb +32 -0
  231. data/spec/models/inline_response_200_12_spec.rb +32 -0
  232. data/spec/models/inline_response_200_13_spec.rb +32 -0
  233. data/spec/models/inline_response_200_14_spec.rb +32 -0
  234. data/spec/models/inline_response_200_15_spec.rb +32 -0
  235. data/spec/models/inline_response_200_16_spec.rb +32 -0
  236. data/spec/models/inline_response_200_17_spec.rb +32 -0
  237. data/spec/models/inline_response_200_18_spec.rb +32 -0
  238. data/spec/models/inline_response_200_19_spec.rb +32 -0
  239. data/spec/models/inline_response_200_1_spec.rb +38 -0
  240. data/spec/models/inline_response_200_20_spec.rb +32 -0
  241. data/spec/models/inline_response_200_21_spec.rb +32 -0
  242. data/spec/models/inline_response_200_22_spec.rb +32 -0
  243. data/spec/models/inline_response_200_23_spec.rb +32 -0
  244. data/spec/models/inline_response_200_24_spec.rb +32 -0
  245. data/spec/models/inline_response_200_25_spec.rb +32 -0
  246. data/spec/models/inline_response_200_26_spec.rb +32 -0
  247. data/spec/models/inline_response_200_27_spec.rb +32 -0
  248. data/spec/models/inline_response_200_28_spec.rb +32 -0
  249. data/spec/models/inline_response_200_29_spec.rb +32 -0
  250. data/spec/models/inline_response_200_2_spec.rb +44 -0
  251. data/spec/models/inline_response_200_30_spec.rb +32 -0
  252. data/spec/models/inline_response_200_31_spec.rb +32 -0
  253. data/spec/models/inline_response_200_32_spec.rb +32 -0
  254. data/spec/models/inline_response_200_33_spec.rb +32 -0
  255. data/spec/models/inline_response_200_3_spec.rb +44 -0
  256. data/spec/models/inline_response_200_4_spec.rb +56 -0
  257. data/spec/models/inline_response_200_5_spec.rb +38 -0
  258. data/spec/models/inline_response_200_6_spec.rb +44 -0
  259. data/spec/models/inline_response_200_7_spec.rb +32 -0
  260. data/spec/models/inline_response_200_8_spec.rb +32 -0
  261. data/spec/models/inline_response_200_9_spec.rb +32 -0
  262. data/spec/models/inline_response_200_spec.rb +32 -0
  263. data/spec/models/investment_spec.rb +176 -0
  264. data/spec/models/investment_value_spec.rb +62 -0
  265. data/spec/models/invite_spec.rb +62 -0
  266. data/spec/models/locked_user_spec.rb +44 -0
  267. data/spec/models/oidc_whitelist_spec.rb +38 -0
  268. data/spec/models/pocket_spec.rb +86 -0
  269. data/spec/models/profile_spec.rb +78 -0
  270. data/spec/models/project_spec.rb +80 -0
  271. data/spec/models/project_type_spec.rb +44 -0
  272. data/spec/models/recipient_spec.rb +116 -0
  273. data/spec/models/security_spec.rb +56 -0
  274. data/spec/models/subscription_spec.rb +92 -0
  275. data/spec/models/terms_of_service_spec.rb +56 -0
  276. data/spec/models/transaction_information_spec.rb +50 -0
  277. data/spec/models/transaction_spec.rb +182 -0
  278. data/spec/models/transactions_cluster_spec.rb +80 -0
  279. data/spec/models/transfer_spec.rb +122 -0
  280. data/spec/models/user_alert_spec.rb +110 -0
  281. data/spec/models/user_spec.rb +48 -0
  282. data/spec/models/webhook_spec.rb +74 -0
  283. data/spec/spec_helper.rb +51 -0
  284. metadata +599 -0
@@ -0,0 +1,378 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'date'
4
+ require 'json'
5
+ require 'logger'
6
+ require 'tempfile'
7
+ require 'typhoeus'
8
+ require 'uri'
9
+
10
+ module BudgeaClient
11
+ class ApiClient
12
+ # The Configuration object holding settings to be used in the API client.
13
+ attr_accessor :config
14
+
15
+ # Defines the headers to be used in HTTP requests of all API calls by default.
16
+ #
17
+ # @return [Hash]
18
+ attr_accessor :default_headers
19
+
20
+ # Initializes the ApiClient
21
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
22
+ def initialize(config = Configuration.default)
23
+ @config = config
24
+ @user_agent = "Swagger-Codegen/#{VERSION}/ruby"
25
+ @default_headers = {
26
+ 'Content-Type' => "application/json",
27
+ 'User-Agent' => @user_agent
28
+ }
29
+ end
30
+
31
+ def self.default
32
+ @@default ||= ApiClient.new
33
+ end
34
+
35
+ # Call an API with given options.
36
+ #
37
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
38
+ # the data deserialized from response body (could be nil), response status code and response headers.
39
+ def call_api(http_method, path, opts = {})
40
+ request = build_request(http_method, path, opts)
41
+ response = request.run
42
+
43
+ if @config.debugging
44
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
45
+ end
46
+
47
+ unless response.success?
48
+ if response.timed_out?
49
+ fail ApiError.new('Connection timed out')
50
+ elsif response.code == 0
51
+ # Errors from libcurl will be made visible here
52
+ fail ApiError.new(:code => 0,
53
+ :message => response.return_message)
54
+ else
55
+ fail ApiError.new(:code => response.code,
56
+ :response_headers => response.headers,
57
+ :response_body => response.body),
58
+ response.status_message
59
+ end
60
+ end
61
+
62
+ if opts[:return_type]
63
+ data = deserialize(response, opts[:return_type])
64
+ else
65
+ data = nil
66
+ end
67
+ return data, response.code, response.headers
68
+ end
69
+
70
+ # Builds the HTTP request
71
+ #
72
+ # @param [String] http_method HTTP method/verb (e.g. POST)
73
+ # @param [String] path URL path (e.g. /account/new)
74
+ # @option opts [Hash] :header_params Header parameters
75
+ # @option opts [Hash] :query_params Query parameters
76
+ # @option opts [Hash] :form_params Query parameters
77
+ # @option opts [Object] :body HTTP body (JSON/XML)
78
+ # @return [Typhoeus::Request] A Typhoeus Request
79
+ def build_request(http_method, path, opts = {})
80
+ url = build_request_url(path)
81
+ http_method = http_method.to_sym.downcase
82
+
83
+ header_params = @default_headers.merge(opts[:header_params] || {})
84
+ query_params = opts[:query_params] || {}
85
+ form_params = opts[:form_params] || {}
86
+
87
+
88
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
89
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
90
+
91
+ req_opts = {
92
+ :method => http_method,
93
+ :headers => header_params,
94
+ :params => query_params,
95
+ :params_encoding => @config.params_encoding,
96
+ :timeout => @config.timeout,
97
+ :ssl_verifypeer => @config.verify_ssl,
98
+ :ssl_verifyhost => _verify_ssl_host,
99
+ :sslcert => @config.cert_file,
100
+ :sslkey => @config.key_file,
101
+ :verbose => @config.debugging
102
+ }
103
+
104
+ # set custom cert, if provided
105
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
106
+
107
+ if [:post, :patch, :put, :delete].include?(http_method)
108
+ req_body = build_request_body(header_params, form_params, opts[:body])
109
+ req_opts.update :body => req_body
110
+ if @config.debugging
111
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
112
+ end
113
+ end
114
+
115
+ request = Typhoeus::Request.new(url, req_opts)
116
+ download_file(request) if opts[:return_type] == 'File'
117
+ request
118
+ end
119
+
120
+ # Check if the given MIME is a JSON MIME.
121
+ # JSON MIME examples:
122
+ # application/json
123
+ # application/json; charset=UTF8
124
+ # APPLICATION/JSON
125
+ # */*
126
+ # @param [String] mime MIME
127
+ # @return [Boolean] True if the MIME is application/json
128
+ def json_mime?(mime)
129
+ (mime == "*/*") || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
130
+ end
131
+
132
+ # Deserialize the response to the given return type.
133
+ #
134
+ # @param [Response] response HTTP response
135
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
136
+ def deserialize(response, return_type)
137
+ body = response.body
138
+
139
+ # handle file downloading - return the File instance processed in request callbacks
140
+ # note that response body is empty when the file is written in chunks in request on_body callback
141
+ return @tempfile if return_type == 'File'
142
+
143
+ return nil if body.nil? || body.empty?
144
+
145
+ # return response body directly for String return type
146
+ return body if return_type == 'String'
147
+
148
+ # ensuring a default content type
149
+ content_type = response.headers['Content-Type'] || 'application/json'
150
+
151
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
152
+
153
+ begin
154
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
155
+ rescue JSON::ParserError => e
156
+ if %w(String Date DateTime).include?(return_type)
157
+ data = body
158
+ else
159
+ raise e
160
+ end
161
+ end
162
+
163
+ convert_to_type data, return_type
164
+ end
165
+
166
+ # Convert data to the given return type.
167
+ # @param [Object] data Data to be converted
168
+ # @param [String] return_type Return type
169
+ # @return [Mixed] Data in a particular type
170
+ def convert_to_type(data, return_type)
171
+ return nil if data.nil?
172
+ case return_type
173
+ when 'String'
174
+ data.to_s
175
+ when 'Integer'
176
+ data.to_i
177
+ when 'Float'
178
+ data.to_f
179
+ when 'BOOLEAN'
180
+ data == true
181
+ when 'DateTime'
182
+ # parse date time (expecting ISO 8601 format)
183
+ DateTime.parse data
184
+ when 'Date'
185
+ # parse date time (expecting ISO 8601 format)
186
+ Date.parse data
187
+ when 'Object'
188
+ # generic object (usually a Hash), return directly
189
+ data
190
+ when /\AArray<(.+)>\z/
191
+ # e.g. Array<Pet>
192
+ sub_type = $1
193
+ data.map {|item| convert_to_type(item, sub_type) }
194
+ when /\AHash\<String, (.+)\>\z/
195
+ # e.g. Hash<String, Integer>
196
+ sub_type = $1
197
+ {}.tap do |hash|
198
+ data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
199
+ end
200
+ else
201
+ # models, e.g. Pet
202
+ BudgeaClient.const_get(return_type).new.tap do |model|
203
+ model.build_from_hash data
204
+ end
205
+ end
206
+ end
207
+
208
+ # Save response body into a file in (the defined) temporary folder, using the filename
209
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
210
+ # The response body is written to the file in chunks in order to handle files which
211
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
212
+ # process can use.
213
+ #
214
+ # @see Configuration#temp_folder_path
215
+ def download_file(request)
216
+ tempfile = nil
217
+ encoding = nil
218
+ request.on_headers do |response|
219
+ content_disposition = response.headers['Content-Disposition']
220
+ if content_disposition and content_disposition =~ /filename=/i
221
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
222
+ prefix = sanitize_filename(filename)
223
+ else
224
+ prefix = 'download-'
225
+ end
226
+ prefix = prefix + '-' unless prefix.end_with?('-')
227
+ encoding = response.body.encoding
228
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
229
+ @tempfile = tempfile
230
+ end
231
+ request.on_body do |chunk|
232
+ chunk.force_encoding(encoding)
233
+ tempfile.write(chunk)
234
+ end
235
+ request.on_complete do |response|
236
+ tempfile.close
237
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
238
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
239
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
240
+ "explicitly with `tempfile.delete`"
241
+ end
242
+ end
243
+
244
+ # Sanitize filename by removing path.
245
+ # e.g. ../../sun.gif becomes sun.gif
246
+ #
247
+ # @param [String] filename the filename to be sanitized
248
+ # @return [String] the sanitized filename
249
+ def sanitize_filename(filename)
250
+ filename.gsub(/.*[\/\\]/, '')
251
+ end
252
+
253
+ def build_request_url(path)
254
+ # Add leading and trailing slashes to path
255
+ path = "/#{path}".gsub(/\/+/, '/')
256
+ URI.encode(@config.base_url + path)
257
+ end
258
+
259
+ # Builds the HTTP request body
260
+ #
261
+ # @param [Hash] header_params Header parameters
262
+ # @param [Hash] form_params Query parameters
263
+ # @param [Object] body HTTP body (JSON/XML)
264
+ # @return [String] HTTP body data in the form of string
265
+ def build_request_body(header_params, form_params, body)
266
+ # http form
267
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
268
+ header_params['Content-Type'] == 'multipart/form-data'
269
+ data = {}
270
+ form_params.each do |key, value|
271
+ case value
272
+ when ::File, ::Array, nil
273
+ # let typhoeus handle File, Array and nil parameters
274
+ data[key] = value
275
+ else
276
+ data[key] = value.to_s
277
+ end
278
+ end
279
+ elsif body
280
+ data = body.is_a?(String) ? body : body.to_json
281
+ else
282
+ data = nil
283
+ end
284
+ data
285
+ end
286
+
287
+ # Update hearder and query params based on authentication settings.
288
+ #
289
+ # @param [Hash] header_params Header parameters
290
+ # @param [Hash] query_params Query parameters
291
+ # @param [String] auth_names Authentication scheme name
292
+ def update_params_for_auth!(header_params, query_params, auth_names)
293
+ Array(auth_names).each do |auth_name|
294
+ auth_setting = @config.auth_settings[auth_name]
295
+ next unless auth_setting
296
+ case auth_setting[:in]
297
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
298
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
299
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
300
+ end
301
+ end
302
+ end
303
+
304
+ # Sets user agent in HTTP header
305
+ #
306
+ # @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
307
+ def user_agent=(user_agent)
308
+ @user_agent = user_agent
309
+ @default_headers['User-Agent'] = @user_agent
310
+ end
311
+
312
+ # Return Accept header based on an array of accepts provided.
313
+ # @param [Array] accepts array for Accept
314
+ # @return [String] the Accept header (e.g. application/json)
315
+ def select_header_accept(accepts)
316
+ return nil if accepts.nil? || accepts.empty?
317
+ # use JSON when present, otherwise use all of the provided
318
+ json_accept = accepts.find { |s| json_mime?(s) }
319
+ return json_accept || accepts.join(',')
320
+ end
321
+
322
+ # Return Content-Type header based on an array of content types provided.
323
+ # @param [Array] content_types array for Content-Type
324
+ # @return [String] the Content-Type header (e.g. application/json)
325
+ def select_header_content_type(content_types)
326
+ # use application/json by default
327
+ return 'application/json' if content_types.nil? || content_types.empty?
328
+ # use JSON when present, otherwise use the first one
329
+ json_content_type = content_types.find { |s| json_mime?(s) }
330
+ return json_content_type || content_types.first
331
+ end
332
+
333
+ # Convert object (array, hash, object, etc) to JSON string.
334
+ # @param [Object] model object to be converted into JSON string
335
+ # @return [String] JSON string representation of the object
336
+ def object_to_http_body(model)
337
+ return model if model.nil? || model.is_a?(String)
338
+ local_body = nil
339
+ if model.is_a?(Array)
340
+ local_body = model.map{|m| object_to_hash(m) }
341
+ else
342
+ local_body = object_to_hash(model)
343
+ end
344
+ local_body.to_json
345
+ end
346
+
347
+ # Convert object(non-array) to hash.
348
+ # @param [Object] obj object to be converted into JSON string
349
+ # @return [String] JSON string representation of the object
350
+ def object_to_hash(obj)
351
+ if obj.respond_to?(:to_hash)
352
+ obj.to_hash
353
+ else
354
+ obj
355
+ end
356
+ end
357
+
358
+ # Build parameter value according to the given collection format.
359
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
360
+ def build_collection_param(param, collection_format)
361
+ case collection_format
362
+ when :csv
363
+ param.join(',')
364
+ when :ssv
365
+ param.join(' ')
366
+ when :tsv
367
+ param.join("\t")
368
+ when :pipes
369
+ param.join('|')
370
+ when :multi
371
+ # return the array directly as typhoeus will handle it as expected
372
+ param
373
+ else
374
+ fail "unknown collection format: #{collection_format.inspect}"
375
+ end
376
+ end
377
+ end
378
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BudgeaClient
4
+ class ApiError < StandardError
5
+ attr_reader :code, :response_headers, :response_body
6
+
7
+ # Usage examples:
8
+ # ApiError.new
9
+ # ApiError.new("message")
10
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
11
+ # ApiError.new(:code => 404, :message => "Not Found")
12
+ def initialize(arg = nil)
13
+ if arg.is_a? Hash
14
+ if arg.key?(:message) || arg.key?('message')
15
+ super(arg[:message] || arg['message'])
16
+ else
17
+ super arg
18
+ end
19
+
20
+ arg.each do |k, v|
21
+ instance_variable_set "@#{k}", v
22
+ end
23
+ else
24
+ super arg
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,192 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+
5
+ module BudgeaClient
6
+ class Configuration
7
+ # Defines url scheme
8
+ attr_accessor :scheme
9
+
10
+ # Defines url host
11
+ attr_accessor :host
12
+
13
+ # Defines url base path
14
+ attr_accessor :base_path
15
+
16
+ # Defines API keys used with API Key authentications.
17
+ #
18
+ # @return [Hash] key: parameter name, value: parameter value (API key)
19
+ #
20
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
21
+ # config.api_key['api_key'] = 'xxx'
22
+ attr_accessor :api_key
23
+
24
+ # Defines API key prefixes used with API Key authentications.
25
+ #
26
+ # @return [Hash] key: parameter name, value: API key prefix
27
+ #
28
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
29
+ # config.api_key_prefix['api_key'] = 'Token'
30
+ attr_accessor :api_key_prefix
31
+
32
+ # Defines the username used with HTTP basic authentication.
33
+ #
34
+ # @return [String]
35
+ attr_accessor :username
36
+
37
+ # Defines the password used with HTTP basic authentication.
38
+ #
39
+ # @return [String]
40
+ attr_accessor :password
41
+
42
+ # Defines the access token (Bearer) used with OAuth2.
43
+ attr_accessor :access_token
44
+
45
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
46
+ # details will be logged with `logger.debug` (see the `logger` attribute).
47
+ # Default to false.
48
+ #
49
+ # @return [true, false]
50
+ attr_accessor :debugging
51
+
52
+ # Defines the logger used for debugging.
53
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
54
+ #
55
+ # @return [#debug]
56
+ attr_accessor :logger
57
+
58
+ # Defines the temporary folder to store downloaded files
59
+ # (for API endpoints that have file response).
60
+ # Default to use `Tempfile`.
61
+ #
62
+ # @return [String]
63
+ attr_accessor :temp_folder_path
64
+
65
+ # The time limit for HTTP request in seconds.
66
+ # Default to 0 (never times out).
67
+ attr_accessor :timeout
68
+
69
+ # Set this to false to skip client side validation in the operation.
70
+ # Default to true.
71
+ # @return [true, false]
72
+ attr_accessor :client_side_validation
73
+
74
+ ### TLS/SSL setting
75
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
76
+ # Default to true.
77
+ #
78
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
79
+ #
80
+ # @return [true, false]
81
+ attr_accessor :verify_ssl
82
+
83
+ ### TLS/SSL setting
84
+ # Set this to false to skip verifying SSL host name
85
+ # Default to true.
86
+ #
87
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
88
+ #
89
+ # @return [true, false]
90
+ attr_accessor :verify_ssl_host
91
+
92
+ ### TLS/SSL setting
93
+ # Set this to customize the certificate file to verify the peer.
94
+ #
95
+ # @return [String] the path to the certificate file
96
+ #
97
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
98
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
99
+ attr_accessor :ssl_ca_cert
100
+
101
+ ### TLS/SSL setting
102
+ # Client certificate file (for client certificate)
103
+ attr_accessor :cert_file
104
+
105
+ ### TLS/SSL setting
106
+ # Client private key file (for client certificate)
107
+ attr_accessor :key_file
108
+
109
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
110
+ # Default to nil.
111
+ #
112
+ # @see The params_encoding option of Ethon. Related source code:
113
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
114
+ attr_accessor :params_encoding
115
+
116
+ attr_accessor :inject_format
117
+
118
+ attr_accessor :force_ending_format
119
+
120
+ def initialize
121
+ @scheme = 'https'
122
+ @host = 'demo.biapi.pro'
123
+ @base_path = '/2.0/'
124
+ @api_key = {}
125
+ @api_key_prefix = {}
126
+ @timeout = 0
127
+ @client_side_validation = true
128
+ @verify_ssl = true
129
+ @verify_ssl_host = true
130
+ @params_encoding = nil
131
+ @cert_file = nil
132
+ @key_file = nil
133
+ @debugging = false
134
+ @inject_format = false
135
+ @force_ending_format = false
136
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
137
+
138
+ yield(self) if block_given?
139
+ end
140
+
141
+ # The default Configuration object.
142
+ def self.default
143
+ @@default ||= Configuration.new
144
+ end
145
+
146
+ def configure
147
+ yield(self) if block_given?
148
+ end
149
+
150
+ def scheme=(scheme)
151
+ # remove :// from scheme
152
+ @scheme = scheme.sub(/:\/\//, '')
153
+ end
154
+
155
+ def host=(host)
156
+ # remove http(s):// and anything after a slash
157
+ @host = host.sub(/https?:\/\//, '').split('/').first
158
+ end
159
+
160
+ def base_path=(base_path)
161
+ # Add leading and trailing slashes to base_path
162
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
163
+ @base_path = "" if @base_path == "/"
164
+ end
165
+
166
+ def base_url
167
+ url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
168
+ URI.encode(url)
169
+ end
170
+
171
+ # Gets API key (with prefix if set).
172
+ # @param [String] param_name the parameter name of API key auth
173
+ def api_key_with_prefix(param_name)
174
+ if @api_key_prefix[param_name]
175
+ "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
176
+ else
177
+ @api_key[param_name]
178
+ end
179
+ end
180
+
181
+ # Gets Basic Auth token string
182
+ def basic_auth_token
183
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
184
+ end
185
+
186
+ # Returns Auth Settings hash for api client.
187
+ def auth_settings
188
+ {
189
+ }
190
+ end
191
+ end
192
+ end