yalla_auth_ruby_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 (40) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/README.md +111 -0
  4. data/Rakefile +10 -0
  5. data/docs/App.md +32 -0
  6. data/docs/AppsApi.md +399 -0
  7. data/docs/AuthApi.md +70 -0
  8. data/docs/AuthValidateTokenGet200Response.md +20 -0
  9. data/docs/Role.md +34 -0
  10. data/docs/User.md +30 -0
  11. data/docs/UserAppAdd.md +18 -0
  12. data/docs/UserRoleAdd.md +24 -0
  13. data/docs/UsersApi.md +531 -0
  14. data/git_push.sh +57 -0
  15. data/lib/openapi_client/api/apps_api.rb +439 -0
  16. data/lib/openapi_client/api/auth_api.rb +84 -0
  17. data/lib/openapi_client/api/users_api.rb +587 -0
  18. data/lib/openapi_client/api_client.rb +392 -0
  19. data/lib/openapi_client/api_error.rb +58 -0
  20. data/lib/openapi_client/configuration.rb +311 -0
  21. data/lib/openapi_client/models/app.rb +283 -0
  22. data/lib/openapi_client/models/auth_validate_token_get200_response.rb +229 -0
  23. data/lib/openapi_client/models/role.rb +292 -0
  24. data/lib/openapi_client/models/user.rb +274 -0
  25. data/lib/openapi_client/models/user_app_add.rb +220 -0
  26. data/lib/openapi_client/models/user_role_add.rb +247 -0
  27. data/lib/openapi_client/version.rb +15 -0
  28. data/lib/openapi_client.rb +48 -0
  29. data/spec/api/apps_api_spec.rb +108 -0
  30. data/spec/api/auth_api_spec.rb +46 -0
  31. data/spec/api/users_api_spec.rb +134 -0
  32. data/spec/models/app_spec.rb +78 -0
  33. data/spec/models/auth_validate_token_get200_response_spec.rb +42 -0
  34. data/spec/models/role_spec.rb +84 -0
  35. data/spec/models/user_app_add_spec.rb +36 -0
  36. data/spec/models/user_role_add_spec.rb +54 -0
  37. data/spec/models/user_spec.rb +72 -0
  38. data/spec/spec_helper.rb +111 -0
  39. data/yalla_auth_ruby_client.gemspec +39 -0
  40. metadata +128 -0
