aspose_storage_cloud 1.0.1 → 18.6

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 (66) hide show
  1. checksums.yaml +4 -4
  2. data/lib/Aspose/Storage/api/storage_api.rb +982 -0
  3. data/lib/Aspose/Storage/api_client.rb +409 -0
  4. data/lib/Aspose/Storage/api_error.rb +54 -0
  5. data/lib/Aspose/Storage/configuration.rb +203 -0
  6. data/lib/Aspose/Storage/models/aspose_response.rb +215 -0
  7. data/lib/Aspose/Storage/models/copy_file_response.rb +215 -0
  8. data/lib/Aspose/Storage/models/create_folder_response.rb +215 -0
  9. data/lib/Aspose/Storage/models/disc_usage.rb +220 -0
  10. data/lib/Aspose/Storage/models/disc_usage_response.rb +224 -0
  11. data/lib/Aspose/Storage/models/file_exist.rb +220 -0
  12. data/lib/Aspose/Storage/models/file_exist_response.rb +224 -0
  13. data/lib/Aspose/Storage/models/file_response.rb +266 -0
  14. data/lib/Aspose/Storage/models/file_version.rb +284 -0
  15. data/lib/Aspose/Storage/models/file_versions_response.rb +226 -0
  16. data/lib/Aspose/Storage/models/files_response.rb +226 -0
  17. data/lib/Aspose/Storage/models/move_file_response.rb +215 -0
  18. data/lib/Aspose/Storage/models/move_folder_response.rb +215 -0
  19. data/lib/Aspose/Storage/models/remove_file_response.rb +215 -0
  20. data/lib/Aspose/Storage/models/remove_folder_response.rb +215 -0
  21. data/lib/Aspose/Storage/models/requests/delete_file_request.rb +57 -0
  22. data/lib/Aspose/Storage/models/requests/delete_folder_request.rb +57 -0
  23. data/lib/Aspose/Storage/models/requests/get_disc_usage_request.rb +47 -0
  24. data/lib/Aspose/Storage/models/requests/get_download_request.rb +57 -0
  25. data/lib/Aspose/Storage/models/requests/get_is_exist_request.rb +57 -0
  26. data/lib/Aspose/Storage/models/requests/get_is_storage_exist_request.rb +47 -0
  27. data/lib/Aspose/Storage/models/requests/get_list_file_versions_request.rb +52 -0
  28. data/lib/Aspose/Storage/models/requests/get_list_files_request.rb +52 -0
  29. data/lib/Aspose/Storage/models/requests/post_move_file_request.rb +67 -0
  30. data/lib/Aspose/Storage/models/requests/post_move_folder_request.rb +62 -0
  31. data/lib/Aspose/Storage/models/requests/put_copy_folder_request.rb +62 -0
  32. data/lib/Aspose/Storage/models/requests/put_copy_request.rb +67 -0
  33. data/lib/Aspose/Storage/models/requests/put_create_folder_request.rb +57 -0
  34. data/lib/Aspose/Storage/models/requests/put_create_request.rb +62 -0
  35. data/lib/Aspose/Storage/models/storage_exist_response.rb +224 -0
  36. data/lib/Aspose/Storage/models/upload_response.rb +215 -0
  37. data/lib/Aspose/Storage/version.rb +29 -0
  38. data/lib/aspose_storage_cloud.rb +71 -41
  39. metadata +62 -55
  40. data/.gitignore +0 -36
  41. data/LICENSE +0 -22
  42. data/README.md +0 -40
  43. data/aspose_storage_cloud.gemspec +0 -25
  44. data/lib/aspose_storage_cloud/api/storage_api.rb +0 -800
  45. data/lib/aspose_storage_cloud/api_client.rb +0 -333
  46. data/lib/aspose_storage_cloud/api_error.rb +0 -24
  47. data/lib/aspose_storage_cloud/aspose_app.rb +0 -20
  48. data/lib/aspose_storage_cloud/configuration.rb +0 -166
  49. data/lib/aspose_storage_cloud/models/base_object.rb +0 -88
  50. data/lib/aspose_storage_cloud/models/base_response.rb +0 -53
  51. data/lib/aspose_storage_cloud/models/disc_usage.rb +0 -45
  52. data/lib/aspose_storage_cloud/models/disc_usage_response.rb +0 -61
  53. data/lib/aspose_storage_cloud/models/file_exist.rb +0 -44
  54. data/lib/aspose_storage_cloud/models/file_exist_response.rb +0 -62
  55. data/lib/aspose_storage_cloud/models/file_response.rb +0 -69
  56. data/lib/aspose_storage_cloud/models/file_version.rb +0 -85
  57. data/lib/aspose_storage_cloud/models/file_versions_response.rb +0 -63
  58. data/lib/aspose_storage_cloud/models/folder_response.rb +0 -63
  59. data/lib/aspose_storage_cloud/models/storage_exist_response.rb +0 -61
  60. data/lib/aspose_storage_cloud/version.rb +0 -3
  61. data/test/data/SampleExecuteTemplate.doc +0 -0
  62. data/test/data/SampleExecuteTemplateData.txt +0 -49
  63. data/test/data/SampleWordDocument.docx +0 -0
  64. data/test/data/buzz.png +0 -0
  65. data/test/data/testfile.txt +0 -1
  66. data/test/storage_tests.rb +0 -134
