groupdocs_viewer_cloud 18.7

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 (106) hide show
  1. checksums.yaml +7 -0
  2. data/lib/groupdocs_viewer_cloud.rb +104 -0
  3. data/lib/groupdocs_viewer_cloud/api/viewer_api.rb +5296 -0
  4. data/lib/groupdocs_viewer_cloud/api_client.rb +390 -0
  5. data/lib/groupdocs_viewer_cloud/api_error.rb +56 -0
  6. data/lib/groupdocs_viewer_cloud/configuration.rb +95 -0
  7. data/lib/groupdocs_viewer_cloud/models/attachment.rb +216 -0
  8. data/lib/groupdocs_viewer_cloud/models/attachment_collection.rb +228 -0
  9. data/lib/groupdocs_viewer_cloud/models/attachment_info.rb +226 -0
  10. data/lib/groupdocs_viewer_cloud/models/cad_options.rb +270 -0
  11. data/lib/groupdocs_viewer_cloud/models/cells_options.rb +296 -0
  12. data/lib/groupdocs_viewer_cloud/models/document_info.rb +282 -0
  13. data/lib/groupdocs_viewer_cloud/models/document_info_options.rb +348 -0
  14. data/lib/groupdocs_viewer_cloud/models/email_options.rb +228 -0
  15. data/lib/groupdocs_viewer_cloud/models/field_label.rb +216 -0
  16. data/lib/groupdocs_viewer_cloud/models/file_response.rb +196 -0
  17. data/lib/groupdocs_viewer_cloud/models/font_collection.rb +208 -0
  18. data/lib/groupdocs_viewer_cloud/models/font_family.rb +206 -0
  19. data/lib/groupdocs_viewer_cloud/models/format.rb +216 -0
  20. data/lib/groupdocs_viewer_cloud/models/format_collection.rb +208 -0
  21. data/lib/groupdocs_viewer_cloud/models/html_attachment_page_collection.rb +238 -0
  22. data/lib/groupdocs_viewer_cloud/models/html_options.rb +428 -0
  23. data/lib/groupdocs_viewer_cloud/models/html_page.rb +228 -0
  24. data/lib/groupdocs_viewer_cloud/models/html_page_collection.rb +228 -0
  25. data/lib/groupdocs_viewer_cloud/models/image_attachment_page_collection.rb +238 -0
  26. data/lib/groupdocs_viewer_cloud/models/image_options.rb +408 -0
  27. data/lib/groupdocs_viewer_cloud/models/image_page.rb +216 -0
  28. data/lib/groupdocs_viewer_cloud/models/image_page_collection.rb +238 -0
  29. data/lib/groupdocs_viewer_cloud/models/page_info.rb +268 -0
  30. data/lib/groupdocs_viewer_cloud/models/page_info_collection.rb +208 -0
  31. data/lib/groupdocs_viewer_cloud/models/pdf_file_info.rb +236 -0
  32. data/lib/groupdocs_viewer_cloud/models/pdf_file_options.rb +348 -0
  33. data/lib/groupdocs_viewer_cloud/models/pdf_options.rb +236 -0
  34. data/lib/groupdocs_viewer_cloud/models/project_options.rb +216 -0
  35. data/lib/groupdocs_viewer_cloud/models/render_options.rb +368 -0
  36. data/lib/groupdocs_viewer_cloud/models/render_options_base.rb +348 -0
  37. data/lib/groupdocs_viewer_cloud/models/reorder_options.rb +226 -0
  38. data/lib/groupdocs_viewer_cloud/models/requests/html_create_attachment_pages_cache_request.rb +65 -0
  39. data/lib/groupdocs_viewer_cloud/models/requests/html_create_pages_cache_from_content_request.rb +65 -0
  40. data/lib/groupdocs_viewer_cloud/models/requests/html_create_pages_cache_from_url_request.rb +65 -0
  41. data/lib/groupdocs_viewer_cloud/models/requests/html_create_pages_cache_request.rb +61 -0
  42. data/lib/groupdocs_viewer_cloud/models/requests/html_create_pdf_file_from_content_request.rb +65 -0
  43. data/lib/groupdocs_viewer_cloud/models/requests/html_create_pdf_file_from_url_request.rb +65 -0
  44. data/lib/groupdocs_viewer_cloud/models/requests/html_create_pdf_file_request.rb +61 -0
  45. data/lib/groupdocs_viewer_cloud/models/requests/html_delete_attachment_pages_cache_request.rb +57 -0
  46. data/lib/groupdocs_viewer_cloud/models/requests/html_delete_pages_cache_request.rb +53 -0
  47. data/lib/groupdocs_viewer_cloud/models/requests/html_get_attachment_info_request.rb +65 -0
  48. data/lib/groupdocs_viewer_cloud/models/requests/html_get_attachment_info_with_options_request.rb +61 -0
  49. data/lib/groupdocs_viewer_cloud/models/requests/html_get_attachment_page_request.rb +109 -0
  50. data/lib/groupdocs_viewer_cloud/models/requests/html_get_attachment_page_resource_request.rb +65 -0
  51. data/lib/groupdocs_viewer_cloud/models/requests/html_get_attachment_pages_request.rb +113 -0
  52. data/lib/groupdocs_viewer_cloud/models/requests/html_get_attachment_request.rb +61 -0
  53. data/lib/groupdocs_viewer_cloud/models/requests/html_get_attachments_request.rb +57 -0
  54. data/lib/groupdocs_viewer_cloud/models/requests/html_get_document_info_from_content_request.rb +61 -0
  55. data/lib/groupdocs_viewer_cloud/models/requests/html_get_document_info_from_url_request.rb +69 -0
  56. data/lib/groupdocs_viewer_cloud/models/requests/html_get_document_info_from_url_with_options_request.rb +61 -0
  57. data/lib/groupdocs_viewer_cloud/models/requests/html_get_document_info_request.rb +65 -0
  58. data/lib/groupdocs_viewer_cloud/models/requests/html_get_document_info_with_options_request.rb +57 -0
  59. data/lib/groupdocs_viewer_cloud/models/requests/html_get_page_request.rb +101 -0
  60. data/lib/groupdocs_viewer_cloud/models/requests/html_get_page_resource_request.rb +61 -0
  61. data/lib/groupdocs_viewer_cloud/models/requests/html_get_pages_from_url_request.rb +109 -0
  62. data/lib/groupdocs_viewer_cloud/models/requests/html_get_pages_request.rb +105 -0
  63. data/lib/groupdocs_viewer_cloud/models/requests/html_get_pdf_file_from_url_request.rb +77 -0
  64. data/lib/groupdocs_viewer_cloud/models/requests/html_get_pdf_file_request.rb +73 -0
  65. data/lib/groupdocs_viewer_cloud/models/requests/html_get_zip_with_attachment_pages_request.rb +113 -0
  66. data/lib/groupdocs_viewer_cloud/models/requests/html_get_zip_with_pages_request.rb +105 -0
  67. data/lib/groupdocs_viewer_cloud/models/requests/html_transform_pages_request.rb +57 -0
  68. data/lib/groupdocs_viewer_cloud/models/requests/image_create_attachment_pages_cache_request.rb +65 -0
  69. data/lib/groupdocs_viewer_cloud/models/requests/image_create_pages_cache_from_content_request.rb +65 -0
  70. data/lib/groupdocs_viewer_cloud/models/requests/image_create_pages_cache_from_url_request.rb +65 -0
  71. data/lib/groupdocs_viewer_cloud/models/requests/image_create_pages_cache_request.rb +61 -0
  72. data/lib/groupdocs_viewer_cloud/models/requests/image_create_pdf_file_from_content_request.rb +65 -0
  73. data/lib/groupdocs_viewer_cloud/models/requests/image_create_pdf_file_from_url_request.rb +65 -0
  74. data/lib/groupdocs_viewer_cloud/models/requests/image_create_pdf_file_request.rb +61 -0
  75. data/lib/groupdocs_viewer_cloud/models/requests/image_delete_attachment_pages_cache_request.rb +57 -0
  76. data/lib/groupdocs_viewer_cloud/models/requests/image_delete_pages_cache_request.rb +53 -0
  77. data/lib/groupdocs_viewer_cloud/models/requests/image_get_attachment_info_request.rb +69 -0
  78. data/lib/groupdocs_viewer_cloud/models/requests/image_get_attachment_info_with_options_request.rb +61 -0
  79. data/lib/groupdocs_viewer_cloud/models/requests/image_get_attachment_page_request.rb +105 -0
  80. data/lib/groupdocs_viewer_cloud/models/requests/image_get_attachment_pages_request.rb +109 -0
  81. data/lib/groupdocs_viewer_cloud/models/requests/image_get_attachment_request.rb +61 -0
  82. data/lib/groupdocs_viewer_cloud/models/requests/image_get_attachments_request.rb +57 -0
  83. data/lib/groupdocs_viewer_cloud/models/requests/image_get_document_info_from_content_request.rb +61 -0
  84. data/lib/groupdocs_viewer_cloud/models/requests/image_get_document_info_from_url_request.rb +73 -0
  85. data/lib/groupdocs_viewer_cloud/models/requests/image_get_document_info_from_url_with_options_request.rb +61 -0
  86. data/lib/groupdocs_viewer_cloud/models/requests/image_get_document_info_request.rb +69 -0
  87. data/lib/groupdocs_viewer_cloud/models/requests/image_get_document_info_with_options_request.rb +57 -0
  88. data/lib/groupdocs_viewer_cloud/models/requests/image_get_page_request.rb +97 -0
  89. data/lib/groupdocs_viewer_cloud/models/requests/image_get_pages_from_url_request.rb +105 -0
  90. data/lib/groupdocs_viewer_cloud/models/requests/image_get_pages_request.rb +101 -0
  91. data/lib/groupdocs_viewer_cloud/models/requests/image_get_pdf_file_from_url_request.rb +77 -0
  92. data/lib/groupdocs_viewer_cloud/models/requests/image_get_pdf_file_request.rb +73 -0
  93. data/lib/groupdocs_viewer_cloud/models/requests/image_get_zip_with_attachment_pages_request.rb +109 -0
  94. data/lib/groupdocs_viewer_cloud/models/requests/image_get_zip_with_pages_request.rb +101 -0
  95. data/lib/groupdocs_viewer_cloud/models/requests/image_transform_pages_request.rb +57 -0
  96. data/lib/groupdocs_viewer_cloud/models/resource.rb +216 -0
  97. data/lib/groupdocs_viewer_cloud/models/resource_url.rb +206 -0
  98. data/lib/groupdocs_viewer_cloud/models/rotate_options.rb +226 -0
  99. data/lib/groupdocs_viewer_cloud/models/row_info.rb +270 -0
  100. data/lib/groupdocs_viewer_cloud/models/slides_options.rb +206 -0
  101. data/lib/groupdocs_viewer_cloud/models/tile.rb +236 -0
  102. data/lib/groupdocs_viewer_cloud/models/transform_options_base.rb +216 -0
  103. data/lib/groupdocs_viewer_cloud/models/watermark.rb +236 -0
  104. data/lib/groupdocs_viewer_cloud/models/words_options.rb +216 -0
  105. data/lib/groupdocs_viewer_cloud/version.rb +29 -0
  106. metadata +235 -0