@@ -0,0 +1,392 @@
1
+ =begin
2
+ #API V1
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: v1
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.12.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'json'
15
+ require 'logger'
16
+ require 'tempfile'
17
+ require 'time'
18
+ require 'typhoeus'
19
+
20
+
21
+ module OpenapiClient
22
+ class ApiClient
23
+ # The Configuration object holding settings to be used in the API client.
24
+ attr_accessor :config
25
+
26
+ # Defines the headers to be used in HTTP requests of all API calls by default.
27
+ #
28
+ # @return [Hash]
29
+ attr_accessor :default_headers
30
+
31
+ # Initializes the ApiClient
32
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
33
+ def initialize(config = Configuration.default)
34
+ @config = config
35
+ @user_agent = "OpenAPI-Generator/#{VERSION}/ruby"
36
+ @default_headers = {
37
+ 'Content-Type' => 'application/json',
38
+ 'User-Agent' => @user_agent
39
+ }
40
+ end
41
+
42
+ def self.default
43
+ @@default ||= ApiClient.new
44
+ end
45
+
46
+ # Call an API with given options.
47
+ #
48
+ # @return [Array<(Object, Integer, Hash)>] an array of 3 elements:
49
+ # the data deserialized from response body (may be a Tempfile or nil), response status code and response headers.
50
+ def call_api(http_method, path, opts = {})
51
+ request = build_request(http_method, path, opts)
52
+ tempfile = nil
53
+ (download_file(request) { tempfile = _1 }) if opts[:return_type] == 'File'
54
+ response = request.run
55
+
56
+ if @config.debugging
57
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
58
+ end
59
+
60
+ unless response.success?
61
+ if response.timed_out?
62
+ fail ApiError.new('Connection timed out')
63
+ elsif response.code == 0
64
+ # Errors from libcurl will be made visible here
65
+ fail ApiError.new(:code => 0,
66
+ :message => response.return_message)
67
+ else
68
+ fail ApiError.new(:code => response.code,
69
+ :response_headers => response.headers,
70
+ :response_body => response.body),
71
+ response.status_message
72
+ end
73
+ end
74
+
75
+ if opts[:return_type] == 'File'
76
+ data = tempfile
77
+ elsif opts[:return_type]
78
+ data = deserialize(response, opts[:return_type])
79
+ else
80
+ data = nil
81
+ end
82
+ return data, response.code, response.headers
83
+ end
84
+
85
+ # Builds the HTTP request
86
+ #
87
+ # @param [String] http_method HTTP method/verb (e.g. POST)
88
+ # @param [String] path URL path (e.g. /account/new)
89
+ # @option opts [Hash] :header_params Header parameters
90
+ # @option opts [Hash] :query_params Query parameters
91
+ # @option opts [Hash] :form_params Query parameters
92
+ # @option opts [Object] :body HTTP body (JSON/XML)
93
+ # @return [Typhoeus::Request] A Typhoeus Request
94
+ def build_request(http_method, path, opts = {})
95
+ url = build_request_url(path, opts)
96
+ http_method = http_method.to_sym.downcase
97
+
98
+ header_params = @default_headers.merge(opts[:header_params] || {})
99
+ query_params = opts[:query_params] || {}
100
+ form_params = opts[:form_params] || {}
101
+ follow_location = opts[:follow_location] || true
102
+
103
+
104
+ # set ssl_verifyhosts option based on @config.verify_ssl_host (true/false)
105
+ _verify_ssl_host = @config.verify_ssl_host ? 2 : 0
106
+
107
+ req_opts = {
108
+ :method => http_method,
109
+ :headers => header_params,
110
+ :params => query_params,
111
+ :params_encoding => @config.params_encoding,
112
+ :timeout => @config.timeout,
113
+ :ssl_verifypeer => @config.verify_ssl,
114
+ :ssl_verifyhost => _verify_ssl_host,
115
+ :sslcert => @config.cert_file,
116
+ :sslkey => @config.key_file,
117
+ :verbose => @config.debugging,
118
+ :followlocation => follow_location
119
+ }
120
+
121
+ # set custom cert, if provided
122
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
123
+
124
+ if [:post, :patch, :put, :delete].include?(http_method)
125
+ req_body = build_request_body(header_params, form_params, opts[:body])
126
+ req_opts.update :body => req_body
127
+ if @config.debugging
128
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
129
+ end
130
+ end
131
+
132
+ Typhoeus::Request.new(url, req_opts)
133
+ end
134
+
135
+ # Builds the HTTP request body
136
+ #
137
+ # @param [Hash] header_params Header parameters
138
+ # @param [Hash] form_params Query parameters
139
+ # @param [Object] body HTTP body (JSON/XML)
140
+ # @return [String] HTTP body data in the form of string
141
+ def build_request_body(header_params, form_params, body)
142
+ # http form
143
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
144
+ header_params['Content-Type'] == 'multipart/form-data'
145
+ data = {}
146
+ form_params.each do |key, value|
147
+ case value
148
+ when ::File, ::Array, nil
149
+ # let typhoeus handle File, Array and nil parameters
150
+ data[key] = value
151
+ else
152
+ data[key] = value.to_s
153
+ end
154
+ end
155
+ elsif body
156
+ data = body.is_a?(String) ? body : body.to_json
157
+ else
158
+ data = nil
159
+ end
160
+ data
161
+ end
162
+
163
+ # Save response body into a file in (the defined) temporary folder, using the filename
164
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
165
+ # The response body is written to the file in chunks in order to handle files which
166
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
167
+ # process can use.
168
+ #
169
+ # @see Configuration#temp_folder_path
170
+ #
171
+ # @return [Tempfile] the tempfile generated
172
+ def download_file(request)
173
+ tempfile = nil
174
+ encoding = nil
175
+ request.on_headers do |response|
176
+ content_disposition = response.headers['Content-Disposition']
177
+ if content_disposition && content_disposition =~ /filename=/i
178
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
179
+ prefix = sanitize_filename(filename)
180
+ else
181
+ prefix = 'download-'
182
+ end
183
+ prefix = prefix + '-' unless prefix.end_with?('-')
184
+ encoding = response.body.encoding
185
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
186
+ end
187
+ request.on_body do |chunk|
188
+ chunk.force_encoding(encoding)
189
+ tempfile.write(chunk)
190
+ end
191
+ request.on_complete do
192
+ if !tempfile
193
+ fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
194
+ end
195
+ tempfile.close
196
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
197
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
198
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
199
+ "explicitly with `tempfile.delete`"
200
+ yield tempfile if block_given?
201
+ end
202
+ end
203
+
204
+ # Check if the given MIME is a JSON MIME.
205
+ # JSON MIME examples:
206
+ # application/json
207
+ # application/json; charset=UTF8
208
+ # APPLICATION/JSON
209
+ # */*
210
+ # @param [String] mime MIME
211
+ # @return [Boolean] True if the MIME is application/json
212
+ def json_mime?(mime)
213
+ (mime == '*/*') || !(mime =~ /^Application\/.*json(?!p)(;.*)?/i).nil?
214
+ end
215
+
216
+ # Deserialize the response to the given return type.
217
+ #
218
+ # @param [Response] response HTTP response
219
+ # @param [String] return_type some examples: "User", "Array<User>", "Hash<String, Integer>"
220
+ def deserialize(response, return_type)
221
+ body = response.body
222
+ return nil if body.nil? || body.empty?
223
+
224
+ # return response body directly for String return type
225
+ return body.to_s if return_type == 'String'
226
+
227
+ # ensuring a default content type
228
+ content_type = response.headers['Content-Type'] || 'application/json'
229
+
230
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
231
+
232
+ begin
233
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
234
+ rescue JSON::ParserError => e
235
+ if %w(String Date Time).include?(return_type)
236
+ data = body
237
+ else
238
+ raise e
239
+ end
240
+ end
241
+
242
+ convert_to_type data, return_type
243
+ end
244
+
245
+ # Convert data to the given return type.
246
+ # @param [Object] data Data to be converted
247
+ # @param [String] return_type Return type
248
+ # @return [Mixed] Data in a particular type
249
+ def convert_to_type(data, return_type)
250
+ return nil if data.nil?
251
+ case return_type
252
+ when 'String'
253
+ data.to_s
254
+ when 'Integer'
255
+ data.to_i
256
+ when 'Float'
257
+ data.to_f
258
+ when 'Boolean'
259
+ data == true
260
+ when 'Time'
261
+ # parse date time (expecting ISO 8601 format)
262
+ Time.parse data
263
+ when 'Date'
264
+ # parse date time (expecting ISO 8601 format)
265
+ Date.parse data
266
+ when 'Object'
267
+ # generic object (usually a Hash), return directly
268
+ data
269
+ when /\AArray<(.+)>\z/
270
+ # e.g. Array<Pet>
271
+ sub_type = $1
272
+ data.map { |item| convert_to_type(item, sub_type) }
273
+ when /\AHash\<String, (.+)\>\z/
274
+ # e.g. Hash<String, Integer>
275
+ sub_type = $1
276
+ {}.tap do |hash|
277
+ data.each { |k, v| hash[k] = convert_to_type(v, sub_type) }
278
+ end
279
+ else
280
+ # models (e.g. Pet) or oneOf
281
+ klass = OpenapiClient.const_get(return_type)
282
+ klass.respond_to?(:openapi_one_of) ? klass.build(data) : klass.build_from_hash(data)
283
+ end
284
+ end
285
+
286
+ # Sanitize filename by removing path.
287
+ # e.g. ../../sun.gif becomes sun.gif
288
+ #
289
+ # @param [String] filename the filename to be sanitized
290
+ # @return [String] the sanitized filename
291
+ def sanitize_filename(filename)
292
+ filename.split(/[\/\\]/).last
293
+ end
294
+
295
+ def build_request_url(path, opts = {})
296
+ # Add leading and trailing slashes to path
297
+ path = "/#{path}".gsub(/\/+/, '/')
298
+ @config.base_url(opts[:operation]) + path
299
+ end
300
+
301
+ # Update header and query params based on authentication settings.
302
+ #
303
+ # @param [Hash] header_params Header parameters
304
+ # @param [Hash] query_params Query parameters
305
+ # @param [String] auth_names Authentication scheme name
306
+ def update_params_for_auth!(header_params, query_params, auth_names)
307
+ Array(auth_names).each do |auth_name|
308
+ auth_setting = @config.auth_settings[auth_name]
309
+ next unless auth_setting
310
+ case auth_setting[:in]
311
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
312
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
313
+ else fail ArgumentError, 'Authentication token must be in `query` or `header`'
314
+ end
315
+ end
316
+ end
317
+
318
+ # Sets user agent in HTTP header
319
+ #
320
+ # @param [String] user_agent User agent (e.g. openapi-generator/ruby/1.0.0)
321
+ def user_agent=(user_agent)
322
+ @user_agent = user_agent
323
+ @default_headers['User-Agent'] = @user_agent
324
+ end
325
+
326
+ # Return Accept header based on an array of accepts provided.
327
+ # @param [Array] accepts array for Accept
328
+ # @return [String] the Accept header (e.g. application/json)
329
+ def select_header_accept(accepts)
330
+ return nil if accepts.nil? || accepts.empty?
331
+ # use JSON when present, otherwise use all of the provided
332
+ json_accept = accepts.find { |s| json_mime?(s) }
333
+ json_accept || accepts.join(',')
334
+ end
335
+
336
+ # Return Content-Type header based on an array of content types provided.
337
+ # @param [Array] content_types array for Content-Type
338
+ # @return [String] the Content-Type header (e.g. application/json)
339
+ def select_header_content_type(content_types)
340
+ # return nil by default
341
+ return if content_types.nil? || content_types.empty?
342
+ # use JSON when present, otherwise use the first one
343
+ json_content_type = content_types.find { |s| json_mime?(s) }
344
+ json_content_type || content_types.first
345
+ end
346
+
347
+ # Convert object (array, hash, object, etc) to JSON string.
348
+ # @param [Object] model object to be converted into JSON string
349
+ # @return [String] JSON string representation of the object
350
+ def object_to_http_body(model)
351
+ return model if model.nil? || model.is_a?(String)
352
+ local_body = nil
353
+ if model.is_a?(Array)
354
+ local_body = model.map { |m| object_to_hash(m) }
355
+ else
356
+ local_body = object_to_hash(model)
357
+ end
358
+ local_body.to_json
359
+ end
360
+
361
+ # Convert object(non-array) to hash.
362
+ # @param [Object] obj object to be converted into JSON string
363
+ # @return [String] JSON string representation of the object
364
+ def object_to_hash(obj)
365
+ if obj.respond_to?(:to_hash)
366
+ obj.to_hash
367
+ else
368
+ obj
369
+ end
370
+ end
371
+
372
+ # Build parameter value according to the given collection format.
373
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
374
+ def build_collection_param(param, collection_format)
375
+ case collection_format
376
+ when :csv
377
+ param.join(',')
378
+ when :ssv
379
+ param.join(' ')
380
+ when :tsv
381
+ param.join("\t")
382
+ when :pipes
383
+ param.join('|')
384
+ when :multi
385
+ # return the array directly as typhoeus will handle it as expected
386
+ param
387
+ else
388
+ fail "unknown collection format: #{collection_format.inspect}"
389
+ end
390
+ end
391
+ end
392
+ end
@@ -0,0 +1,58 @@
1
+ =begin
2
+ #API V1
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: v1
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.12.0
10
+
11
+ =end
12
+
13
+ module OpenapiClient
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
+ @message = arg
36
+ end
37
+ end
38
+
39
+ # Override to_s to display a friendly error message
40
+ def to_s
41
+ message
42
+ end
43
+
44
+ def message
45
+ if @message.nil?
46
+ msg = "Error message: the server returns an error"
47
+ else
48
+ msg = @message
49
+ end
50
+
51
+ msg += "\nHTTP status code: #{code}" if code
52
+ msg += "\nResponse headers: #{response_headers}" if response_headers
53
+ msg += "\nResponse body: #{response_body}" if response_body
54
+
55
+ msg
56
+ end
57
+ end
58
+ end