@@ -1,333 +0,0 @@
1
- require 'date'
2
- require 'json'
3
- require 'logger'
4
- require 'tempfile'
5
- require 'typhoeus'
6
- require 'uri'
7
- require 'openssl'
8
- require 'base64'
9
- require 'rexml/document'
10
-
11
- module AsposeStorageCloud
12
- class ApiClient
13
-
14
- attr_accessor :host
15
-
16
- # Defines the headers to be used in HTTP requests of all API calls by default.
17
- #
18
- # @return [Hash]
19
- attr_accessor :default_headers
20
-
21
- # Stores the HTTP response from the last API call using this API client.
22
- attr_accessor :last_response
23
-
24
- def initialize(host = nil)
25
- @host = host || Configuration.base_url
26
- @format = 'json'
27
- @user_agent = "ruby-swagger-#{VERSION}"
28
- @default_headers = {
29
- 'Content-Type' => "application/#{@format.downcase}",
30
- 'User-Agent' => @user_agent
31
- }
32
- end
33
-
34
- def call_api(http_method, path, opts = {})
35
- request = build_request(http_method, path, opts)
36
- response = request.run
37
-
38
- # record as last response
39
- @last_response = response
40
-
41
- if Configuration.debugging
42
- Configuration.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
43
- end
44
-
45
- unless response.success?
46
- fail ApiError.new(:code => response.code,
47
- :response_headers => response.headers,
48
- :response_body => response.body),
49
- response.status_message
50
- end
51
-
52
- if opts[:return_type]
53
- deserialize(response, opts[:return_type])
54
- else
55
- nil
56
- end
57
- end
58
-
59
- def build_request(http_method, path, opts = {})
60
- url = build_request_url(path)
61
- http_method = http_method.to_sym.downcase
62
-
63
- header_params = @default_headers.merge(opts[:header_params] || {})
64
- query_params = {}
65
- form_params = opts[:form_params] || {}
66
-
67
- req_opts = {
68
- :method => http_method,
69
- :headers => header_params,
70
- :params => query_params,
71
- :ssl_verifypeer => Configuration.verify_ssl,
72
- :sslcert => Configuration.cert_file,
73
- :sslkey => Configuration.key_file,
74
- :cainfo => Configuration.ssl_ca_cert,
75
- :verbose => Configuration.debugging
76
- }
77
-
78
- if [:post, :patch, :put, :delete].include?(http_method)
79
- req_body = build_request_body(header_params, form_params, opts[:body])
80
- req_opts.update :body => req_body
81
- if Configuration.debugging
82
- Configuration.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
83
- end
84
- end
85
-
86
- url = sign(url, opts[:query_params])
87
- Typhoeus::Request.new(url, req_opts)
88
-
89
- end
90
-
91
- # Signs a URI with your appSID and Key.
92
- # * :url describes the URL to sign
93
-
94
- def sign(url, query_params)
95
-
96
- fail "Please set Aspose App key and SID first. You can get App key and App SID from https://cloud.aspose.com" if AsposeApp.app_key.nil? || AsposeApp.app_sid.nil?
97
-
98
- url = url[0..-2] if url[-1].eql? '/'
99
-
100
- unless query_params.empty?
101
- url = "#{url}?"
102
- query_params.each { |key, value|
103
- url = "#{url}#{key}=#{value}&"
104
- }
105
- url = url[0..-2]
106
- end
107
-
108
- url = URI.escape(url)
109
- parsed_url = URI.parse(url)
110
-
111
- url_to_sign = "#{parsed_url.scheme}://#{parsed_url.host}#{parsed_url.path}"
112
- url_to_sign += "?#{parsed_url.query}" if parsed_url.query
113
- if parsed_url.query
114
- url_to_sign += "&appSID=#{AsposeApp.app_sid}"
115
- else
116
- url_to_sign += "?appSID=#{AsposeApp.app_sid}"
117
- end
118
-
119
- # create a signature using the private key and the URL
120
- raw_signature = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), AsposeApp.app_key, url_to_sign)
121
-
122
- #Convert raw to encoded string
123
- signature = Base64.strict_encode64(raw_signature).tr('+/', '-_')
124
-
125
- #remove invalid character
126
- signature = signature.gsub(/[=_-]/, '=' => '', '_' => '%2f', '-' => '%2b')
127
-
128
- #Define expression
129
- pat = Regexp.new('%[0-9a-f]{2}')
130
-
131
- #Replace the portion matched to the above pattern to upper case
132
- 6.times do
133
- signature = signature.sub(pat, pat.match(signature).to_s.upcase)
134
- end
135
-
136
- # prepend the server and append the signature.
137
- url_to_sign + "&signature=#{signature}"
138
-
139
- end
140
-
141
- # Deserialize the response to the given return type.
142
- #
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
- # handle file downloading - save response body into a tmp file and return the File instance
149
- return download_file(response) if return_type == 'File'
150
-
151
- # ensuring a default content type
152
- content_type = response.headers['Content-Type'] || 'application/json'
153
-
154
- unless content_type.start_with?('application/json')
155
- fail "Content-Type is not supported: #{content_type}"
156
- end
157
-
158
- begin
159
- data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
160
- rescue JSON::ParserError => e
161
- if %w(String Date DateTime).include?(return_type)
162
- data = body
163
- else
164
- raise e
165
- end
166
- end
167
-
168
- convert_to_type data, return_type
169
- end
170
-
171
- # Convert data to the given return type.
172
- def convert_to_type(data, return_type)
173
- return nil if data.nil?
174
- case return_type
175
- when 'String'
176
- data.to_s
177
- when 'Integer'
178
- data.to_i
179
- when 'Float'
180
- data.to_f
181
- when 'BOOLEAN'
182
- data == true
183
- when 'DateTime'
184
- # parse date time (expecting ISO 8601 format)
185
- DateTime.parse data
186
- when 'Date'
187
- # parse date time (expecting ISO 8601 format)
188
- Date.parse data
189
- when 'Object'
190
- # generic object, return directly
191
- data
192
- when /\AArray<(.+)>\z/
193
- # e.g. Array<Pet>
194
- sub_type = $1
195
- data.map {|item| convert_to_type(item, sub_type) }
196
- when /\AHash\<String, (.+)\>\z/
197
- # e.g. Hash<String, Integer>
198
- sub_type = $1
199
- {}.tap do |hash|
200
- data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
201
- end
202
- else
203
- # models, e.g. Pet
204
- AsposeStorageCloud.const_get(return_type).new.tap do |model|
205
- model.build_from_hash data
206
- end
207
- end
208
- end
209
-
210
- # Save response body into a file in (the defined) temporary folder, using the filename
211
- # from the "Content-Disposition" header if provided, otherwise a random filename.
212
- #
213
- # @see Configuration#temp_folder_path
214
- # @return [File] the file downloaded
215
- def download_file(response)
216
- tmp_file = Tempfile.new '', Configuration.temp_folder_path
217
- content_disposition = response.headers['Content-Disposition']
218
-
219
- if content_disposition
220
- filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
221
- path = File.join File.dirname(tmp_file), filename
222
- else
223
- path = tmp_file.path
224
- end
225
- # close and delete temp file
226
- tmp_file.close!
227
-
228
- File.open(path, 'w') { |file| file.write(response.body) }
229
- Configuration.logger.info "File written to #{path}. Please move the file to a proper "\
230
- "folder for further processing and delete the temp afterwards"
231
- File.new(path)
232
- end
233
-
234
- def build_request_url(path)
235
- # Add leading and trailing slashes to path
236
- path = "/#{path}".gsub(/\/+/, '/')
237
- URI.encode(host + path)
238
- end
239
-
240
- def build_request_body(header_params, form_params, body)
241
- # http form
242
- if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
243
- header_params['Content-Type'] == 'multipart/form-data'
244
-
245
- data = form_params.dup
246
- data.each do |key, value|
247
- if key.eql? "file"
248
- data = value
249
- break
250
- else
251
- data[key] = value.to_s if value && !value.is_a?(File)
252
- end
253
- end
254
- elsif body
255
- data = body.is_a?(String) ? body : body.to_json
256
- else
257
- data = nil
258
- end
259
- data
260
- end
261
-
262
- # Update hearder and query params based on authentication settings.
263
- def update_params_for_auth!(header_params, query_params, auth_names)
264
- Array(auth_names).each do |auth_name|
265
- auth_setting = Configuration.auth_settings[auth_name]
266
- next unless auth_setting
267
- case auth_setting[:in]
268
- when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
269
- when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
270
- else fail ArgumentError, 'Authentication token must be in `query` of `header`'
271
- end
272
- end
273
- end
274
-
275
- def user_agent=(user_agent)
276
- @user_agent = user_agent
277
- @default_headers['User-Agent'] = @user_agent
278
- end
279
-
280
- # Return Accept header based on an array of accepts provided.
281
- # @param [Array] accepts array for Accept
282
- # @return [String] the Accept header (e.g. application/json)
283
- def select_header_accept(accepts)
284
- if accepts.empty?
285
- return
286
- elsif accepts.any?{ |s| s.casecmp('application/json') == 0 }
287
- 'application/json' # look for json data by default
288
- else
289
- accepts.join(',')
290
- end
291
- end
292
-
293
- # Return Content-Type header based on an array of content types provided.
294
- # @param [Array] content_types array for Content-Type
295
- # @return [String] the Content-Type header (e.g. application/json)
296
- def select_header_content_type(content_types)
297
- if content_types.empty?
298
- 'application/json' # use application/json by default
299
- elsif content_types.any?{ |s| s.casecmp('application/json')==0 }
300
- 'application/json' # use application/json if it's included
301
- else
302
- content_types[0] # otherwise, use the first one
303
- end
304
- end
305
-
306
- # Convert object (array, hash, object, etc) to JSON string.
307
- # @param [Object] model object to be converted into JSON string
308
- # @return [String] JSON string representation of the object
309
- def object_to_http_body(model)
310
- return if model.nil?
311
- _body = nil
312
- if model.is_a?(Array)
313
- _body = model.map{|m| object_to_hash(m) }
314
- else
315
- _body = object_to_hash(model)
316
- end
317
- _body.to_json
318
- end
319
-
320
- # Convert object(non-array) to hash.
321
- # @param [Object] obj object to be converted into JSON string
322
- # @return [String] JSON string representation of the object
323
- def object_to_hash(obj)
324
- if obj.respond_to?(:to_hash)
325
- obj.to_hash
326
- else
327
- obj
328
- end
329
- end
330
-
331
-
332
- end
333
- end
@@ -1,24 +0,0 @@
1
- module AsposeStorageCloud
2
- class ApiError < StandardError
3
- attr_reader :code, :response_headers, :response_body
4
-
5
- # Usage examples:
6
- # ApiError.new
7
- # ApiError.new("message")
8
- # ApiError.new(:code => 500, :response_headers => {}, :response_body => "")
9
- # ApiError.new(:code => 404, :message => "Not Found")
10
- def initialize(arg = nil)
11
- if arg.is_a? Hash
12
- arg.each do |k, v|
13
- if k.to_s == 'message'
14
- super v
15
- else
16
- instance_variable_set "@#{k}", v
17
- end
18
- end
19
- else
20
- super arg
21
- end
22
- end
23
- end
24
- end
@@ -1,20 +0,0 @@
1
- module AsposeStorageCloud
2
- class AsposeApp
3
-
4
- @@app_key = nil
5
- @app_sid = nil
6
-
7
- def AsposeApp.app_key_and_sid(app_key, app_sid)
8
- @@app_key = app_key
9
- @@app_sid = app_sid
10
- end
11
-
12
- def AsposeApp.app_key
13
- @@app_key
14
- end
15
-
16
- def AsposeApp.app_sid
17
- @@app_sid
18
- end
19
- end
20
- end
@@ -1,166 +0,0 @@
1
- require 'uri'
2
- require 'singleton'
3
-
4
- module AsposeStorageCloud
5
- class Configuration
6
-
7
- include Singleton
8
-
9
- # Default api client
10
- attr_accessor :api_client
11
-
12
- # Defines url scheme
13
- attr_accessor :scheme
14
-
15
- # Defines url host
16
- attr_accessor :host
17
-
18
- # Defines url base path
19
- attr_accessor :base_path
20
-
21
- # Defines API keys used with API Key authentications.
22
- #
23
- # @return [Hash] key: parameter name, value: parameter value (API key)
24
- #
25
- # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
26
- # config.api_key['api_key'] = 'xxx'
27
- attr_accessor :api_key
28
-
29
- # Defines API key prefixes used with API Key authentications.
30
- #
31
- # @return [Hash] key: parameter name, value: API key prefix
32
- #
33
- # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
34
- # config.api_key_prefix['api_key'] = 'Token'
35
- attr_accessor :api_key_prefix
36
-
37
- # Defines the username used with HTTP basic authentication.
38
- #
39
- # @return [String]
40
- attr_accessor :username
41
-
42
- # Defines the password used with HTTP basic authentication.
43
- #
44
- # @return [String]
45
- attr_accessor :password
46
-
47
- # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
48
- # details will be logged with `logger.debug` (see the `logger` attribute).
49
- # Default to false.
50
- #
51
- # @return [true, false]
52
- attr_accessor :debugging
53
-
54
- # Defines the logger used for debugging.
55
- # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
56
- #
57
- # @return [#debug]
58
- attr_accessor :logger
59
-
60
- # Defines the temporary folder to store downloaded files
61
- # (for API endpoints that have file response).
62
- # Default to use `Tempfile`.
63
- #
64
- # @return [String]
65
- attr_accessor :temp_folder_path
66
-
67
- ### TLS/SSL
68
- # Set this to false to skip verifying SSL certificate when calling API from https server.
69
- # Default to true.
70
- #
71
- # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
72
- #
73
- # @return [true, false]
74
- attr_accessor :verify_ssl
75
-
76
- # Set this to customize the certificate file to verify the peer.
77
- #
78
- # @return [String] the path to the certificate file
79
- #
80
- # @see The `cainfo` option of Typhoeus, `--cert` option of libcurl. Related source code:
81
- # https://github.com/typhoeus/typhoeus/blob/master/lib/typhoeus/easy_factory.rb#L145
82
- attr_accessor :ssl_ca_cert
83
-
84
- # Client certificate file (for client certificate)
85
- attr_accessor :cert_file
86
-
87
- # Client private key file (for client certificate)
88
- attr_accessor :key_file
89
-
90
- attr_accessor :inject_format
91
-
92
- attr_accessor :force_ending_format
93
-
94
- class << self
95
- def method_missing(method_name, *args, &block)
96
- config = Configuration.instance
97
- if config.respond_to?(method_name)
98
- config.send(method_name, *args, &block)
99
- else
100
- super
101
- end
102
- end
103
- end
104
-
105
- def initialize
106
- @scheme = 'http'
107
- @host = 'api.aspose.cloud'
108
- @base_path = '/v1.1'
109
- @api_key = {}
110
- @api_key_prefix = {}
111
- @verify_ssl = true
112
- @cert_file = nil
113
- @key_file = nil
114
- @debugging = false
115
- @inject_format = false
116
- @force_ending_format = false
117
- @logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
118
- end
119
-
120
- def api_client
121
- @api_client ||= ApiClient.new
122
- end
123
-
124
- def scheme=(scheme)
125
- # remove :// from scheme
126
- @scheme = scheme.sub(/:\/\//, '')
127
- end
128
-
129
- def host=(host)
130
- # remove http(s):// and anything after a slash
131
- @host = host.sub(/https?:\/\//, '').split('/').first
132
- end
133
-
134
- def base_path=(base_path)
135
- # Add leading and trailing slashes to base_path
136
- @base_path = "/#{base_path}".gsub(/\/+/, '/')
137
- @base_path = "" if @base_path == "/"
138
- end
139
-
140
- def base_url
141
- url = "#{scheme}://#{[host, base_path].join('/').gsub(/\/+/, '/')}".sub(/\/+\z/, '')
142
- URI.encode(url)
143
- end
144
-
145
- # Gets API key (with prefix if set).
146
- # @param [String] param_name the parameter name of API key auth
147
- def api_key_with_prefix(param_name)
148
- if @api_key_prefix[param_name]
149
- "#{@api_key_prefix[param_name]} #{@api_key[param_name]}"
150
- else
151
- @api_key[param_name]
152
- end
153
- end
154
-
155
- # Gets Basic Auth token string
156
- def basic_auth_token
157
- 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
158
- end
159
-
160
- # Returns Auth Settings hash for api client.
161
- def auth_settings
162
- {
163
- }
164
- end
165
- end
166
- end