@@ -0,0 +1,390 @@
1
+ # -----------------------------------------------------------------------------------
2
+ # <copyright company="Aspose Pty Ltd" file="api_client.rb">
3
+ # Copyright (c) 2003-2018 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 GroupDocsViewerCloud
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' => "application/json",
55
+ 'x-groupdocs-client' => "ruby sdk",
56
+ 'x-groupdocs-version' => GroupDocsViewerCloud::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
+ if response.status == 0
73
+ # Errors from libcurl will be made visible here
74
+ raise ApiError.new(:code => 0,
75
+ :message => response.reason_phrase)
76
+ else
77
+ raise ApiError.new(:code => response.status,
78
+ :response_headers => response.headers,
79
+ :response_body => response.body),
80
+ response.reason_phrase
81
+ end
82
+ end
83
+
84
+
85
+ data = deserialize(response, opts[:return_type]) if opts[:return_type]
86
+ [data, response.status, response.headers]
87
+ end
88
+
89
+ # Builds the HTTP request
90
+ #
91
+ # @param [String] http_method HTTP method/verb (e.g. POST)
92
+ # @param [String] path URL path (e.g. /account/new)
93
+ # @option opts [Hash] :header_params Header parameters
94
+ # @option opts [Hash] :query_params Query parameters
95
+ # @option opts [Hash] :form_params Query parameters
96
+ # @option opts [Object] :body HTTP body (JSON/XML)
97
+ # @return [Faraday::Response] A Faraday Response
98
+ def build_request(http_method, path, opts = {})
99
+ url = build_request_url(path)
100
+ http_method = http_method.to_sym.downcase
101
+
102
+ header_params = @default_headers.merge(opts[:header_params] || {})
103
+ query_params = opts[:query_params] || {}
104
+ form_params = opts[:form_params] || {}
105
+ body = opts[:body] if opts[:body] || nil?
106
+
107
+ update_params_for_oauth! header_params, opts[:access_token]
108
+
109
+ req_opts = {
110
+ :method => http_method,
111
+ :headers => header_params,
112
+ :params => query_params,
113
+ :body => body
114
+ }
115
+
116
+ if [:post, :patch, :put, :delete].include?(http_method)
117
+ req_body = build_request_body(header_params, form_params, opts[:body])
118
+ req_opts.update :body => req_body
119
+ if @config.debugging
120
+ @config.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
121
+ end
122
+ end
123
+
124
+ conn = Faraday.new url, { :params => query_params, :headers => header_params } do |f|
125
+ f.request :multipart
126
+ f.request :url_encoded
127
+ f.adapter Faraday.default_adapter
128
+ end
129
+
130
+ case http_method
131
+ when :post
132
+ return conn.post url, req_opts[:body]
133
+ when :put
134
+ return conn.put url, req_opts[:body]
135
+ when :get
136
+ return conn.get url, req_opts[:body]
137
+ else
138
+ return conn.delete url do |c|
139
+ c.body = req_opts[:body]
140
+ end
141
+ end
142
+ end
143
+
144
+ # Check if the given MIME is a JSON MIME.
145
+ # JSON MIME examples:
146
+ # application/json
147
+ # application/json; charset=UTF8
148
+ # APPLICATION/JSON
149
+ # */*
150
+ # @param [String] mime MIME
151
+ # @return [Boolean] True if the MIME is application/json
152
+ def json_mime?(mime)
153
+ (mime == "*/*") || !(mime =~ /Application\/.*json(?!p)(;.*)?/i).nil?
154
+ end
155
+
156
+ # Deserialize the response to the given return type.
157
+ #
158
+ # @param [Response] response HTTP response
159
+ # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
160
+ def deserialize(response, return_type)
161
+ body = response.body
162
+
163
+ # handle file downloading - return the File instance processed in request callbacks
164
+ # note that response body is empty when the file is written in chunks in request on_body callback
165
+ return @tempfile if return_type == 'File'
166
+
167
+ return nil if body.nil? || body.empty?
168
+
169
+ # return response body directly for String return type
170
+ return body if return_type == 'String'
171
+
172
+ # ensuring a default content type
173
+ content_type = response.headers['Content-Type'] || 'application/json'
174
+
175
+ raise "Content-Type is not supported: #{content_type}" unless json_mime?(content_type)
176
+
177
+ begin
178
+ data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
179
+ rescue JSON::ParserError => e
180
+ if %w[String Date DateTime].include?(return_type)
181
+ data = body
182
+ else
183
+ raise e
184
+ end
185
+ end
186
+
187
+ convert_to_type data, return_type
188
+ end
189
+
190
+ # Convert data to the given return type.
191
+ # @param [Object] data Data to be converted
192
+ # @param [String] return_type Return type
193
+ # @return [Mixed] Data in a particular type
194
+ def convert_to_type(data, return_type)
195
+ return nil if data.nil?
196
+ case return_type
197
+ when 'String'
198
+ data.to_s
199
+ when 'Integer'
200
+ data.to_i
201
+ when 'Float'
202
+ data.to_f
203
+ when 'BOOLEAN'
204
+ data == true
205
+ when 'DateTime'
206
+ # parse date time (expecting ISO 8601 format)
207
+ DateTime.parse data
208
+ when 'Date'
209
+ # parse date time (expecting ISO 8601 format)
210
+ Date.parse data
211
+ when 'Object'
212
+ # generic object (usually a Hash), return directly
213
+ data
214
+ when /\AArray<(.+)>\z/
215
+ # e.g. Array<Pet>
216
+ sub_type = $1
217
+ data.map {|item| convert_to_type(item, sub_type) }
218
+ when /\AHash\<String, (.+)\>\z/
219
+ # e.g. Hash<String, Integer>
220
+ sub_type = $1
221
+ {}.tap do |hash|
222
+ data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
223
+ end
224
+ else
225
+ # models, e.g. Pet
226
+ GroupDocsViewerCloud.const_get(return_type).new.tap do |model|
227
+ model.build_from_hash data
228
+ end
229
+ end
230
+ end
231
+
232
+ # Save response body into a file in (the defined) temporary folder, using the filename
233
+ # from the "Content-Disposition" header if provided, otherwise a random filename.
234
+ # The response body is written to the file in chunks in order to handle files which
235
+ # size is larger than maximum Ruby String or even larger than the maximum memory a Ruby
236
+ # process can use.
237
+ #
238
+ # @see Configuration#temp_folder_path
239
+ def download_file(response)
240
+ tempfile = nil
241
+ encoding = nil
242
+ content_disposition = response.headers['Content-Disposition']
243
+ if content_disposition and content_disposition =~ /filename=/i
244
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
245
+ prefix = sanitize_filename(filename)
246
+ else
247
+ prefix = 'download-'
248
+ end
249
+ prefix += '-' unless prefix.end_with?('-')
250
+ encoding = response.body.encoding
251
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
252
+ @tempfile = tempfile
253
+ tempfile.write(response.body)
254
+ response.on_complete do |resp|
255
+ tempfile.close
256
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
257
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
258
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
259
+ "explicitly with `tempfile.delete`"
260
+ end
261
+ end
262
+
263
+ # Sanitize filename by removing path.
264
+ # e.g. ../../sun.gif becomes sun.gif
265
+ #
266
+ # @param [String] filename the filename to be sanitized
267
+ # @return [String] the sanitized filename
268
+ def sanitize_filename(filename)
269
+ filename.gsub(/.*[\/\\]/, '')
270
+ end
271
+
272
+ def build_request_url(path)
273
+ # Add leading and trailing slashes to path
274
+ path = "/#{path}".gsub(/\/+/, '/')
275
+ Addressable::URI.encode(@config.api_base_url + @config.api_version + path)
276
+ end
277
+
278
+ # Builds the HTTP request body
279
+ #
280
+ # @param [Hash] header_params Header parameters
281
+ # @param [Hash] form_params Query parameters
282
+ # @param [Object] body HTTP body (JSON/XML)
283
+ # @return [String] HTTP body data in the form of string
284
+ def build_request_body(header_params, form_params, body)
285
+ # http form
286
+ if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
287
+ header_params['Content-Type'] == 'multipart/form-data'
288
+ data = {}
289
+ form_params.each do |key, value|
290
+ case value
291
+ when ::File
292
+ data[key] = Faraday::UploadIO.new(value.path, MimeMagic.by_magic(value).to_s, key)
293
+ when ::Array, nil
294
+ data[key] = value
295
+ else
296
+ data[key] = value.to_s
297
+ end
298
+ end
299
+ elsif body
300
+ data = body.is_a?(String) ? body : body.to_json
301
+ else
302
+ data = nil
303
+ end
304
+ data
305
+ end
306
+
307
+ # Update hearder and query params based on authentication settings.
308
+ #
309
+ # @param [Hash] header_params Header parameters
310
+ # @param [String] access_token OAuth access token
311
+ def update_params_for_oauth!(header_params, access_token)
312
+ header_params["Authorization"] = "Bearer #{access_token}"
313
+ end
314
+
315
+ # Sets user agent in HTTP header
316
+ #
317
+ # @param [String] user_agent User agent (e.g. swagger-codegen/ruby/1.0.0)
318
+ def user_agent=(user_agent)
319
+ @user_agent = user_agent
320
+ @default_headers['User-Agent'] = @user_agent
321
+ end
322
+
323
+ # Return Accept header based on an array of accepts provided.
324
+ # @param [Array] accepts array for Accept
325
+ # @return [String] the Accept header (e.g. application/json)
326
+ def select_header_accept(accepts)
327
+ return nil if accepts.nil? || accepts.empty?
328
+ # use JSON when present, otherwise use all of the provided
329
+ json_accept = accepts.find { |s| json_mime?(s) }
330
+ return json_accept || accepts.join(',')
331
+ end
332
+
333
+ # Return Content-Type header based on an array of content types provided.
334
+ # @param [Array] content_types array for Content-Type
335
+ # @return [String] the Content-Type header (e.g. application/json)
336
+ def select_header_content_type(content_types)
337
+ # use application/json by default
338
+ return 'application/json' if content_types.nil? || content_types.empty?
339
+ # use JSON when present, otherwise use the first one
340
+ json_content_type = content_types.find { |s| json_mime?(s) }
341
+ return json_content_type || content_types.first
342
+ end
343
+
344
+ # Convert object (array, hash, object, etc) to JSON string.
345
+ # @param [Object] model object to be converted into JSON string
346
+ # @return [String] JSON string representation of the object
347
+ def object_to_http_body(model)
348
+ return '"' + model + '"' if model.is_a?(String)
349
+ return model if model.nil?
350
+ local_body = nil
351
+ if model.is_a?(Array)
352
+ local_body = model.map { |m| object_to_hash(m) }
353
+ else
354
+ local_body = object_to_hash(model)
355
+ end
356
+ local_body.to_json
357
+ end
358
+
359
+ # Convert object(non-array) to hash.
360
+ # @param [Object] obj object to be converted into JSON string
361
+ # @return [String] JSON string representation of the object
362
+ def object_to_hash(obj)
363
+ if obj.respond_to?(:to_hash)
364
+ obj.to_hash
365
+ else
366
+ obj
367
+ end
368
+ end
369
+
370
+ # Build parameter value according to the given collection format.
371
+ # @param [String] collection_format one of :csv, :ssv, :tsv, :pipes and :multi
372
+ def build_collection_param(param, collection_format)
373
+ case collection_format
374
+ when :csv
375
+ param.join(',')
376
+ when :ssv
377
+ param.join(' ')
378
+ when :tsv
379
+ param.join("\t")
380
+ when :pipes
381
+ param.join('|')
382
+ when :multi
383
+ # return the array directly as faraday will handle it as expected
384
+ param
385
+ else
386
+ raise "unknown collection format: #{collection_format.inspect}"
387
+ end
388
+ end
389
+ end
390
+ end
@@ -0,0 +1,56 @@
1
+ # -----------------------------------------------------------------------------------
2
+ # <copyright company="Aspose Pty Ltd" file="api_error.rb">
3
+ # Copyright (c) 2003-2018 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 GroupDocsViewerCloud
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][:message]
44
+ end
45
+ end
46
+
47
+ if arg.key?(:arg) then
48
+ @code = arg[:code]
49
+ end
50
+
51
+ else
52
+ super arg
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,95 @@
1
+ # ------------------------------------------------------------------------------------
2
+ # <copyright company="Aspose Pty Ltd" file="configuration.rb">
3
+ # Copyright (c) 2003-2018 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 GroupDocsViewerCloud
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 ''
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'
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