aspose_imaging_cloud 1.0.0 → 19.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +224 -61
  3. data/lib/aspose-imaging-cloud.rb +161 -0
  4. data/lib/aspose-imaging-cloud/api/imaging_api.rb +684 -0
  5. data/lib/aspose-imaging-cloud/api_client.rb +357 -0
  6. data/lib/aspose-imaging-cloud/api_error.rb +42 -0
  7. data/lib/{aspose_imaging_cloud → aspose-imaging-cloud}/configuration.rb +236 -166
  8. data/lib/aspose-imaging-cloud/models/big_rectangular_filter_properties.rb +206 -0
  9. data/lib/aspose-imaging-cloud/models/bilateral_smoothing_filter_properties.rb +281 -0
  10. data/lib/aspose-imaging-cloud/models/bmp_properties.rb +202 -0
  11. data/lib/aspose-imaging-cloud/models/convolution_filter_properties.rb +236 -0
  12. data/lib/aspose-imaging-cloud/models/deconvolution_filter_properties.rb +266 -0
  13. data/lib/aspose-imaging-cloud/models/dicom_properties.rb +584 -0
  14. data/lib/aspose-imaging-cloud/models/disc_usage.rb +222 -0
  15. data/lib/aspose-imaging-cloud/models/djvu_properties.rb +232 -0
  16. data/lib/aspose-imaging-cloud/models/dng_properties.rb +329 -0
  17. data/lib/aspose-imaging-cloud/models/error.rb +232 -0
  18. data/lib/aspose-imaging-cloud/models/error_details.rb +217 -0
  19. data/lib/aspose-imaging-cloud/models/exif_data.rb +1560 -0
  20. data/lib/aspose-imaging-cloud/models/file_version.rb +277 -0
  21. data/lib/aspose-imaging-cloud/models/file_versions.rb +204 -0
  22. data/lib/aspose-imaging-cloud/models/files_list.rb +204 -0
  23. data/lib/aspose-imaging-cloud/models/files_upload_result.rb +216 -0
  24. data/lib/aspose-imaging-cloud/models/filter_properties_base.rb +206 -0
  25. data/lib/aspose-imaging-cloud/models/gauss_wiener_filter_properties.rb +296 -0
  26. data/lib/aspose-imaging-cloud/models/gaussian_blur_filter_properties.rb +266 -0
  27. data/lib/aspose-imaging-cloud/models/gif_properties.rb +247 -0
  28. data/lib/aspose-imaging-cloud/models/image_duplicates.rb +204 -0
  29. data/lib/aspose-imaging-cloud/models/image_duplicates_set.rb +204 -0
  30. data/lib/aspose-imaging-cloud/models/image_features.rb +257 -0
  31. data/lib/aspose-imaging-cloud/models/imaging_response.rb +412 -0
  32. data/lib/aspose-imaging-cloud/models/jfif_data.rb +247 -0
  33. data/lib/aspose-imaging-cloud/models/jpeg2000_properties.rb +214 -0
  34. data/lib/aspose-imaging-cloud/models/jpeg_exif_data.rb +1738 -0
  35. data/lib/aspose-imaging-cloud/models/jpeg_properties.rb +222 -0
  36. data/lib/aspose-imaging-cloud/models/median_filter_properties.rb +221 -0
  37. data/lib/aspose-imaging-cloud/models/motion_wiener_filter_properties.rb +311 -0
  38. data/lib/aspose-imaging-cloud/models/object_exist.rb +222 -0
  39. data/lib/aspose-imaging-cloud/models/odg_metadata.rb +372 -0
  40. data/lib/aspose-imaging-cloud/models/odg_page.rb +222 -0
  41. data/lib/aspose-imaging-cloud/models/odg_properties.rb +229 -0
  42. data/lib/aspose-imaging-cloud/models/png_properties.rb +192 -0
  43. data/lib/aspose-imaging-cloud/models/psd_properties.rb +242 -0
  44. data/lib/aspose-imaging-cloud/models/requests/add_search_image_request.rb +91 -0
  45. data/lib/aspose-imaging-cloud/models/requests/append_tiff_request.rb +88 -0
  46. data/lib/aspose-imaging-cloud/models/requests/compare_images_request.rb +94 -0
  47. data/lib/aspose-imaging-cloud/models/requests/convert_tiff_to_fax_request.rb +80 -0
  48. data/lib/aspose-imaging-cloud/models/requests/copy_file_request.rb +91 -0
  49. data/lib/aspose-imaging-cloud/models/requests/copy_folder_request.rb +88 -0
  50. data/lib/aspose-imaging-cloud/models/requests/create_cropped_image_request.rb +121 -0
  51. data/lib/aspose-imaging-cloud/models/requests/create_folder_request.rb +77 -0
  52. data/lib/aspose-imaging-cloud/models/requests/create_image_features_request.rb +89 -0
  53. data/lib/aspose-imaging-cloud/models/requests/create_image_frame_request.rb +112 -0
  54. data/lib/aspose-imaging-cloud/models/requests/create_image_search_request.rb +79 -0
  55. data/lib/aspose-imaging-cloud/models/requests/create_image_tag_request.rb +96 -0
  56. data/lib/aspose-imaging-cloud/models/requests/create_modified_bmp_request.rb +108 -0
  57. data/lib/aspose-imaging-cloud/models/requests/create_modified_emf_request.rb +127 -0
  58. data/lib/aspose-imaging-cloud/models/requests/create_modified_gif_request.rb +102 -0
  59. data/lib/aspose-imaging-cloud/models/requests/create_modified_jpeg2000_request.rb +95 -0
  60. data/lib/aspose-imaging-cloud/models/requests/create_modified_jpeg_request.rb +90 -0
  61. data/lib/aspose-imaging-cloud/models/requests/create_modified_psd_request.rb +90 -0
  62. data/lib/aspose-imaging-cloud/models/requests/create_modified_svg_request.rb +114 -0
  63. data/lib/aspose-imaging-cloud/models/requests/create_modified_tiff_request.rb +104 -0
  64. data/lib/aspose-imaging-cloud/models/requests/create_modified_web_p_request.rb +116 -0
  65. data/lib/aspose-imaging-cloud/models/requests/create_modified_wmf_request.rb +127 -0
  66. data/lib/aspose-imaging-cloud/models/requests/create_resized_image_request.rb +105 -0
  67. data/lib/aspose-imaging-cloud/models/requests/create_rotate_flipped_image_request.rb +97 -0
  68. data/lib/aspose-imaging-cloud/models/requests/create_saved_image_as_request.rb +89 -0
  69. data/lib/aspose-imaging-cloud/models/requests/create_updated_image_request.rb +145 -0
  70. data/lib/aspose-imaging-cloud/models/requests/create_web_site_image_features_request.rb +88 -0
  71. data/lib/aspose-imaging-cloud/models/requests/crop_image_request.rb +120 -0
  72. data/lib/aspose-imaging-cloud/models/requests/delete_file_request.rb +80 -0
  73. data/lib/aspose-imaging-cloud/models/requests/delete_folder_request.rb +80 -0
  74. data/lib/aspose-imaging-cloud/models/requests/delete_image_features_request.rb +88 -0
  75. data/lib/aspose-imaging-cloud/models/requests/delete_image_search_request.rb +80 -0
  76. data/lib/aspose-imaging-cloud/models/requests/delete_search_image_request.rb +88 -0
  77. data/lib/aspose-imaging-cloud/models/requests/download_file_request.rb +80 -0
  78. data/lib/aspose-imaging-cloud/models/requests/extract_image_features_request.rb +91 -0
  79. data/lib/aspose-imaging-cloud/models/requests/extract_image_frame_properties_request.rb +82 -0
  80. data/lib/aspose-imaging-cloud/models/requests/extract_image_properties_request.rb +75 -0
  81. data/lib/aspose-imaging-cloud/models/requests/filter_effect_image_request.rb +103 -0
  82. data/lib/aspose-imaging-cloud/models/requests/find_image_duplicates_request.rb +88 -0
  83. data/lib/aspose-imaging-cloud/models/requests/find_images_by_tags_request.rb +104 -0
  84. data/lib/aspose-imaging-cloud/models/requests/find_similar_images_request.rb +102 -0
  85. data/lib/aspose-imaging-cloud/models/requests/get_disc_usage_request.rb +70 -0
  86. data/lib/aspose-imaging-cloud/models/requests/get_file_versions_request.rb +77 -0
  87. data/lib/aspose-imaging-cloud/models/requests/get_files_list_request.rb +77 -0
  88. data/lib/aspose-imaging-cloud/models/requests/get_image_features_request.rb +88 -0
  89. data/lib/aspose-imaging-cloud/models/requests/get_image_frame_properties_request.rb +87 -0
  90. data/lib/aspose-imaging-cloud/models/requests/get_image_frame_request.rb +111 -0
  91. data/lib/aspose-imaging-cloud/models/requests/get_image_properties_request.rb +80 -0
  92. data/lib/aspose-imaging-cloud/models/requests/get_image_search_status_request.rb +80 -0
  93. data/lib/aspose-imaging-cloud/models/requests/get_search_image_request.rb +88 -0
  94. data/lib/aspose-imaging-cloud/models/requests/http_request.rb +50 -0
  95. data/lib/aspose-imaging-cloud/models/requests/imaging_request.rb +101 -0
  96. data/lib/aspose-imaging-cloud/models/requests/modify_bmp_request.rb +107 -0
  97. data/lib/aspose-imaging-cloud/models/requests/modify_emf_request.rb +126 -0
  98. data/lib/aspose-imaging-cloud/models/requests/modify_gif_request.rb +101 -0
  99. data/lib/aspose-imaging-cloud/models/requests/modify_jpeg2000_request.rb +94 -0
  100. data/lib/aspose-imaging-cloud/models/requests/modify_jpeg_request.rb +89 -0
  101. data/lib/aspose-imaging-cloud/models/requests/modify_psd_request.rb +89 -0
  102. data/lib/aspose-imaging-cloud/models/requests/modify_svg_request.rb +113 -0
  103. data/lib/aspose-imaging-cloud/models/requests/modify_tiff_request.rb +103 -0
  104. data/lib/aspose-imaging-cloud/models/requests/modify_web_p_request.rb +115 -0
  105. data/lib/aspose-imaging-cloud/models/requests/modify_wmf_request.rb +126 -0
  106. data/lib/aspose-imaging-cloud/models/requests/move_file_request.rb +91 -0
  107. data/lib/aspose-imaging-cloud/models/requests/move_folder_request.rb +88 -0
  108. data/lib/aspose-imaging-cloud/models/requests/object_exists_request.rb +80 -0
  109. data/lib/aspose-imaging-cloud/models/requests/resize_image_request.rb +104 -0
  110. data/lib/aspose-imaging-cloud/models/requests/rotate_flip_image_request.rb +96 -0
  111. data/lib/aspose-imaging-cloud/models/requests/save_image_as_request.rb +88 -0
  112. data/lib/aspose-imaging-cloud/models/requests/storage_exists_request.rb +74 -0
  113. data/lib/aspose-imaging-cloud/models/requests/update_image_features_request.rb +91 -0
  114. data/lib/aspose-imaging-cloud/models/requests/update_image_request.rb +144 -0
  115. data/lib/aspose-imaging-cloud/models/requests/update_search_image_request.rb +91 -0
  116. data/lib/aspose-imaging-cloud/models/requests/upload_file_request.rb +86 -0
  117. data/lib/aspose-imaging-cloud/models/search_context_status.rb +212 -0
  118. data/lib/aspose-imaging-cloud/models/search_result.rb +217 -0
  119. data/lib/aspose-imaging-cloud/models/search_results_set.rb +204 -0
  120. data/lib/aspose-imaging-cloud/models/sharpen_filter_properties.rb +266 -0
  121. data/lib/aspose-imaging-cloud/models/small_rectangular_filter_properties.rb +206 -0
  122. data/lib/aspose-imaging-cloud/models/storage_exist.rb +207 -0
  123. data/lib/aspose-imaging-cloud/models/storage_file.rb +252 -0
  124. data/lib/aspose-imaging-cloud/models/svg_properties.rb +202 -0
  125. data/lib/aspose-imaging-cloud/models/tiff_frame.rb +242 -0
  126. data/lib/aspose-imaging-cloud/models/tiff_options.rb +734 -0
  127. data/lib/aspose-imaging-cloud/models/tiff_properties.rb +224 -0
  128. data/lib/aspose-imaging-cloud/models/web_p_properties.rb +252 -0
  129. data/lib/aspose-imaging-cloud/version.rb +15 -0
  130. metadata +149 -129
  131. data/LICENSE +0 -22
  132. data/aspose_imaging_cloud.gemspec +0 -26
  133. data/lib/aspose_imaging_cloud.rb +0 -43
  134. data/lib/aspose_imaging_cloud/api/imaging_api.rb +0 -1776
  135. data/lib/aspose_imaging_cloud/api_client.rb +0 -335
  136. data/lib/aspose_imaging_cloud/api_error.rb +0 -24
  137. data/lib/aspose_imaging_cloud/models/base_object.rb +0 -86
  138. data/lib/aspose_imaging_cloud/models/base_response.rb +0 -53
  139. data/lib/aspose_imaging_cloud/models/bmp_properties.rb +0 -37
  140. data/lib/aspose_imaging_cloud/models/exif_data.rb +0 -855
  141. data/lib/aspose_imaging_cloud/models/gif_properties.rb +0 -53
  142. data/lib/aspose_imaging_cloud/models/imaging_response.rb +0 -149
  143. data/lib/aspose_imaging_cloud/models/jfif_data.rb +0 -61
  144. data/lib/aspose_imaging_cloud/models/jpeg_exif_data.rb +0 -991
  145. data/lib/aspose_imaging_cloud/models/jpeg_properties.rb +0 -53
  146. data/lib/aspose_imaging_cloud/models/psd_properties.rb +0 -61
  147. data/lib/aspose_imaging_cloud/models/tiff_frame.rb +0 -61
  148. data/lib/aspose_imaging_cloud/models/tiff_options.rb +0 -419
  149. data/lib/aspose_imaging_cloud/models/tiff_properties.rb +0 -55
  150. data/lib/aspose_imaging_cloud/version.rb +0 -3
  151. data/test/data/TestDemo.tif +0 -0
  152. data/test/data/aspose.jpg +0 -0
  153. data/test/data/aspose_imaging_for_cloud.png +0 -0
  154. data/test/data/demo.tif +0 -0
  155. data/test/data/sample-multi.tif +0 -0
  156. data/test/data/sample.bmp +0 -0
  157. data/test/data/sample.gif +0 -0
  158. data/test/data/sample.psd +0 -0
  159. data/test/data/sample.tif +0 -0
  160. data/test/data/test.bmp +0 -0
  161. data/test/imaging_tests.rb +0 -291
