groupdocs_merger_cloud 19.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/groupdocs_merger_cloud.rb +72 -0
- data/lib/groupdocs_merger_cloud/api/document_api.rb +411 -0
- data/lib/groupdocs_merger_cloud/api/file_api.rb +729 -0
- data/lib/groupdocs_merger_cloud/api/folder_api.rb +694 -0
- data/lib/groupdocs_merger_cloud/api/info_api.rb +266 -0
- data/lib/groupdocs_merger_cloud/api/pages_api.rb +702 -0
- data/lib/groupdocs_merger_cloud/api/security_api.rb +528 -0
- data/lib/groupdocs_merger_cloud/api/storage_api.rb +541 -0
- data/lib/groupdocs_merger_cloud/api_client.rb +380 -0
- data/lib/groupdocs_merger_cloud/api_error.rb +58 -0
- data/lib/groupdocs_merger_cloud/configuration.rb +95 -0
- data/lib/groupdocs_merger_cloud/models/disc_usage.rb +234 -0
- data/lib/groupdocs_merger_cloud/models/document_result.rb +214 -0
- data/lib/groupdocs_merger_cloud/models/error.rb +244 -0
- data/lib/groupdocs_merger_cloud/models/error_details.rb +229 -0
- data/lib/groupdocs_merger_cloud/models/extract_options.rb +318 -0
- data/lib/groupdocs_merger_cloud/models/file_info.rb +244 -0
- data/lib/groupdocs_merger_cloud/models/file_version.rb +289 -0
- data/lib/groupdocs_merger_cloud/models/file_versions.rb +216 -0
- data/lib/groupdocs_merger_cloud/models/files_list.rb +216 -0
- data/lib/groupdocs_merger_cloud/models/files_upload_result.rb +228 -0
- data/lib/groupdocs_merger_cloud/models/format.rb +224 -0
- data/lib/groupdocs_merger_cloud/models/formats_result.rb +216 -0
- data/lib/groupdocs_merger_cloud/models/info_result.rb +251 -0
- data/lib/groupdocs_merger_cloud/models/join_item.rb +308 -0
- data/lib/groupdocs_merger_cloud/models/join_options.rb +226 -0
- data/lib/groupdocs_merger_cloud/models/move_options.rb +254 -0
- data/lib/groupdocs_merger_cloud/models/multi_document_result.rb +216 -0
- data/lib/groupdocs_merger_cloud/models/object_exist.rb +234 -0
- data/lib/groupdocs_merger_cloud/models/options.rb +224 -0
- data/lib/groupdocs_merger_cloud/models/orientation_options.rb +349 -0
- data/lib/groupdocs_merger_cloud/models/page_info.rb +264 -0
- data/lib/groupdocs_merger_cloud/models/page_options.rb +318 -0
- data/lib/groupdocs_merger_cloud/models/password_result.rb +219 -0
- data/lib/groupdocs_merger_cloud/models/preview_options.rb +379 -0
- data/lib/groupdocs_merger_cloud/models/remove_options.rb +318 -0
- data/lib/groupdocs_merger_cloud/models/rotate_options.rb +349 -0
- data/lib/groupdocs_merger_cloud/models/split_options.rb +349 -0
- data/lib/groupdocs_merger_cloud/models/storage_exist.rb +219 -0
- data/lib/groupdocs_merger_cloud/models/storage_file.rb +264 -0
- data/lib/groupdocs_merger_cloud/models/swap_options.rb +254 -0
- data/lib/groupdocs_merger_cloud/models/update_password_options.rb +234 -0
- data/lib/groupdocs_merger_cloud/version.rb +29 -0
- metadata +155 -0
@@ -0,0 +1,380 @@
|
|
1
|
+
# -----------------------------------------------------------------------------------
|
2
|
+
# <copyright company="Aspose Pty Ltd" file="api_client.rb">
|
3
|
+
# Copyright (c) 2003-2019 Aspose Pty Ltd
|
4
|
+
# </copyright>
|
5
|
+
# <summary>
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in all
|
14
|
+
# copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
# </summary>
|
24
|
+
# -----------------------------------------------------------------------------------
|
25
|
+
|
26
|
+
require 'date'
|
27
|
+
require 'json'
|
28
|
+
require 'logger'
|
29
|
+
require 'tempfile'
|
30
|
+
require 'faraday'
|
31
|
+
require 'mimemagic'
|
32
|
+
require 'addressable'
|
33
|
+
require_relative 'version'
|
34
|
+
require_relative 'api_error'
|
35
|
+
|
36
|
+
module GroupDocsMergerCloud
|
37
|
+
#
|
38
|
+
# api client is mainly responsible for making the HTTP call to the API backend.
|
39
|
+
#
|
40
|
+
class ApiClient
|
41
|
+
# The Configuration object holding settings to be used in the API client.
|
42
|
+
attr_accessor :config
|
43
|
+
|
44
|
+
# Defines the headers to be used in HTTP requests of all API calls by default.
|
45
|
+
#
|
46
|
+
# @return [Hash]
|
47
|
+
attr_accessor :default_headers
|
48
|
+
|
49
|
+
# Initializes the ApiClient
|
50
|
+
# @option config [Configuration] Configuration for initializing the object
|
51
|
+
def initialize(config)
|
52
|
+
@config = config
|
53
|
+
@default_headers = {
|
54
|
+
'Content-Type' => config.api_version == '' ? "application/x-www-form-urlencoded" : "application/json",
|
55
|
+
'x-groupdocs-client' => "ruby sdk",
|
56
|
+
'x-groupdocs-version' => GroupDocsMergerCloud::VERSION.to_s
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
# Call an API with given options.
|
61
|
+
#
|
62
|
+
# @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
|
63
|
+
# the data deserialized from response body (could be nil), response status code and response headers.
|
64
|
+
def call_api(http_method, path, opts = {})
|
65
|
+
response = build_request(http_method, path, opts)
|
66
|
+
download_file response if opts[:return_type] == 'File'
|
67
|
+
if @config.debugging
|
68
|
+
@config.logger.debug "'HTTP' response body '~BEGIN~'\n #{response.body}\n'~END~'\n"
|
69
|
+
end
|
70
|
+
|
71
|
+
unless response.success?
|
72
|
+
raise ApiError.new(:code => response.status, :response_body => response.body)
|
73
|
+
end
|
74
|
+
|
75
|
+
data = deserialize(response, opts[:return_type]) if opts[:return_type]
|
76
|
+
[data, response.status, response.headers]
|
77
|
+
end
|
78
|
+
|
79
|
+
# Builds the HTTP request
|
80
|
+
#
|
81
|
+
# @param [String] http_method HTTP method/verb (e.g. POST)
|
82
|
+
# @param [String] path URL path (e.g. /account/new)
|
83
|
+
# @option opts [Hash] :header_params Header parameters
|
84
|
+
# @option opts [Hash] :query_params Query parameters
|
85
|
+
# @option opts [Hash] :form_params Query parameters
|
86
|
+
# @option opts [Object] :body HTTP body (JSON/XML)
|
87
|
+
# @return [Faraday::Response] A Faraday Response
|
88
|
+
def build_request(http_method, path, opts = {})
|
89
|
+
url = build_request_url(path)
|
90
|
+
http_method = http_method.to_sym.downcase
|
91
|
+
|
92
|
+
header_params = @default_headers.merge(opts[:header_params] || {})
|
93
|
+
query_params = opts[:query_params] || {}
|
94
|
+
form_params = opts[:form_params] || {}
|
95
|
+
body = opts[:body] if opts[:body] || nil?
|
96
|
+
|
97
|
+
update_params_for_oauth! header_params, opts[:access_token]
|
98
|
+
|
99
|
+
req_opts = {
|
100
|
+
:method => http_method,
|
101
|
+
:headers => header_params,
|
102
|
+
:params => query_params,
|
103
|
+
:body => body
|
104
|
+
}
|
105
|
+
|
106
|
+
if [:post, :patch, :put, :delete].include?(http_method)
|
107
|
+
req_body = build_request_body(header_params, form_params, opts[:body])
|
108
|
+
req_opts.update :body => req_body
|
109
|
+
if @config.debugging
|
110
|
+
@config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
conn = Faraday.new url, { :params => query_params, :headers => header_params } do |f|
|
115
|
+
f.request :multipart
|
116
|
+
f.request :url_encoded
|
117
|
+
f.adapter Faraday.default_adapter
|
118
|
+
end
|
119
|
+
|
120
|
+
case http_method
|
121
|
+
when :post
|
122
|
+
return conn.post url, req_opts[:body]
|
123
|
+
when :put
|
124
|
+
return conn.put url, req_opts[:body]
|
125
|
+
when :get
|
126
|
+
return conn.get url, req_opts[:body]
|
127
|
+
else
|
128
|
+
return conn.delete url do |c|
|
129
|
+
c.body = req_opts[:body]
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
# Check if the given MIME is a JSON MIME.
|
135
|
+
# JSON MIME examples:
|
136
|
+
# application/json
|
137
|
+
# application/json; charset=UTF8
|
138
|
+
# APPLICATION/JSON
|
139
|
+
# */*
|
140
|
+
# @param [String] mime MIME
|
141
|
+
# @return [Boolean] True if the MIME is application/json
|
142
|
+
def json_mime?(mime)
|
143
|
+
(mime == "*/*") || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
|
144
|
+
end
|
145
|
+
|
146
|
+
# Deserialize the response to the given return type.
|
147
|
+
#
|
148
|
+
# @param [Response] response HTTP response
|
149
|
+
# @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
|
150
|
+
def deserialize(response, return_type)
|
151
|
+
body = response.body
|
152
|
+
|
153
|
+
# handle file downloading - return the File instance processed in request callbacks
|
154
|
+
# note that response body is empty when the file is written in chunks in request on_body callback
|
155
|
+
return @tempfile if return_type == 'File'
|
156
|
+
|
157
|
+
return nil if body.nil? || body.empty?
|
158
|
+
|
159
|
+
# return response body directly for String return type
|
160
|
+
return body if return_type == 'String'
|
161
|
+
|
162
|
+
# ensuring a default content type
|
163
|
+
content_type = response.headers['Content-Type'] || 'application/json'
|
164
|
+
|
165
|
+
raise "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
|
166
|
+
|
167
|
+
begin
|
168
|
+
data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
|
169
|
+
rescue JSON::ParserError => e
|
170
|
+
if %w[String Date DateTime].include?(return_type)
|
171
|
+
data = body
|
172
|
+
else
|
173
|
+
raise e
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
convert_to_type data, return_type
|
178
|
+
end
|
179
|
+
|
180
|
+
# Convert data to the given return type.
|
181
|
+
# @param [Object] data Data to be converted
|
182
|
+
# @param [String] return_type Return type
|
183
|
+
# @return [Mixed] Data in a particular type
|
184
|
+
def convert_to_type(data, return_type)
|
185
|
+
return nil if data.nil?
|
186
|
+
case return_type
|
187
|
+
when 'String'
|
188
|
+
data.to_s
|
189
|
+
when 'Integer'
|
190
|
+
data.to_i
|
191
|
+
when 'Float'
|
192
|
+
data.to_f
|
193
|
+
when 'BOOLEAN'
|
194
|
+
data == true
|
195
|
+
when 'DateTime'
|
196
|
+
# parse date time (expecting ISO 8601 format)
|
197
|
+
DateTime.parse data
|
198
|
+
when 'Date'
|
199
|
+
# parse date time (expecting ISO 8601 format)
|
200
|
+
Date.parse data
|
201
|
+
when 'Object'
|
202
|
+
# generic object (usually a Hash), return directly
|
203
|
+
data
|
204
|
+
when /\AArray<(.+)>\z/
|
205
|
+
# e.g. Array<Pet>
|
206
|
+
sub_type = $1
|
207
|
+
data.map {|item| convert_to_type(item, sub_type) }
|
208
|
+
when /\AHash\<String, (.+)\>\z/
|
209
|
+
# e.g. Hash<String, Integer>
|
210
|
+
sub_type = $1
|
211
|
+
{}.tap do |hash|
|
212
|
+
data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
|
213
|
+
end
|
214
|
+
else
|
215
|
+
# models, e.g. Pet
|
216
|
+
GroupDocsMergerCloud.const_get(return_type).new.tap do |model|
|
217
|
+
model.build_from_hash data
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
# Save response body into a file in (the defined) temporary folder, using the filename
|
223
|
+
# from the "Content-Disposition" header if provided, otherwise a random filename.
|
224
|
+
# The response body is written to the file in chunks in order to handle files which
|
225
|
+
# size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
|
226
|
+
# process can use.
|
227
|
+
#
|
228
|
+
# @see Configuration#temp_folder_path
|
229
|
+
def download_file(response)
|
230
|
+
tempfile = nil
|
231
|
+
encoding = nil
|
232
|
+
content_disposition = response.headers['Content-Disposition']
|
233
|
+
if content_disposition and content_disposition =~ /filename=/i
|
234
|
+
filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
|
235
|
+
prefix = sanitize_filename(filename)
|
236
|
+
else
|
237
|
+
prefix = 'download-'
|
238
|
+
end
|
239
|
+
prefix += '-' unless prefix.end_with?('-')
|
240
|
+
encoding = response.body.encoding
|
241
|
+
tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
|
242
|
+
@tempfile = tempfile
|
243
|
+
tempfile.write(response.body)
|
244
|
+
response.on_complete do |resp|
|
245
|
+
tempfile.close
|
246
|
+
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
247
|
+
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
248
|
+
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
249
|
+
"explicitly with `tempfile.delete`"
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
# Sanitize filename by removing path.
|
254
|
+
# e.g. ../../sun.gif becomes sun.gif
|
255
|
+
#
|
256
|
+
# @param [String] filename the filename to be sanitized
|
257
|
+
# @return [String] the sanitized filename
|
258
|
+
def sanitize_filename(filename)
|
259
|
+
filename.gsub(/.*[\/\\]/, '')
|
260
|
+
end
|
261
|
+
|
262
|
+
def build_request_url(path)
|
263
|
+
# Add leading and trailing slashes to path
|
264
|
+
path = "/#{path}".gsub(/\/+/, '/')
|
265
|
+
Addressable::URI.encode(@config.api_base_url + @config.api_version + path)
|
266
|
+
end
|
267
|
+
|
268
|
+
# Builds the HTTP request body
|
269
|
+
#
|
270
|
+
# @param [Hash] header_params Header parameters
|
271
|
+
# @param [Hash] form_params Query parameters
|
272
|
+
# @param [Object] body HTTP body (JSON/XML)
|
273
|
+
# @return [String] HTTP body data in the form of string
|
274
|
+
def build_request_body(header_params, form_params, body)
|
275
|
+
# http form
|
276
|
+
if body
|
277
|
+
data = body.is_a?(String) ? body : body.to_json
|
278
|
+
elsif header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
|
279
|
+
header_params['Content-Type'] == 'multipart/form-data'
|
280
|
+
data = {}
|
281
|
+
form_params.each do |key, value|
|
282
|
+
case value
|
283
|
+
when ::File
|
284
|
+
data[key] = Faraday::UploadIO.new(value.path, MimeMagic.by_magic(value).to_s, key)
|
285
|
+
when ::Array, nil
|
286
|
+
data[key] = value
|
287
|
+
else
|
288
|
+
data[key] = value.to_s
|
289
|
+
end
|
290
|
+
end
|
291
|
+
else
|
292
|
+
data = nil
|
293
|
+
end
|
294
|
+
data
|
295
|
+
end
|
296
|
+
|
297
|
+
# Update hearder and query params based on authentication settings.
|
298
|
+
#
|
299
|
+
# @param [Hash] header_params Header parameters
|
300
|
+
# @param [String] access_token OAuth access token
|
301
|
+
def update_params_for_oauth!(header_params, access_token)
|
302
|
+
header_params["Authorization"] = "Bearer #{access_token}"
|
303
|
+
end
|
304
|
+
|
305
|
+
# Sets user agent in HTTP header
|
306
|
+
#
|
307
|
+
# @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
|
308
|
+
def user_agent=(user_agent)
|
309
|
+
@user_agent = user_agent
|
310
|
+
@default_headers['User-Agent'] = @user_agent
|
311
|
+
end
|
312
|
+
|
313
|
+
# Return Accept header based on an array of accepts provided.
|
314
|
+
# @param [Array] accepts array for Accept
|
315
|
+
# @return [String] the Accept header (e.g. application/json)
|
316
|
+
def select_header_accept(accepts)
|
317
|
+
return nil if accepts.nil? || accepts.empty?
|
318
|
+
# use JSON when present, otherwise use all of the provided
|
319
|
+
json_accept = accepts.find { |s| json_mime?(s) }
|
320
|
+
return json_accept || accepts.join(',')
|
321
|
+
end
|
322
|
+
|
323
|
+
# Return Content-Type header based on an array of content types provided.
|
324
|
+
# @param [Array] content_types array for Content-Type
|
325
|
+
# @return [String] the Content-Type header (e.g. application/json)
|
326
|
+
def select_header_content_type(content_types)
|
327
|
+
# use application/json by default
|
328
|
+
return 'application/json' if content_types.nil? || content_types.empty?
|
329
|
+
# use JSON when present, otherwise use the first one
|
330
|
+
json_content_type = content_types.find { |s| json_mime?(s) }
|
331
|
+
return json_content_type || content_types.first
|
332
|
+
end
|
333
|
+
|
334
|
+
# Convert object (array, hash, object, etc) to JSON string.
|
335
|
+
# @param [Object] model object to be converted into JSON string
|
336
|
+
# @return [String] JSON string representation of the object
|
337
|
+
def object_to_http_body(model)
|
338
|
+
return '"' + model + '"' if model.is_a?(String)
|
339
|
+
return model if model.nil?
|
340
|
+
local_body = nil
|
341
|
+
if model.is_a?(Array)
|
342
|
+
local_body = model.map { |m| object_to_hash(m) }
|
343
|
+
else
|
344
|
+
local_body = object_to_hash(model)
|
345
|
+
end
|
346
|
+
local_body.to_json
|
347
|
+
end
|
348
|
+
|
349
|
+
# Convert object(non-array) to hash.
|
350
|
+
# @param [Object] obj object to be converted into JSON string
|
351
|
+
# @return [String] JSON string representation of the object
|
352
|
+
def object_to_hash(obj)
|
353
|
+
if obj.respond_to?(:to_hash)
|
354
|
+
obj.to_hash
|
355
|
+
else
|
356
|
+
obj
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
# Build parameter value according to the given collection format.
|
361
|
+
# @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
|
362
|
+
def build_collection_param(param, collection_format)
|
363
|
+
case collection_format
|
364
|
+
when :csv
|
365
|
+
param.join(',')
|
366
|
+
when :ssv
|
367
|
+
param.join(' ')
|
368
|
+
when :tsv
|
369
|
+
param.join("\t")
|
370
|
+
when :pipes
|
371
|
+
param.join('|')
|
372
|
+
when :multi
|
373
|
+
# return the array directly as faraday will handle it as expected
|
374
|
+
param
|
375
|
+
else
|
376
|
+
raise "unknown collection format: #{collection_format.inspect}"
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# -----------------------------------------------------------------------------------
|
2
|
+
# <copyright company="Aspose Pty Ltd" file="api_error.rb">
|
3
|
+
# Copyright (c) 2003-2019 Aspose Pty Ltd
|
4
|
+
# </copyright>
|
5
|
+
# <summary>
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in all
|
14
|
+
# copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
# </summary>
|
24
|
+
# -----------------------------------------------------------------------------------
|
25
|
+
|
26
|
+
module GroupDocsMergerCloud
|
27
|
+
#
|
28
|
+
# ApiError class for error handling
|
29
|
+
#
|
30
|
+
class ApiError < StandardError
|
31
|
+
attr_reader :code
|
32
|
+
attr_reader :message
|
33
|
+
|
34
|
+
# Usage examples:
|
35
|
+
# ApiError.new
|
36
|
+
# ApiError.new(:code => 500, :response_body => "")
|
37
|
+
def initialize(arg = nil)
|
38
|
+
if arg.is_a? Hash
|
39
|
+
|
40
|
+
if arg.key?(:response_body) then
|
41
|
+
data = JSON.parse(arg[:response_body], :symbolize_names => true)
|
42
|
+
if !data.nil? && !data[:error].nil? then
|
43
|
+
@message = data[:error]
|
44
|
+
elsif !data.nil? && !data[:Error].nil? && !data[:Error][:Message].nil? then
|
45
|
+
@message = data[:Error][:Message]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
if arg.key?(:arg) then
|
50
|
+
@code = arg[:Code]
|
51
|
+
end
|
52
|
+
|
53
|
+
else
|
54
|
+
super arg
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# ------------------------------------------------------------------------------------
|
2
|
+
# <copyright company="Aspose Pty Ltd" file="configuration.rb">
|
3
|
+
# Copyright (c) 2003-2019 Aspose Pty Ltd
|
4
|
+
# </copyright>
|
5
|
+
# <summary>
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
# of this software and associated documentation files (the "Software"), to deal
|
8
|
+
# in the Software without restriction, including without limitation the rights
|
9
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
# copies of the Software, and to permit persons to whom the Software is
|
11
|
+
# furnished to do so, subject to the following conditions:
|
12
|
+
#
|
13
|
+
# The above copyright notice and this permission notice shall be included in all
|
14
|
+
# copies or substantial portions of the Software.
|
15
|
+
#
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
22
|
+
# SOFTWARE.
|
23
|
+
# </summary>
|
24
|
+
# ------------------------------------------------------------------------------------
|
25
|
+
|
26
|
+
module GroupDocsMergerCloud
|
27
|
+
#
|
28
|
+
# Class for storing API configuration info
|
29
|
+
#
|
30
|
+
class Configuration
|
31
|
+
|
32
|
+
# Api base url, default is 'https://api.groupdocs.cloud'
|
33
|
+
#
|
34
|
+
# @return [String] Api base url
|
35
|
+
attr_accessor :api_base_url
|
36
|
+
|
37
|
+
# Api version, default is '/v1.0'
|
38
|
+
#
|
39
|
+
# @return [String] Api version
|
40
|
+
attr_accessor :api_version
|
41
|
+
|
42
|
+
# Application identifier (App SID)
|
43
|
+
#
|
44
|
+
# @return [String] Application identifier (App SID)
|
45
|
+
attr_accessor :app_sid
|
46
|
+
|
47
|
+
# Application private key (App Key)
|
48
|
+
#
|
49
|
+
# @return [String] Application private key (App Key)
|
50
|
+
attr_accessor :app_key
|
51
|
+
|
52
|
+
# Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
|
53
|
+
# details will be logged with `logger.debug` (see the `logger` attribute).
|
54
|
+
# Default value is false.
|
55
|
+
#
|
56
|
+
# @return [true, false]
|
57
|
+
attr_accessor :debugging
|
58
|
+
|
59
|
+
# Defines the logger used for debugging.
|
60
|
+
# Default to `Rails.logger` (when in Rails) or logging to STDOUT.
|
61
|
+
#
|
62
|
+
# @return [#logger]
|
63
|
+
attr_accessor :logger
|
64
|
+
|
65
|
+
# Defines the temporary folder to store downloaded files
|
66
|
+
# (for API endpoints that have file response).
|
67
|
+
# System temporary folder is used by default.
|
68
|
+
#
|
69
|
+
# @return [String]
|
70
|
+
attr_accessor :temp_folder_path
|
71
|
+
|
72
|
+
# Set this to false to skip client side validation in the operation.
|
73
|
+
# Default to true.
|
74
|
+
# @return [true, false]
|
75
|
+
attr_accessor :client_side_validation
|
76
|
+
|
77
|
+
# Initializes new instance of Configuration
|
78
|
+
#
|
79
|
+
# @param [app_sid] Application identifier (App SID)
|
80
|
+
# @param [app_key] Application private key (App Key)
|
81
|
+
# @return [Configuration] New instance of Configuration
|
82
|
+
def initialize(app_sid, app_key)
|
83
|
+
@api_base_url = "https://api.groupdocs.cloud"
|
84
|
+
@api_version = '/v1.0'
|
85
|
+
@app_sid = app_sid
|
86
|
+
@app_key = app_key
|
87
|
+
@client_side_validation = true
|
88
|
+
@debugging = false
|
89
|
+
@logger = defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
90
|
+
|
91
|
+
yield(self) if block_given?
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|