groupdocs_platform_cloud 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 (52) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +160 -0
  4. data/Ruby Mustache Templates/ReadMe.txt +1 -0
  5. data/Ruby Mustache Templates/api_client.mustache +441 -0
  6. data/Swagger Specs File/platform.json +1683 -0
  7. data/groupdocs_platform_cloud.gemspec +26 -0
  8. data/lib/groupdocs_platform_cloud.rb +72 -0
  9. data/lib/groupdocs_platform_cloud/api/app_api.rb +359 -0
  10. data/lib/groupdocs_platform_cloud/api/app_statistics_api.rb +572 -0
  11. data/lib/groupdocs_platform_cloud/api/auth_api.rb +176 -0
  12. data/lib/groupdocs_platform_cloud/api/file_api.rb +282 -0
  13. data/lib/groupdocs_platform_cloud/api/folder_api.rb +267 -0
  14. data/lib/groupdocs_platform_cloud/api/heroku_api.rb +241 -0
  15. data/lib/groupdocs_platform_cloud/api/storage_api.rb +249 -0
  16. data/lib/groupdocs_platform_cloud/api/usage_api.rb +233 -0
  17. data/lib/groupdocs_platform_cloud/api_client.rb +446 -0
  18. data/lib/groupdocs_platform_cloud/api_error.rb +38 -0
  19. data/lib/groupdocs_platform_cloud/configuration.rb +216 -0
  20. data/lib/groupdocs_platform_cloud/groupdocs_app.rb +20 -0
  21. data/lib/groupdocs_platform_cloud/models/access_token_list_response.rb +213 -0
  22. data/lib/groupdocs_platform_cloud/models/access_token_response.rb +211 -0
  23. data/lib/groupdocs_platform_cloud/models/app.rb +243 -0
  24. data/lib/groupdocs_platform_cloud/models/app_usage.rb +235 -0
  25. data/lib/groupdocs_platform_cloud/models/application_usage_response.rb +202 -0
  26. data/lib/groupdocs_platform_cloud/models/disc_usage.rb +207 -0
  27. data/lib/groupdocs_platform_cloud/models/disc_usage_response.rb +211 -0
  28. data/lib/groupdocs_platform_cloud/models/file.rb +253 -0
  29. data/lib/groupdocs_platform_cloud/models/file_exist.rb +207 -0
  30. data/lib/groupdocs_platform_cloud/models/file_exist_response.rb +211 -0
  31. data/lib/groupdocs_platform_cloud/models/file_response.rb +224 -0
  32. data/lib/groupdocs_platform_cloud/models/file_version.rb +276 -0
  33. data/lib/groupdocs_platform_cloud/models/file_versions_response.rb +213 -0
  34. data/lib/groupdocs_platform_cloud/models/folder_response.rb +208 -0
  35. data/lib/groupdocs_platform_cloud/models/heroku_request.rb +233 -0
  36. data/lib/groupdocs_platform_cloud/models/heroku_request_options.rb +188 -0
  37. data/lib/groupdocs_platform_cloud/models/move_file_response.rb +202 -0
  38. data/lib/groupdocs_platform_cloud/models/move_folder_response.rb +202 -0
  39. data/lib/groupdocs_platform_cloud/models/remove_file_response.rb +202 -0
  40. data/lib/groupdocs_platform_cloud/models/remove_folder_response.rb +202 -0
  41. data/lib/groupdocs_platform_cloud/models/saa_spose_response.rb +202 -0
  42. data/lib/groupdocs_platform_cloud/models/storage_exist_response.rb +216 -0
  43. data/lib/groupdocs_platform_cloud/models/user_usage_summary_response.rb +211 -0
  44. data/lib/groupdocs_platform_cloud/models/user_usage_summary_statistics.rb +291 -0
  45. data/lib/groupdocs_platform_cloud/version.rb +15 -0
  46. data/test/data/SampleExecuteTemplate.doc +0 -0
  47. data/test/data/SampleExecuteTemplateData.txt +49 -0
  48. data/test/data/SampleWordDocument.docx +0 -0
  49. data/test/data/buzz.png +0 -0
  50. data/test/data/testfile.txt +1 -0
  51. data/test/platform_tests.rb +144 -0
  52. metadata +156 -0