@@ -1,335 +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 AsposeImagingCloud
12
- class ApiClient
13
-
14
- include AsposeStorageCloud
15
-
16
- attr_accessor :host
17
-
18
- # Defines the headers to be used in HTTP requests of all API calls by default.
19
- #
20
- # @return [Hash]
21
- attr_accessor :default_headers
22
-
23
- # Stores the HTTP response from the last API call using this API client.
24
- attr_accessor :last_response
25
-
26
- def initialize(host = nil)
27
- @host = host || Configuration.base_url
28
- @format = 'json'
29
- @user_agent = "ruby-swagger-#{VERSION}"
30
- @default_headers = {
31
- 'Content-Type' => "application/#{@format.downcase}",
32
- 'User-Agent' => @user_agent
33
- }
34
- end
35
-
36
- def call_api(http_method, path, opts = {})
37
- request = build_request(http_method, path, opts)
38
- response = request.run
39
-
40
- # record as last response
41
- @last_response = response
42
-
43
- if Configuration.debugging
44
- Configuration.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
45
- end
46
-
47
- unless response.success?
48
- fail ApiError.new(:code => response.code,
49
- :response_headers => response.headers,
50
- :response_body => response.body),
51
- response.status_message
52
- end
53
-
54
- if opts[:return_type]
55
- deserialize(response, opts[:return_type])
56
- else
57
- nil
58
- end
59
- end
60
-
61
- def build_request(http_method, path, opts = {})
62
- url = build_request_url(path)
63
- http_method = http_method.to_sym.downcase
64
-
65
- header_params = @default_headers.merge(opts[:header_params] || {})
66
- query_params = {}
67
- form_params = opts[:form_params] || {}
68
-
69
- req_opts = {
70
- :method => http_method,
71
- :headers => header_params,
72
- :params => query_params,
73
- :ssl_verifypeer => Configuration.verify_ssl,
74
- :sslcert => Configuration.cert_file,
75
- :sslkey => Configuration.key_file,
76
- :cainfo => Configuration.ssl_ca_cert,
77
- :verbose => Configuration.debugging
78
- }
79
-
80
- if [:post, :patch, :put, :delete].include?(http_method)
81
- req_body = build_request_body(header_params, form_params, opts[:body])
82
- req_opts.update :body => req_body
83
- if Configuration.debugging
84
- Configuration.logger.debug "HTTP request body param ~BEGIN~\n#{req_body}\n~END~\n"
85
- end
86
- end
87
-
88
- url = sign(url, opts[:query_params])
89
- Typhoeus::Request.new(url, req_opts)
90
-
91
- end
92
-
93
- # Signs a URI with your appSID and Key.
94
- # * :url describes the URL to sign
95
-
96
- def sign(url, query_params)
97
-
98
- 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?
99
-
100
- url = url[0..-2] if url[-1].eql? '/'
101
-
102
- unless query_params.empty?
103
- url = "#{url}?"
104
- query_params.each { |key, value|
105
- url = "#{url}#{key}=#{value}&"
106
- }
107
- url = url[0..-2]
108
- end
109
-
110
- url = URI.escape(url)
111
- parsed_url = URI.parse(url)
112
-
113
- url_to_sign = "#{parsed_url.scheme}://#{parsed_url.host}#{parsed_url.path}"
114
- url_to_sign += "?#{parsed_url.query}" if parsed_url.query
115
- if parsed_url.query
116
- url_to_sign += "&appSID=#{AsposeApp.app_sid}"
117
- else
118
- url_to_sign += "?appSID=#{AsposeApp.app_sid}"
119
- end
120
-
121
- # create a signature using the private key and the URL
122
- raw_signature = OpenSSL::HMAC.digest(OpenSSL::Digest.new('sha1'), AsposeApp.app_key, url_to_sign)
123
-
124
- #Convert raw to encoded string
125
- signature = Base64.strict_encode64(raw_signature).tr('+/', '-_')
126
-
127
- #remove invalid character
128
- signature = signature.gsub(/[=_-]/, '=' => '', '_' => '%2f', '-' => '%2b')
129
-
130
- #Define expression
131
- pat = Regexp.new('%[0-9a-f]{2}')
132
-
133
- #Replace the portion matched to the above pattern to upper case
134
- 6.times do
135
- signature = signature.sub(pat, pat.match(signature).to_s.upcase)
136
- end
137
-
138
- # prepend the server and append the signature.
139
- url_to_sign + "&signature=#{signature}"
140
-
141
- end
142
-
143
- # Deserialize the response to the given return type.
144
- #
145
- # @param [String] return_type some examples: "User", "Array[User]", "Hash[String,Integer]"
146
- def deserialize(response, return_type)
147
- body = response.body
148
- return nil if body.nil? || body.empty?
149
-
150
- # handle file downloading - save response body into a tmp file and return the File instance
151
- return download_file(response) if return_type == 'File'
152
-
153
- # ensuring a default content type
154
- content_type = response.headers['Content-Type'] || 'application/json'
155
-
156
- unless content_type.start_with?('application/json')
157
- fail "Content-Type is not supported: #{content_type}"
158
- end
159
-
160
- begin
161
- data = JSON.parse("[#{body}]", :symbolize_names => true)[0]
162
- rescue JSON::ParserError => e
163
- if %w(String Date DateTime).include?(return_type)
164
- data = body
165
- else
166
- raise e
167
- end
168
- end
169
-
170
- convert_to_type data, return_type
171
- end
172
-
173
- # Convert data to the given return type.
174
- def convert_to_type(data, return_type)
175
- return nil if data.nil?
176
- case return_type
177
- when 'String'
178
- data.to_s
179
- when 'Integer'
180
- data.to_i
181
- when 'Float'
182
- data.to_f
183
- when 'BOOLEAN'
184
- data == true
185
- when 'DateTime'
186
- # parse date time (expecting ISO 8601 format)
187
- DateTime.parse data
188
- when 'Date'
189
- # parse date time (expecting ISO 8601 format)
190
- Date.parse data
191
- when 'Object'
192
- # generic object, return directly
193
- data
194
- when /\AArray<(.+)>\z/
195
- # e.g. Array<Pet>
196
- sub_type = $1
197
- data.map {|item| convert_to_type(item, sub_type) }
198
- when /\AHash\<String, (.+)\>\z/
199
- # e.g. Hash<String, Integer>
200
- sub_type = $1
201
- {}.tap do |hash|
202
- data.each {|k, v| hash[k] = convert_to_type(v, sub_type) }
203
- end
204
- else
205
- # models, e.g. Pet
206
- AsposeImagingCloud.const_get(return_type).new.tap do |model|
207
- model.build_from_hash data
208
- end
209
- end
210
- end
211
-
212
- # Save response body into a file in (the defined) temporary folder, using the filename
213
- # from the "Content-Disposition" header if provided, otherwise a random filename.
214
- #
215
- # @see Configuration#temp_folder_path
216
- # @return [File] the file downloaded
217
- def download_file(response)
218
- tmp_file = Tempfile.new '', Configuration.temp_folder_path
219
- content_disposition = response.headers['Content-Disposition']
220
-
221
- if content_disposition
222
- filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
223
- path = File.join File.dirname(tmp_file), filename
224
- else
225
- path = tmp_file.path
226
- end
227
- # close and delete temp file
228
- tmp_file.close!
229
-
230
- File.open(path, 'w') { |file| file.write(response.body) }
231
- Configuration.logger.info "File written to #{path}. Please move the file to a proper "\
232
- "folder for further processing and delete the temp afterwards"
233
- File.new(path)
234
- end
235
-
236
- def build_request_url(path)
237
- # Add leading and trailing slashes to path
238
- path = "/#{path}".gsub(/\/+/, '/')
239
- URI.encode(host + path)
240
- end
241
-
242
- def build_request_body(header_params, form_params, body)
243
- # http form
244
- if header_params['Content-Type'] == 'application/x-www-form-urlencoded' ||
245
- header_params['Content-Type'] == 'multipart/form-data'
246
-
247
- data = form_params.dup
248
- data.each do |key, value|
249
- if key.eql? "file"
250
- data = value
251
- break
252
- else
253
- data[key] = value.to_s if value && !value.is_a?(File)
254
- end
255
- end
256
- elsif body
257
- data = body.is_a?(String) ? body : body.to_json
258
- else
259
- data = nil
260
- end
261
- data
262
- end
263
-
264
- # Update hearder and query params based on authentication settings.
265
- def update_params_for_auth!(header_params, query_params, auth_names)
266
- Array(auth_names).each do |auth_name|
267
- auth_setting = Configuration.auth_settings[auth_name]
268
- next unless auth_setting
269
- case auth_setting[:in]
270
- when 'header' then header_params[auth_setting[:key]] = auth_setting[:value]
271
- when 'query' then query_params[auth_setting[:key]] = auth_setting[:value]
272
- else fail ArgumentError, 'Authentication token must be in `query` of `header`'
273
- end
274
- end
275
- end
276
-
277
- def user_agent=(user_agent)
278
- @user_agent = user_agent
279
- @default_headers['User-Agent'] = @user_agent
280
- end
281
-
282
- # Return Accept header based on an array of accepts provided.
283
- # @param [Array] accepts array for Accept
284
- # @return [String] the Accept header (e.g. application/json)
285
- def select_header_accept(accepts)
286
- if accepts.empty?
287
- return
288
- elsif accepts.any?{ |s| s.casecmp('application/json') == 0 }
289
- 'application/json' # look for json data by default
290
- else
291
- accepts.join(',')
292
- end
293
- end
294
-
295
- # Return Content-Type header based on an array of content types provided.
296
- # @param [Array] content_types array for Content-Type
297
- # @return [String] the Content-Type header (e.g. application/json)
298
- def select_header_content_type(content_types)
299
- if content_types.empty?
300
- 'application/json' # use application/json by default
301
- elsif content_types.any?{ |s| s.casecmp('application/json')==0 }
302
- 'application/json' # use application/json if it's included
303
- else
304
- content_types[0] # otherwise, use the first one
305
- end
306
- end
307
-
308
- # Convert object (array, hash, object, etc) to JSON string.
309
- # @param [Object] model object to be converted into JSON string
310
- # @return [String] JSON string representation of the object
311
- def object_to_http_body(model)
312
- return if model.nil?
313
- _body = nil
314
- if model.is_a?(Array)
315
- _body = model.map{|m| object_to_hash(m) }
316
- else
317
- _body = object_to_hash(model)
318
- end
319
- _body.to_json
320
- end
321
-
322
- # Convert object(non-array) to hash.
323
- # @param [Object] obj object to be converted into JSON string
324
- # @return [String] JSON string representation of the object
325
- def object_to_hash(obj)
326
- if obj.respond_to?(:to_hash)
327
- obj.to_hash
328
- else
329
- obj
330
- end
331
- end
332
-
333
-
334
- end
335
- end
@@ -1,24 +0,0 @@
1
- module AsposeImagingCloud
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,86 +0,0 @@
1
- require 'date'
2
-
3
- module AsposeImagingCloud
4
- # base class containing fundamental method such as to_hash, build_from_hash and more
5
- class BaseObject
6
-
7
- # build the object from hash
8
- def build_from_hash(attributes)
9
- return nil unless attributes.is_a?(Hash)
10
- self.class.swagger_types.each_pair do |key, type|
11
- if type =~ /^Array<(.*)>/i
12
- if attributes[self.class.attribute_map[key]].is_a?(Array)
13
- self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
14
- else
15
- #TODO show warning in debug mode
16
- end
17
- elsif !attributes[self.class.attribute_map[key]].nil?
18
- self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
19
- else
20
- # data not found in attributes(hash), not an issue as the data can be optional
21
- end
22
- end
23
-
24
- self
25
- end
26
-
27
- def _deserialize(type, value)
28
- case type.to_sym
29
- when :DateTime
30
- DateTime.parse(value)
31
- when :Date
32
- Date.parse(value)
33
- when :String
34
- value.to_s
35
- when :Integer
36
- value.to_i
37
- when :Float
38
- value.to_f
39
- when :BOOLEAN
40
- if value =~ /^(true|t|yes|y|1)$/i
41
- true
42
- else
43
- false
44
- end
45
- else # model
46
- _model = AsposeImagingCloud.const_get(type).new
47
- _model.build_from_hash(value)
48
- end
49
- end
50
-
51
- def to_s
52
- to_hash.to_s
53
- end
54
-
55
- # to_body is an alias to to_body (backward compatibility))
56
- def to_body
57
- to_hash
58
- end
59
-
60
- # return the object in the form of hash
61
- def to_hash
62
- hash = {}
63
- self.class.attribute_map.each_pair do |attr, param|
64
- value = self.send(attr)
65
- next if value.nil?
66
- if value.is_a?(Array)
67
- hash[param] = value.compact.map{ |v| _to_hash(v) }
68
- else
69
- hash[param] = _to_hash(value)
70
- end
71
- end
72
- hash
73
- end
74
-
75
- # Method to output non-array value in the form of hash
76
- # For object, use to_hash. Otherwise, just return the value
77
- def _to_hash(value)
78
- if value.respond_to? :to_hash
79
- value.to_hash
80
- else
81
- value
82
- end
83
- end
84
-
85
- end
86
- end
@@ -1,53 +0,0 @@
1
- module AsposeImagingCloud
2
- #
3
- class BaseResponse < BaseObject
4
- attr_accessor :status, :code
5
- # attribute mapping from ruby-style variable name to JSON key
6
- def self.attribute_map
7
- {
8
-
9
- #
10
- :'status' => :'Status',
11
-
12
- #
13
- :'code' => :'Code'
14
-
15
- }
16
- end
17
-
18
- # attribute type
19
- def self.swagger_types
20
- {
21
- :'status' => :'String',
22
- :'code' => :'String'
23
-
24
- }
25
- end
26
-
27
- def initialize(attributes = {})
28
- return if !attributes.is_a?(Hash) || attributes.empty?
29
-
30
- # convert string to symbol for hash key
31
- attributes = attributes.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
32
-
33
-
34
- if attributes[:'Status']
35
- self.status = attributes[:'Status']
36
- end
37
-
38
- if attributes[:'Code']
39
- self.code = attributes[:'Code']
40
- end
41
-
42
- end
43
-
44
- def status=(status)
45
- allowed_values = ["Continue", "SwitchingProtocols", "OK", "Created", "Accepted", "NonAuthoritativeInformation", "NoContent", "ResetContent", "PartialContent", "MultipleChoices", "Ambiguous", "MovedPermanently", "Moved", "Found", "Redirect", "SeeOther", "RedirectMethod", "NotModified", "UseProxy", "Unused", "TemporaryRedirect", "RedirectKeepVerb", "BadRequest", "Unauthorized", "PaymentRequired", "Forbidden", "NotFound", "MethodNotAllowed", "NotAcceptable", "ProxyAuthenticationRequired", "RequestTimeout", "Conflict", "Gone", "LengthRequired", "PreconditionFailed", "RequestEntityTooLarge", "RequestUriTooLong", "UnsupportedMediaType", "RequestedRangeNotSatisfiable", "ExpectationFailed", "UpgradeRequired", "InternalServerError", "NotImplemented", "BadGateway", "ServiceUnavailable", "GatewayTimeout", "HttpVersionNotSupported"]
46
- if status && !allowed_values.include?(status)
47
- fail "invalid value for 'status', must be one of #{allowed_values}"
48
- end
49
- @status = status
50
- end
51
-
52
- end
53
- end