qwil_api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (230) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +91 -0
  3. data/docs/AccountSerializer.md +18 -0
  4. data/docs/AccountsApi.md +243 -0
  5. data/docs/ApitokenauthApi.md +57 -0
  6. data/docs/CashoutCalculationSerializer.md +10 -0
  7. data/docs/CashoutSerializer.md +20 -0
  8. data/docs/CashoutSliceSerializer.md +11 -0
  9. data/docs/CashoutsApi.md +56 -0
  10. data/docs/CompanyInformationSerializer.md +18 -0
  11. data/docs/ContactInfoSerializer.md +10 -0
  12. data/docs/ContactInformationSerializer.md +16 -0
  13. data/docs/ContractorSerializer.md +20 -0
  14. data/docs/IncomeApi.md +98 -0
  15. data/docs/IncomeNestedSerializer.md +18 -0
  16. data/docs/IncomeSerializer.md +18 -0
  17. data/docs/IncomeSerializerFixedSource.md +18 -0
  18. data/docs/InvoiceSerializer.md +17 -0
  19. data/docs/InvoiceSerializerFixedSourceCreate.md +17 -0
  20. data/docs/InvoicesApi.md +98 -0
  21. data/docs/JSONWebTokenSerializer.md +7 -0
  22. data/docs/ManagerPlatformSerializer.md +22 -0
  23. data/docs/ManagerSerializer.md +10 -0
  24. data/docs/ManagersApi.md +172 -0
  25. data/docs/MembershipSerializer.md +9 -0
  26. data/docs/MembershipsApi.md +56 -0
  27. data/docs/PersonalInformationSerializer.md +16 -0
  28. data/docs/PlaidPublicTokenSerializer.md +8 -0
  29. data/docs/PlatformIncomeRequestSerializer.md +15 -0
  30. data/docs/PlatformMembershipRequestSerializer.md +11 -0
  31. data/docs/PlatformSerializer.md +30 -0
  32. data/docs/PlatformSummarySerializer.md +10 -0
  33. data/docs/PlatformsApi.md +1369 -0
  34. data/docs/RebateSerializer.md +15 -0
  35. data/docs/RebatesApi.md +98 -0
  36. data/docs/ReceivablesSerializer.md +9 -0
  37. data/docs/TaxSavingsSerializer.md +10 -0
  38. data/docs/UserAccountSerializer.md +17 -0
  39. data/docs/UserCashoutSerializer.md +20 -0
  40. data/docs/UserIncomeRequestSerializer.md +15 -0
  41. data/docs/UserPlatformMembershipRequestSerializer.md +13 -0
  42. data/docs/UserSerializer.md +40 -0
  43. data/docs/UsersApi.md +2173 -0
  44. data/docs/WriteAccountSerializer.md +16 -0
  45. data/docs/WriteCashoutCalculationSerializer.md +8 -0
  46. data/docs/WriteCashoutSerializer.md +16 -0
  47. data/docs/WriteCashoutSliceSerializer.md +11 -0
  48. data/docs/WriteCompanyInformationSerializer.md +17 -0
  49. data/docs/WriteContactInfoSerializer.md +10 -0
  50. data/docs/WriteContactInformationSerializer.md +15 -0
  51. data/docs/WriteContractorSerializer.md +14 -0
  52. data/docs/WriteIncomeNestedSerializer.md +12 -0
  53. data/docs/WriteIncomeSerializer.md +13 -0
  54. data/docs/WriteIncomeSerializerFixedSource.md +12 -0
  55. data/docs/WriteInvoiceSerializer.md +13 -0
  56. data/docs/WriteInvoiceSerializerFixedSourceCreate.md +9 -0
  57. data/docs/WriteJSONWebTokenSerializer.md +7 -0
  58. data/docs/WriteManagerPlatformSerializer.md +15 -0
  59. data/docs/WriteManagerSerializer.md +8 -0
  60. data/docs/WriteMembershipSerializer.md +8 -0
  61. data/docs/WritePersonalInformationSerializer.md +16 -0
  62. data/docs/WritePlaidPublicTokenSerializer.md +8 -0
  63. data/docs/WritePlatformIncomeRequestSerializer.md +10 -0
  64. data/docs/WritePlatformMembershipRequestSerializer.md +7 -0
  65. data/docs/WritePlatformSerializer.md +19 -0
  66. data/docs/WritePlatformSummarySerializer.md +8 -0
  67. data/docs/WriteRebateSerializer.md +9 -0
  68. data/docs/WriteReceivablesSerializer.md +8 -0
  69. data/docs/WriteTaxSavingsSerializer.md +8 -0
  70. data/docs/WriteUserAccountSerializer.md +14 -0
  71. data/docs/WriteUserCashoutSerializer.md +15 -0
  72. data/docs/WriteUserIncomeRequestSerializer.md +10 -0
  73. data/docs/WriteUserPlatformMembershipRequestSerializer.md +9 -0
  74. data/docs/WriteUserSerializer.md +21 -0
  75. data/generate-client.sh +6 -0
  76. data/lib/qwil_api/api/accounts_api.rb +320 -0
  77. data/lib/qwil_api/api/apitokenauth_api.rb +87 -0
  78. data/lib/qwil_api/api/cashouts_api.rb +89 -0
  79. data/lib/qwil_api/api/income_api.rb +142 -0
  80. data/lib/qwil_api/api/invoices_api.rb +142 -0
  81. data/lib/qwil_api/api/managers_api.rb +237 -0
  82. data/lib/qwil_api/api/memberships_api.rb +89 -0
  83. data/lib/qwil_api/api/platforms_api.rb +1674 -0
  84. data/lib/qwil_api/api/rebates_api.rb +142 -0
  85. data/lib/qwil_api/api/users_api.rb +2672 -0
  86. data/lib/qwil_api/api_client.rb +376 -0
  87. data/lib/qwil_api/api_error.rb +45 -0
  88. data/lib/qwil_api/configuration.rb +205 -0
  89. data/lib/qwil_api/models/account_serializer.rb +370 -0
  90. data/lib/qwil_api/models/cashout_calculation_serializer.rb +221 -0
  91. data/lib/qwil_api/models/cashout_serializer.rb +379 -0
  92. data/lib/qwil_api/models/cashout_slice_serializer.rb +232 -0
  93. data/lib/qwil_api/models/company_information_serializer.rb +299 -0
  94. data/lib/qwil_api/models/contact_info_serializer.rb +218 -0
  95. data/lib/qwil_api/models/contact_information_serializer.rb +280 -0
  96. data/lib/qwil_api/models/contractor_serializer.rb +361 -0
  97. data/lib/qwil_api/models/income_nested_serializer.rb +302 -0
  98. data/lib/qwil_api/models/income_serializer.rb +302 -0
  99. data/lib/qwil_api/models/income_serializer_fixed_source.rb +302 -0
  100. data/lib/qwil_api/models/invoice_serializer.rb +299 -0
  101. data/lib/qwil_api/models/invoice_serializer_fixed_source_create.rb +299 -0
  102. data/lib/qwil_api/models/json_web_token_serializer.rb +188 -0
  103. data/lib/qwil_api/models/manager_platform_serializer.rb +391 -0
  104. data/lib/qwil_api/models/manager_serializer.rb +218 -0
  105. data/lib/qwil_api/models/membership_serializer.rb +208 -0
  106. data/lib/qwil_api/models/personal_information_serializer.rb +279 -0
  107. data/lib/qwil_api/models/plaid_public_token_serializer.rb +199 -0
  108. data/lib/qwil_api/models/platform_income_request_serializer.rb +307 -0
  109. data/lib/qwil_api/models/platform_membership_request_serializer.rb +262 -0
  110. data/lib/qwil_api/models/platform_serializer.rb +480 -0
  111. data/lib/qwil_api/models/platform_summary_serializer.rb +218 -0
  112. data/lib/qwil_api/models/rebate_serializer.rb +276 -0
  113. data/lib/qwil_api/models/receivables_serializer.rb +208 -0
  114. data/lib/qwil_api/models/tax_savings_serializer.rb +219 -0
  115. data/lib/qwil_api/models/user_account_serializer.rb +359 -0
  116. data/lib/qwil_api/models/user_cashout_serializer.rb +379 -0
  117. data/lib/qwil_api/models/user_income_request_serializer.rb +307 -0
  118. data/lib/qwil_api/models/user_platform_membership_request_serializer.rb +283 -0
  119. data/lib/qwil_api/models/user_serializer.rb +592 -0
  120. data/lib/qwil_api/models/write_account_serializer.rb +331 -0
  121. data/lib/qwil_api/models/write_cashout_calculation_serializer.rb +198 -0
  122. data/lib/qwil_api/models/write_cashout_serializer.rb +316 -0
  123. data/lib/qwil_api/models/write_cashout_slice_serializer.rb +232 -0
  124. data/lib/qwil_api/models/write_company_information_serializer.rb +280 -0
  125. data/lib/qwil_api/models/write_contact_info_serializer.rb +218 -0
  126. data/lib/qwil_api/models/write_contact_information_serializer.rb +262 -0
  127. data/lib/qwil_api/models/write_contractor_serializer.rb +289 -0
  128. data/lib/qwil_api/models/write_income_nested_serializer.rb +236 -0
  129. data/lib/qwil_api/models/write_income_serializer.rb +247 -0
  130. data/lib/qwil_api/models/write_income_serializer_fixed_source.rb +236 -0
  131. data/lib/qwil_api/models/write_invoice_serializer.rb +252 -0
  132. data/lib/qwil_api/models/write_invoice_serializer_fixed_source_create.rb +210 -0
  133. data/lib/qwil_api/models/write_json_web_token_serializer.rb +188 -0
  134. data/lib/qwil_api/models/write_manager_platform_serializer.rb +314 -0
  135. data/lib/qwil_api/models/write_manager_serializer.rb +198 -0
  136. data/lib/qwil_api/models/write_membership_serializer.rb +198 -0
  137. data/lib/qwil_api/models/write_personal_information_serializer.rb +270 -0
  138. data/lib/qwil_api/models/write_plaid_public_token_serializer.rb +199 -0
  139. data/lib/qwil_api/models/write_platform_income_request_serializer.rb +220 -0
  140. data/lib/qwil_api/models/write_platform_membership_request_serializer.rb +188 -0
  141. data/lib/qwil_api/models/write_platform_serializer.rb +309 -0
  142. data/lib/qwil_api/models/write_platform_summary_serializer.rb +198 -0
  143. data/lib/qwil_api/models/write_rebate_serializer.rb +209 -0
  144. data/lib/qwil_api/models/write_receivables_serializer.rb +198 -0
  145. data/lib/qwil_api/models/write_tax_savings_serializer.rb +198 -0
  146. data/lib/qwil_api/models/write_user_account_serializer.rb +312 -0
  147. data/lib/qwil_api/models/write_user_cashout_serializer.rb +307 -0
  148. data/lib/qwil_api/models/write_user_income_request_serializer.rb +220 -0
  149. data/lib/qwil_api/models/write_user_platform_membership_request_serializer.rb +208 -0
  150. data/lib/qwil_api/models/write_user_serializer.rb +358 -0
  151. data/lib/qwil_api/version.rb +24 -0
  152. data/lib/qwil_api.rb +51 -0
  153. data/qwil_api.gemspec +53 -0
  154. data/spec/api/accounts_api_spec.rb +110 -0
  155. data/spec/api/apitokenauth_api_spec.rb +56 -0
  156. data/spec/api/cashouts_api_spec.rb +56 -0
  157. data/spec/api/income_api_spec.rb +67 -0
  158. data/spec/api/invoices_api_spec.rb +67 -0
  159. data/spec/api/managers_api_spec.rb +88 -0
  160. data/spec/api/memberships_api_spec.rb +56 -0
  161. data/spec/api/platforms_api_spec.rb +398 -0
  162. data/spec/api/rebates_api_spec.rb +67 -0
  163. data/spec/api/users_api_spec.rb +625 -0
  164. data/spec/api_client_spec.rb +235 -0
  165. data/spec/configuration_spec.rb +51 -0
  166. data/spec/models/account_serializer_spec.rb +111 -0
  167. data/spec/models/cashout_calculation_serializer_spec.rb +63 -0
  168. data/spec/models/cashout_serializer_spec.rb +135 -0
  169. data/spec/models/cashout_slice_serializer_spec.rb +69 -0
  170. data/spec/models/company_information_serializer_spec.rb +111 -0
  171. data/spec/models/contact_info_serializer_spec.rb +63 -0
  172. data/spec/models/contact_information_serializer_spec.rb +99 -0
  173. data/spec/models/contractor_serializer_spec.rb +127 -0
  174. data/spec/models/income_nested_serializer_spec.rb +111 -0
  175. data/spec/models/income_serializer_fixed_source_spec.rb +111 -0
  176. data/spec/models/income_serializer_spec.rb +111 -0
  177. data/spec/models/invoice_serializer_fixed_source_create_spec.rb +105 -0
  178. data/spec/models/invoice_serializer_spec.rb +105 -0
  179. data/spec/models/json_web_token_serializer_spec.rb +45 -0
  180. data/spec/models/manager_platform_serializer_spec.rb +143 -0
  181. data/spec/models/manager_serializer_spec.rb +63 -0
  182. data/spec/models/membership_serializer_spec.rb +57 -0
  183. data/spec/models/personal_information_serializer_spec.rb +99 -0
  184. data/spec/models/plaid_public_token_serializer_spec.rb +51 -0
  185. data/spec/models/platform_income_request_serializer_spec.rb +97 -0
  186. data/spec/models/platform_membership_request_serializer_spec.rb +73 -0
  187. data/spec/models/platform_serializer_spec.rb +191 -0
  188. data/spec/models/platform_summary_serializer_spec.rb +63 -0
  189. data/spec/models/rebate_serializer_spec.rb +93 -0
  190. data/spec/models/receivables_serializer_spec.rb +57 -0
  191. data/spec/models/tax_savings_serializer_spec.rb +63 -0
  192. data/spec/models/user_account_serializer_spec.rb +105 -0
  193. data/spec/models/user_cashout_serializer_spec.rb +135 -0
  194. data/spec/models/user_income_request_serializer_spec.rb +97 -0
  195. data/spec/models/user_platform_membership_request_serializer_spec.rb +85 -0
  196. data/spec/models/user_serializer_spec.rb +251 -0
  197. data/spec/models/write_account_serializer_spec.rb +99 -0
  198. data/spec/models/write_cashout_calculation_serializer_spec.rb +51 -0
  199. data/spec/models/write_cashout_serializer_spec.rb +107 -0
  200. data/spec/models/write_cashout_slice_serializer_spec.rb +69 -0
  201. data/spec/models/write_company_information_serializer_spec.rb +105 -0
  202. data/spec/models/write_contact_info_serializer_spec.rb +63 -0
  203. data/spec/models/write_contact_information_serializer_spec.rb +93 -0
  204. data/spec/models/write_contractor_serializer_spec.rb +91 -0
  205. data/spec/models/write_income_nested_serializer_spec.rb +75 -0
  206. data/spec/models/write_income_serializer_fixed_source_spec.rb +75 -0
  207. data/spec/models/write_income_serializer_spec.rb +81 -0
  208. data/spec/models/write_invoice_serializer_fixed_source_create_spec.rb +57 -0
  209. data/spec/models/write_invoice_serializer_spec.rb +81 -0
  210. data/spec/models/write_json_web_token_serializer_spec.rb +45 -0
  211. data/spec/models/write_manager_platform_serializer_spec.rb +101 -0
  212. data/spec/models/write_manager_serializer_spec.rb +51 -0
  213. data/spec/models/write_membership_serializer_spec.rb +51 -0
  214. data/spec/models/write_personal_information_serializer_spec.rb +99 -0
  215. data/spec/models/write_plaid_public_token_serializer_spec.rb +51 -0
  216. data/spec/models/write_platform_income_request_serializer_spec.rb +63 -0
  217. data/spec/models/write_platform_membership_request_serializer_spec.rb +45 -0
  218. data/spec/models/write_platform_serializer_spec.rb +117 -0
  219. data/spec/models/write_platform_summary_serializer_spec.rb +51 -0
  220. data/spec/models/write_rebate_serializer_spec.rb +57 -0
  221. data/spec/models/write_receivables_serializer_spec.rb +51 -0
  222. data/spec/models/write_tax_savings_serializer_spec.rb +51 -0
  223. data/spec/models/write_user_account_serializer_spec.rb +87 -0
  224. data/spec/models/write_user_cashout_serializer_spec.rb +101 -0
  225. data/spec/models/write_user_income_request_serializer_spec.rb +63 -0
  226. data/spec/models/write_user_platform_membership_request_serializer_spec.rb +57 -0
  227. data/spec/models/write_user_serializer_spec.rb +133 -0
  228. data/spec/spec_helper.rb +120 -0
  229. data/swagger-codegen-config.json +9 -0
  230. metadata +527 -0