@@ -0,0 +1,446 @@
1
+ =begin
2
+ #Web API Swagger specification
3
+
4
+ #No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5
+
6
+ OpenAPI spec version: 1.0
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.3.0-SNAPSHOT
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'json'
15
+ require 'logger'
16
+ require 'tempfile'
17
+ require 'typhoeus'
18
+ require 'uri'
19
+ require 'openssl'
20
+ require 'base64'
21
+ require 'rexml/document'
22
+
23
+ module GroupDocsPlatformCloud
24
+ class ApiClient
25
+
26
+ # The Configuration object holding settings to be used in the API client.
27
+ attr_accessor :config
28
+
29
+ # Defines the headers to be used in HTTP requests of all API calls by default.
30
+ #
31
+ # @return [Hash]
32
+ attr_accessor :default_headers
33
+
34
+ # Initializes the ApiClient
35
+ # @option config [Configuration] Configuration for initializing the object, default to Configuration.default
36
+ def initialize(config = Configuration.default)
37
+ @config = config
38
+ @user_agent = "Swagger-Codegen/#{VERSION}/ruby"
39
+ @default_headers = {
40
+ 'Content-Type' => "application/json",
41
+ 'User-Agent' => @user_agent
42
+ }
43
+ end
44
+
45
+ def self.default
46
+ @@default ||= ApiClient.new
47
+ end
48
+
49
+ # Call an API with given options.
50
+ #
51
+ # @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
52
+ # the data deserialized from response body (could be nil), response status code and response headers.
53
+ def call_api(http_method, path, opts = {})
54
+ puts "http_method #{http_method} path #{path} opts #{opts}"
55
+ request = build_request(http_method, path, opts)
56
+ response = request.run
57
+
58
+ if @config.debugging
59
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
60
+ end
61
+
62
+ unless response.success?
63
+ if response.timed_out?
64
+ fail ApiError.new('Connection timed out')
65
+ elsif response.code == 0
66
+ # Errors from libcurl will be made visible here
67
+ fail ApiError.new(:code => 0,
68
+ :message => response.return_message)
69
+ else
70
+ fail ApiError.new(:code => response.code,
71
+ :response_headers => response.headers,
72
+ :response_body => response.body),
73
+ response.status_message
74
+ end
75
+ end
76
+
77
+ if 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)
96
+ http_method = http_method.to_sym.downcase
97
+
98
+ header_params = @default_headers.merge(opts[:header_params] || {})
99
+ query_params = {}
100
+ form_params = opts[:form_params] || {}
101
+
102
+ update_params_for_auth! header_params, query_params, opts[:auth_names]
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
+ }
119
+
120
+ # set custom cert, if provided
121
+ req_opts[:cainfo] = @config.ssl_ca_cert if @config.ssl_ca_cert
122
+
123
+ if [:post, :patch, :put, :delete].include?(http_method)
124
+ req_body = build_request_body(header_params, form_params, opts[:body])
125
+ req_opts.update :body => req_body
126
+ if @config.debugging
127
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
128
+ end
129
+ end
130
+
131
+ url = sign(url, opts[:query_params])
132
+ puts "URL #{url}"
133
+ request = Typhoeus::Request.new(url, req_opts)
134
+ download_file(request) if opts[:return_type] == 'File'
135
+ request
136
+ end
137
+
138
+ # Signs a URI with your appSID and Key.
139
+ # * :url describes the URL to sign
140
+
141
+ def sign(url, query_params)
142
+
143
+ fail "Please set GroupDocs App key and SID first. You can get App key and App SID from " if GroupDocsApp.app_key.nil? || GroupDocsApp.app_sid.nil?
144
+
145
+ url = url[0..-2] if url[-1].eql? '/'
146
+
147
+ unless query_params.empty?
148
+ url = "#{url}?"
149
+ query_params.each { |key, value|
150
+ url = "#{url}#{key}=#{value}&"
151
+ }
152
+ url = url[0..-2]
153
+ end
154
+
155
+ parsed_url = URI.parse(url)
156
+
157
+ url_to_sign = "#{parsed_url.scheme}://#{parsed_url.host}#{parsed_url.path}"
158
+ url_to_sign += "?#{parsed_url.query}" if parsed_url.query
159
+ if parsed_url.query
160
+ url_to_sign += "&appSID=#{GroupDocsApp.app_sid}"
161
+ else
162
+ url_to_sign += "?appSID=#{GroupDocsApp.app_sid}"
163
+ end
164
+
165
+ # create a signature using the private key and the URL
166
+ raw_signature = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), GroupDocsApp.app_key, url_to_sign)
167
+
168
+ #Convert raw to encoded string
169
+ signature = Base64.strict_encode64(raw_signature).tr('+/', '-_')
170
+
171
+ #remove invalid character
172
+ signature = signature.gsub(/[=_-]/, '=' => '', '_' => '%2f', '-' => '%2b')
173
+
174
+ #Define expression
175
+ pat = Regexp.new('%[0-9a-f]{2}')
176
+
177
+ #Replace the portion matched to the above pattern to upper case
178
+ 6.times do
179
+ signature = signature.sub(pat, pat.match(signature).to_s.upcase)
180
+ end
181
+
182
+ # prepend the server and append the signature.
183
+ url_to_sign + "&signature=#{signature}"
184
+
185
+ end
186
+
187
+ # Check if the given MIME is a JSON MIME.
188
+ # JSON MIME examples:
189
+ # application/json
190
+ # application/json; charset=UTF8
191
+ # APPLICATION/JSON
192
+ # */*
193
+ # @param [String] mime MIME
194
+ # @return [Boolean] True if the MIME is application/json
195
+ def json_mime?(mime)
196
+ (mime == "*/*") || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
197
+ end
198
+
199
+ # Deserialize the response to the given return type.
200
+ #
201
+ # @param [Response] response HTTP response
202
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
203
+ def deserialize(response, return_type)
204
+ body = response.body
205
+
206
+ # handle file downloading - return the File instance processed in request callbacks
207
+ # note that response body is empty when the file is written in chunks in request on_body callback
208
+ return @tempfile if return_type == 'File'
209
+
210
+ return nil if body.nil? || body.empty?
211
+
212
+ # return response body directly for String return type
213
+ return body if return_type == 'String'
214
+
215
+ # ensuring a default content type
216
+ content_type = response.headers['Content-Type'] || 'application/json'
217
+
218
+ fail "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
219
+
220
+ begin
221
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
222
+ rescue JSON::ParserError => e
223
+ if %w(String Date DateTime).include?(return_type)
224
+ data = body
225
+ else
226
+ raise e
227
+ end
228
+ end
229
+
230
+ convert_to_type data, return_type
231
+ end
232
+
233
+ # Convert data to the given return type.
234
+ # @param [Object] data Data to be converted
235
+ # @param [String] return_type Return type
236
+ # @return [Mixed] Data in a particular type
237
+ def convert_to_type(data, return_type)
238
+ return nil if data.nil?
239
+ case return_type
240
+ when 'String'
241
+ data.to_s
242
+ when 'Integer'
243
+ data.to_i
244
+ when 'Float'
245
+ data.to_f
246
+ when 'BOOLEAN'
247
+ data == true
248
+ when 'DateTime'
249
+ # parse date time (expecting ISO 8601 format)
250
+ DateTime.parse data
251
+ when 'Date'
252
+ # parse date time (expecting ISO 8601 format)
253
+ Date.parse data
254
+ when 'Object'
255
+ # generic object (usually a Hash), return directly
256
+ data
257
+ when /\AArray<(.+)>\z/
258
+ # e.g. Array<Pet>
259
+ sub_type = $1
260
+ data.map {|item| convert_to_type(item, sub_type) }
261
+ when /\AHash\<String, (.+)\>\z/
262
+ # e.g. Hash<String, Integer>
263
+ sub_type = $1
264
+ {}.tap do |hash|
265
+ data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
266
+ end
267
+ else
268
+ # models, e.g. Pet
269
+ GroupDocsPlatformCloud.const_get(return_type).new.tap do |model|
270
+ model.build_from_hash data
271
+ end
272
+ end
273
+ end
274
+
275
+ # Save response body into a file in (the defined) temporary folder, using the filename
276
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
277
+ # The response body is written to the file in chunks in order to handle files which
278
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
279
+ # process can use.
280
+ #
281
+ # @see Configuration#temp_folder_path
282
+ def download_file(request)
283
+ tempfile = nil
284
+ encoding = nil
285
+ request.on_headers do |response|
286
+ content_disposition = response.headers['Content-Disposition']
287
+ if content_disposition and content_disposition =~ /filename=/i
288
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
289
+ prefix = sanitize_filename(filename)
290
+ else
291
+ prefix = 'download-'
292
+ end
293
+ prefix = prefix + '-' unless prefix.end_with?('-')
294
+ encoding = response.body.encoding
295
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
296
+ @tempfile = tempfile
297
+ end
298
+ request.on_body do |chunk|
299
+ chunk.force_encoding(encoding)
300
+ tempfile.write(chunk)
301
+ end
302
+ request.on_complete do |response|
303
+ tempfile.close
304
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
305
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
306
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
307
+ "explicitly with `tempfile.delete`"
308
+
309
+ end
310
+ end
311
+
312
+ # Sanitize filename by removing path.
313
+ # e.g. ../../sun.gif becomes sun.gif
314
+ #
315
+ # @param [String] filename the filename to be sanitized
316
+ # @return [String] the sanitized filename
317
+ def sanitize_filename(filename)
318
+ filename.gsub(/.*[\/\\]/, '')
319
+ end
320
+
321
+ def build_request_url(path)
322
+ # Add leading and trailing slashes to path
323
+ path = "/#{path}".gsub(/\/+/, '/')
324
+ URI.encode(@config.base_url + path)
325
+ end
326
+
327
+ # Builds the HTTP request body
328
+ #
329
+ # @param [Hash] header_params Header parameters
330
+ # @param [Hash] form_params Query parameters
331
+ # @param [Object] body HTTP body (JSON/XML)
332
+ # @return [String] HTTP body data in the form of string
333
+ def build_request_body(header_params, form_params, body)
334
+ # http form
335
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
336
+ header_params['Content-Type'] == 'multipart/form-data'
337
+ data = {}
338
+ form_params.each do |key, value|
339
+ case value
340
+ when File, Array, nil
341
+ # let typhoeus handle File, Array and nil parameters
342
+ data[key] = value
343
+ else
344
+ data[key] = value.to_s
345
+ end
346
+ end
347
+ elsif body
348
+ data = body.is_a?(String) ? body : body.to_json
349
+ else
350
+ data = nil
351
+ end
352
+ data
353
+ end
354
+
355
+ # Update hearder and query params based on authentication settings.
356
+ #
357
+ # @param [Hash] header_params Header parameters
358
+ # @param [Hash] query_params Query parameters
359
+ # @param [String] auth_names Authentication scheme name
360
+ def update_params_for_auth!(header_params, query_params, auth_names)
361
+ Array(auth_names).each do |auth_name|
362
+ auth_setting = @config.auth_settings[auth_name]
363
+ next unless auth_setting
364
+ case auth_setting[:in]
365
+ when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
366
+ when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
367
+ else fail ArgumentError, 'Authentication token must be in `query` of `header`'
368
+ end
369
+ end
370
+ end
371
+
372
+ # Sets user agent in HTTP header
373
+ #
374
+ # @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
375
+ def user_agent=(user_agent)
376
+ @user_agent = user_agent
377
+ @default_headers['User-Agent'] = @user_agent
378
+ end
379
+
380
+ # Return Accept header based on an array of accepts provided.
381
+ # @param [Array] accepts array for Accept
382
+ # @return [String] the Accept header (e.g. application/json)
383
+ def select_header_accept(accepts)
384
+ return nil if accepts.nil? || accepts.empty?
385
+ # use JSON when present, otherwise use all of the provided
386
+ json_accept = accepts.find { |s| json_mime?(s) }
387
+ return json_accept || accepts.join(',')
388
+ end
389
+
390
+ # Return Content-Type header based on an array of content types provided.
391
+ # @param [Array] content_types array for Content-Type
392
+ # @return [String] the Content-Type header (e.g. application/json)
393
+ def select_header_content_type(content_types)
394
+ # use application/json by default
395
+ return 'application/json' if content_types.nil? || content_types.empty?
396
+ # use JSON when present, otherwise use the first one
397
+ json_content_type = content_types.find { |s| json_mime?(s) }
398
+ return json_content_type || content_types.first
399
+ end
400
+
401
+ # Convert object (array, hash, object, etc) to JSON string.
402
+ # @param [Object] model object to be converted into JSON string
403
+ # @return [String] JSON string representation of the object
404
+ def object_to_http_body(model)
405
+ return model if model.nil? || model.is_a?(String)
406
+ local_body = nil
407
+ if model.is_a?(Array)
408
+ local_body = model.map{|m| object_to_hash(m) }
409
+ else
410
+ local_body = object_to_hash(model)
411
+ end
412
+ local_body.to_json
413
+ end
414
+
415
+ # Convert object(non-array) to hash.
416
+ # @param [Object] obj object to be converted into JSON string
417
+ # @return [String] JSON string representation of the object
418
+ def object_to_hash(obj)
419
+ if obj.respond_to?(:to_hash)
420
+ obj.to_hash
421
+ else
422
+ obj
423
+ end
424
+ end
425
+
426
+ # Build parameter value according to the given collection format.
427
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
428
+ def build_collection_param(param, collection_format)
429
+ case collection_format
430
+ when :csv
431
+ param.join(',')
432
+ when :ssv
433
+ param.join(' ')
434
+ when :tsv
435
+ param.join("\t")
436
+ when :pipes
437
+ param.join('|')
438
+ when :multi
439
+ # return the array directly as typhoeus will handle it as expected
440
+ param
441
+ else
442
+ fail "unknown collection format: #{collection_format.inspect}"
443
+ end
444
+ end
445
+ end
446
+ end
@@ -0,0 +1,38 @@
1
+ =begin
2
+ #Web API Swagger specification
3
+
4
+ #No description provided (generated by Swagger Codegen https://github.com/swagger-api/swagger-codegen)
5
+
6
+ OpenAPI spec version: 1.0
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.3.0-SNAPSHOT
10
+
11
+ =end
12
+
13
+ module GroupDocsPlatformCloud
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
+ end
38
+ end