@@ -0,0 +1,376 @@
1
+ =begin
2
+ #No descripton provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
3
+
4
+ OpenAPI spec version:
5
+
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+ Licensed under the Apache License, Version 2.0 (the "License");
9
+ you may not use this file except in compliance with the License.
10
+ You may obtain a copy of the License at
11
+
12
+ http://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing, software
15
+ distributed under the License is distributed on an "AS IS" BASIS,
16
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ See the License for the specific language governing permissions and
18
+ limitations under the License.
19
+
20
+ =end
21
+
22
+ require 'date'
23
+ require 'json'
24
+ require 'logger'
25
+ require 'tempfile'
26
+ require 'typhoeus'
27
+ require 'uri'
28
+
29
+ module QwilAPI
30
+ class ApiClient
31
+ # The Configuration object holding settings to be used in the API client.
32
+ attr_accessor :config
33
+
34
+ # Defines the headers to be used in HTTP requests of all API calls by default.
35
+ #
36
+ # @return [Hash]
37
+ attr_accessor :default_headers
38
+
39
+ # Initializes the ApiClient
40
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
41
+ def initialize(config = Configuration.default)
42
+ @config = config
43
+ @user_agent = "Swagger-Codegen/#{VERSION}/ruby"
44
+ @default_headers = {
45
+ 'Content-Type' => "application/json",
46
+ 'User-Agent' => @user_agent
47
+ }
48
+ end
49
+
50
+ def self.default
51
+ @@default ||= ApiClient.new
52
+ end
53
+
54
+ # Call an API with given options.
55
+ #
56
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
57
+ # the data deserialized from response body (could be nil), response status code and response headers.
58
+ def call_api(http_method, path, opts = {})
59
+ request = build_request(http_method, path, opts)
60
+ response = request.run
61
+
62
+ if @config.debugging
63
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
64
+ end
65
+
66
+ unless response.success?
67
+ fail ApiError.new(:code => response.code,
68
+ :response_headers => response.headers,
69
+ :response_body => response.body),
70
+ response.status_message
71
+ end
72
+
73
+ if opts[:return_type]
74
+ data = deserialize(response, opts[:return_type])
75
+ else
76
+ data = nil
77
+ end
78
+ return data, response.code, response.headers
79
+ end
80
+
81
+ # Builds the HTTP request
82
+ #
83
+ # @param [String] http_method HTTP method/verb (e.g. POST)
84
+ # @param [String] path URL path (e.g. /account/new)
85
+ # @option opts [Hash] :header_params Header parameters
86
+ # @option opts [Hash] :query_params Query parameters
87
+ # @option opts [Hash] :form_params Query parameters
88
+ # @option opts [Object] :body HTTP body (JSON/XML)
89
+ # @return [Typhoeus::Request] A Typhoeus Request
90
+ def build_request(http_method, path, opts = {})
91
+ url = build_request_url(path)
92
+ http_method = http_method.to_sym.downcase
93
+
94
+ header_params = @default_headers.merge(opts[:header_params] || {})
95
+ query_params = opts[:query_params] || {}
96
+ form_params = opts[:form_params] || {}
97
+
98
+
99
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
100
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
101
+
102
+ req_opts = {
103
+ :method => http_method,
104
+ :headers => header_params,
105
+ :params => query_params,
106
+ :params_encoding => @config.params_encoding,
107
+ :timeout => @config.timeout,
108
+ :ssl_verifypeer => @config.verify_ssl,
109
+ :ssl_verifyhost => _verify_ssl_host,
110
+ :sslcert => @config.cert_file,
111
+ :sslkey => @config.key_file,
112
+ :verbose => @config.debugging
113
+ }
114
+
115
+ # set custom cert, if provided
116
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
117
+
118
+ if [:post, :patch, :put, :delete].include?(http_method)
119
+ req_body = build_request_body(header_params, form_params, opts[:body])
120
+ req_opts.update :body => req_body
121
+ if @config.debugging
122
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
123
+ end
124
+ end
125
+
126
+ Typhoeus::Request.new(url, req_opts)
127
+ end
128
+
129
+ # Check if the given MIME is a JSON MIME.
130
+ # JSON MIME examples:
131
+ # application/json
132
+ # application/json; charset=UTF8
133
+ # APPLICATION/JSON
134
+ # @param [String] mime MIME
135
+ # @return [Boolean] True if the MIME is applicaton/json
136
+ def json_mime?(mime)
137
+ !(mime =~ /\Aapplication\/json(;.*)?\z/i).nil?
138
+ end
139
+
140
+ # Deserialize the response to the given return type.
141
+ #
142
+ # @param [Response] response HTTP response
143
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
144
+ def deserialize(response, return_type)
145
+ body = response.body
146
+ return nil if body.nil? || body.empty?
147
+
148
+ # return response body directly for String return type
149
+ return body if return_type == 'String'
150
+
151
+ # handle file downloading - save response body into a tmp file and return the File instance
152
+ return download_file(response) if return_type == 'File'
153
+
154
+ # ensuring a default content type
155
+ content_type = response.headers['Content-Type'] || 'application/json'
156
+
157
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
158
+
159
+ begin
160
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
161
+ rescue JSON::ParserError => e
162
+ if %w(String Date DateTime).include?(return_type)
163
+ data = body
164
+ else
165
+ raise e
166
+ end
167
+ end
168
+
169
+ convert_to_type data, return_type
170
+ end
171
+
172
+ # Convert data to the given return type.
173
+ # @param [Object] data Data to be converted
174
+ # @param [String] return_type Return type
175
+ # @return [Mixed] Data in a particular type
176
+ def convert_to_type(data, return_type)
177
+ return nil if data.nil?
178
+ case return_type
179
+ when 'String'
180
+ data.to_s
181
+ when 'Integer'
182
+ data.to_i
183
+ when 'Float'
184
+ data.to_f
185
+ when 'BOOLEAN'
186
+ data == true
187
+ when 'DateTime'
188
+ # parse date time (expecting ISO 8601 format)
189
+ DateTime.parse data
190
+ when 'Date'
191
+ # parse date time (expecting ISO 8601 format)
192
+ Date.parse data
193
+ when 'Object'
194
+ # generic object (usually a Hash), return directly
195
+ data
196
+ when /\AArray<(.+)>\z/
197
+ # e.g. Array<Pet>
198
+ sub_type = $1
199
+ data.map {|item| convert_to_type(item, sub_type) }
200
+ when /\AHash\<String, (.+)\>\z/
201
+ # e.g. Hash<String, Integer>
202
+ sub_type = $1
203
+ {}.tap do |hash|
204
+ data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
205
+ end
206
+ else
207
+ # models, e.g. Pet
208
+ QwilAPI.const_get(return_type).new.tap do |model|
209
+ model.build_from_hash data
210
+ end
211
+ end
212
+ end
213
+
214
+ # Save response body into a file in (the defined) temporary folder, using the filename
215
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
216
+ #
217
+ # @see Configuration#temp_folder_path
218
+ # @return [Tempfile] the file downloaded
219
+ def download_file(response)
220
+ content_disposition = response.headers['Content-Disposition']
221
+ if content_disposition and content_disposition =~ /filename=/i
222
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
223
+ prefix = sanitize_filename(filename)
224
+ else
225
+ prefix = 'download-'
226
+ end
227
+ prefix = prefix + '-' unless prefix.end_with?('-')
228
+
229
+ tempfile = nil
230
+ encoding = response.body.encoding
231
+ Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding) do |file|
232
+ file.write(response.body)
233
+ tempfile = file
234
+ end
235
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
236
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
237
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
238
+ "explicitly with `tempfile.delete`"
239
+ tempfile
240
+ end
241
+
242
+ # Sanitize filename by removing path.
243
+ # e.g. ../../sun.gif becomes sun.gif
244
+ #
245
+ # @param [String] filename the filename to be sanitized
246
+ # @return [String] the sanitized filename
247
+ def sanitize_filename(filename)
248
+ filename.gsub(/.*[\/\\]/, '')
249
+ end
250
+
251
+ def build_request_url(path)
252
+ # Add leading and trailing slashes to path
253
+ path = "/#{path}".gsub(/\/+/, '/')
254
+ URI.encode(@config.base_url + path)
255
+ end
256
+
257
+ # Builds the HTTP request body
258
+ #
259
+ # @param [Hash] header_params Header parameters
260
+ # @param [Hash] form_params Query parameters
261
+ # @param [Object] body HTTP body (JSON/XML)
262
+ # @return [String] HTTP body data in the form of string
263
+ def build_request_body(header_params, form_params, body)
264
+ # http form
265
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
266
+ header_params['Content-Type'] == 'multipart/form-data'
267
+ data = {}
268
+ form_params.each do |key, value|
269
+ case value
270
+ when File, Array, nil
271
+ # let typhoeus handle File, Array and nil parameters
272
+ data[key] = value
273
+ else
274
+ data[key] = value.to_s
275
+ end
276
+ end
277
+ elsif body
278
+ data = body.is_a?(String) ? body : body.to_json
279
+ else
280
+ data = nil
281
+ end
282
+ data
283
+ end
284
+
285
+ # Update hearder and query params based on authentication settings.
286
+ #
287
+ # @param [Hash] header_params Header parameters
288
+ # @param [Hash] form_params Query parameters
289
+ # @param [String] auth_names Authentication scheme name
290
+ def update_params_for_auth!(header_params, query_params, auth_names)
291
+ Array(auth_names).each do |auth_name|
292
+ auth_setting = @config.auth_settings[auth_name]
293
+ next unless auth_setting
294
+ case auth_setting[:in]
295
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
296
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
297
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
298
+ end
299
+ end
300
+ end
301
+
302
+ # Sets user agent in HTTP header
303
+ #
304
+ # @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
305
+ def user_agent=(user_agent)
306
+ @user_agent = user_agent
307
+ @default_headers['User-Agent'] = @user_agent
308
+ end
309
+
310
+ # Return Accept header based on an array of accepts provided.
311
+ # @param [Array] accepts array for Accept
312
+ # @return [String] the Accept header (e.g. application/json)
313
+ def select_header_accept(accepts)
314
+ return nil if accepts.nil? || accepts.empty?
315
+ # use JSON when present, otherwise use all of the provided
316
+ json_accept = accepts.find { |s| json_mime?(s) }
317
+ return json_accept || accepts.join(',')
318
+ end
319
+
320
+ # Return Content-Type header based on an array of content types provided.
321
+ # @param [Array] content_types array for Content-Type
322
+ # @return [String] the Content-Type header (e.g. application/json)
323
+ def select_header_content_type(content_types)
324
+ # use application/json by default
325
+ return 'application/json' if content_types.nil? || content_types.empty?
326
+ # use JSON when present, otherwise use the first one
327
+ json_content_type = content_types.find { |s| json_mime?(s) }
328
+ return json_content_type || content_types.first
329
+ end
330
+
331
+ # Convert object (array, hash, object, etc) to JSON string.
332
+ # @param [Object] model object to be converted into JSON string
333
+ # @return [String] JSON string representation of the object
334
+ def object_to_http_body(model)
335
+ return model if model.nil? || model.is_a?(String)
336
+ local_body = nil
337
+ if model.is_a?(Array)
338
+ local_body = model.map{|m| object_to_hash(m) }
339
+ else
340
+ local_body = object_to_hash(model)
341
+ end
342
+ local_body.to_json
343
+ end
344
+
345
+ # Convert object(non-array) to hash.
346
+ # @param [Object] obj object to be converted into JSON string
347
+ # @return [String] JSON string representation of the object
348
+ def object_to_hash(obj)
349
+ if obj.respond_to?(:to_hash)
350
+ obj.to_hash
351
+ else
352
+ obj
353
+ end
354
+ end
355
+
356
+ # Build parameter value according to the given collection format.
357
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
358
+ def build_collection_param(param, collection_format)
359
+ case collection_format
360
+ when :csv
361
+ param.join(',')
362
+ when :ssv
363
+ param.join(' ')
364
+ when :tsv
365
+ param.join("\t")
366
+ when :pipes
367
+ param.join('|')
368
+ when :multi
369
+ # return the array directly as typhoeus will handle it as expected
370
+ param
371
+ else
372
+ fail "unknown collection format: #{collection_format.inspect}"
373
+ end
374
+ end
375
+ end
376
+ end
@@ -0,0 +1,45 @@
1
+ =begin
2
+ #No descripton provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
3
+
4
+ OpenAPI spec version:
5
+
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+ Licensed under the Apache License, Version 2.0 (the "License");
9
+ you may not use this file except in compliance with the License.
10
+ You may obtain a copy of the License at
11
+
12
+ http://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing, software
15
+ distributed under the License is distributed on an "AS IS" BASIS,
16
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ See the License for the specific language governing permissions and
18
+ limitations under the License.
19
+
20
+ =end
21
+
22
+ module QwilAPI
23
+ class ApiError < StandardError
24
+ attr_reader :code, :response_headers, :response_body
25
+
26
+ # Usage examples:
27
+ # ApiError.new
28
+ # ApiError.new("message")
29
+ # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
30
+ # ApiError.new(:code => 404, :message => "Not Found")
31
+ def initialize(arg = nil)
32
+ if arg.is_a? Hash
33
+ arg.each do |k, v|
34
+ if k.to_s == 'message'
35
+ super v
36
+ else
37
+ instance_variable_set "@#{k}", v
38
+ end
39
+ end
40
+ else
41
+ super arg
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,205 @@
1
+ =begin
2
+ #No descripton provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
3
+
4
+ OpenAPI spec version:
5
+
6
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
7
+
8
+ Licensed under the Apache License, Version 2.0 (the "License");
9
+ you may not use this file except in compliance with the License.
10
+ You may obtain a copy of the License at
11
+
12
+ http://www.apache.org/licenses/LICENSE-2.0
13
+
14
+ Unless required by applicable law or agreed to in writing, software
15
+ distributed under the License is distributed on an "AS IS" BASIS,
16
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ See the License for the specific language governing permissions and
18
+ limitations under the License.
19
+
20
+ =end
21
+
22
+ require 'uri'
23
+
24
+ module QwilAPI
25
+ class Configuration
26
+ # Defines url scheme
27
+ attr_accessor :scheme
28
+
29
+ # Defines url host
30
+ attr_accessor :host
31
+
32
+ # Defines url base path
33
+ attr_accessor :base_path
34
+
35
+ # Defines API keys used with API Key authentications.
36
+ #
37
+ # @return [Hash] key: parameter name, value: parameter value (API key)
38
+ #
39
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
40
+ # config.api_key['api_key'] = 'xxx'
41
+ attr_accessor :api_key
42
+
43
+ # Defines API key prefixes used with API Key authentications.
44
+ #
45
+ # @return [Hash] key: parameter name, value: API key prefix
46
+ #
47
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
48
+ # config.api_key_prefix['api_key'] = 'Token'
49
+ attr_accessor :api_key_prefix
50
+
51
+ # Defines the username used with HTTP basic authentication.
52
+ #
53
+ # @return [String]
54
+ attr_accessor :username
55
+
56
+ # Defines the password used with HTTP basic authentication.
57
+ #
58
+ # @return [String]
59
+ attr_accessor :password
60
+
61
+ # Defines the access token (Bearer) used with OAuth2.
62
+ attr_accessor :access_token
63
+
64
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
65
+ # details will be logged with `logger.debug` (see the `logger` attribute).
66
+ # Default to false.
67
+ #
68
+ # @return [true, false]
69
+ attr_accessor :debugging
70
+
71
+ # Defines the logger used for debugging.
72
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
73
+ #
74
+ # @return [#debug]
75
+ attr_accessor :logger
76
+
77
+ # Defines the temporary folder to store downloaded files
78
+ # (for API endpoints that have file response).
79
+ # Default to use `Tempfile`.
80
+ #
81
+ # @return [String]
82
+ attr_accessor :temp_folder_path
83
+
84
+ # The time limit for HTTP request in seconds.
85
+ # Default to 0 (never times out).
86
+ attr_accessor :timeout
87
+
88
+ ### TLS/SSL setting
89
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
90
+ # Default to true.
91
+ #
92
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
93
+ #
94
+ # @return [true, false]
95
+ attr_accessor :verify_ssl
96
+
97
+ ### TLS/SSL setting
98
+ # Set this to false to skip verifying SSL host name
99
+ # Default to true.
100
+ #
101
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
102
+ #
103
+ # @return [true, false]
104
+ attr_accessor :verify_ssl_host
105
+
106
+ ### TLS/SSL setting
107
+ # Set this to customize the certificate file to verify the peer.
108
+ #
109
+ # @return [String] the path to the certificate file
110
+ #
111
+ # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
112
+ # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
113
+ attr_accessor :ssl_ca_cert
114
+
115
+ ### TLS/SSL setting
116
+ # Client certificate file (for client certificate)
117
+ attr_accessor :cert_file
118
+
119
+ ### TLS/SSL setting
120
+ # Client private key file (for client certificate)
121
+ attr_accessor :key_file
122
+
123
+ # Set this to customize parameters encoding of array parameter with multi collectionFormat.
124
+ # Default to nil.
125
+ #
126
+ # @see The params_encoding option of Ethon. Related source code:
127
+ # https://github.com/typhoeus/ethon/blob/master/lib/ethon/easy/queryable.rb#L96
128
+ attr_accessor :params_encoding
129
+
130
+ attr_accessor :inject_format
131
+
132
+ attr_accessor :force_ending_format
133
+
134
+ def initialize
135
+ @scheme = 'http'
136
+ @host = 'localhost:8000'
137
+ @base_path = '/'
138
+ @api_key = {}
139
+ @api_key_prefix = {}
140
+ @timeout = 0
141
+ @verify_ssl = true
142
+ @verify_ssl_host = true
143
+ @params_encoding = nil
144
+ @cert_file = nil
145
+ @key_file = nil
146
+ @debugging = false
147
+ @inject_format = false
148
+ @force_ending_format = false
149
+ @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
150
+
151
+ yield(self) if block_given?
152
+ end
153
+
154
+ # The default Configuration object.
155
+ def self.default
156
+ @@default ||= Configuration.new
157
+ end
158
+
159
+ def configure
160
+ yield(self) if block_given?
161
+ end
162
+
163
+ def scheme=(scheme)
164
+ # remove :// from scheme
165
+ @scheme = scheme.sub(/:\/\//, '')
166
+ end
167
+
168
+ def host=(host)
169
+ # remove http(s):// and anything after a slash
170
+ @host = host.sub(/https?:\/\//, '').split('/').first
171
+ end
172
+
173
+ def base_path=(base_path)
174
+ # Add leading and trailing slashes to base_path
175
+ @base_path = "/#{base_path}".gsub(/\/+/, '/')
176
+ @base_path = "" if @base_path == "/"
177
+ end
178
+
179
+ def base_url
180
+ url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
181
+ URI.encode(url)
182
+ end
183
+
184
+ # Gets API key (with prefix if set).
185
+ # @param [String] param_name the parameter name of API key auth
186
+ def api_key_with_prefix(param_name)
187
+ if @api_key_prefix[param_name]
188
+ "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
189
+ else
190
+ @api_key[param_name]
191
+ end
192
+ end
193
+
194
+ # Gets Basic Auth token string
195
+ def basic_auth_token
196
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
197
+ end
198
+
199
+ # Returns Auth Settings hash for api client.
200
+ def auth_settings
201
+ {
202
+ }
203
+ end
204
+ end
205
+ end