Class: AsposeHtml::HtmlApi
- Inherits:
-
Object
- Object
- AsposeHtml::HtmlApi
- Defined in:
- lib/aspose_html_cloud/api/html_api.rb
Instance Attribute Summary collapse
-
#api_client ⇒ Object
Returns the value of attribute api_client.
Instance Method Summary collapse
-
#convert(src, dst, src_in_local, dst_in_local, is_url, options = nil, storage_name = nil) ⇒ OperationResult
Converting a document to various formats.
-
#convert_local_to_local(src, dst, options = nil) ⇒ OperationResult
Converting a document from the local file and putting the result in the local file.
-
#convert_local_to_storage(src, dst, storage, options = nil) ⇒ OperationResult
Converting a document from the local file and putting the result in the storage.
-
#convert_storage_to_local(src, dst, storage, options = nil) ⇒ OperationResult
Converting a document from the storage and putting the result in the local file.
-
#convert_storage_to_storage(src, dst, storage, options = nil) ⇒ OperationResult
Converting a document from the storage and putting the result in the storage.
-
#convert_url_to_local(src, dst, options = nil) ⇒ OperationResult
Converting the HTML page from URL and putting the result in the local file.
-
#convert_url_to_storage(src, dst, storage, options = nil) ⇒ OperationResult
Converting the HTML page from URL and putting the result in the storage.
- #get_input_format(path) ⇒ Object
- #get_status(id) ⇒ Object
-
#initialize(args) ⇒ HtmlApi
constructor
A new instance of HtmlApi.
-
#vectorize(src, dst, src_in_local, dst_in_local, options = nil, storage_name = nil) ⇒ OperationResult
Vectorization an image from to SVG format.
-
#vectorize_local_to_local(src, dst, options = nil) ⇒ OperationResult
Vectorization an image from the local file and putting the result in the local file.
-
#vectorize_local_to_storage(src, dst, storage, options = nil) ⇒ OperationResult
Vectorization an image from the local file and putting the result in the storage.
-
#vectorize_storage_to_local(src, dst, storage, options = nil) ⇒ OperationResult
Vectorization an image from the storage and putting the result in the local file.
-
#vectorize_storage_to_storage(src, dst, storage, options = nil) ⇒ OperationResult
Vectorization an image from the storage and putting the result in the storage.
Constructor Details
#initialize(args) ⇒ HtmlApi
Returns a new instance of HtmlApi.
36 37 38 39 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 36 def initialize(args) @api_client = AsposeHtml::ApiClient.default(args) @storage_api = AsposeHtml::StorageApi.new args end |
Instance Attribute Details
#api_client ⇒ Object
Returns the value of attribute api_client.
34 35 36 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 34 def api_client @api_client end |
Instance Method Details
#convert(src, dst, src_in_local, dst_in_local, is_url, options = nil, storage_name = nil) ⇒ OperationResult
Converting a document to various formats
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 239 def convert(src, dst, src_in_local, dst_in_local, is_url, =nil, storage_name=nil) if src_in_local res = @storage_api.upload_file("/", src) if res.uploaded.length != 1 || res.errors.length != 0 fail ApiError.new('Unable to upload file') end file_in_storage = res.uploaded[0] else file_in_storage = src end out_file = File.basename(dst) out_file = dst unless dst_in_local input_format = 'html' input_format = get_input_format(src) unless is_url output_format = File.extname(dst).strip.downcase[1..-1] if output_format == 'jpg' output_format = 'jpeg' elsif output_format == 'mht' output_format = 'mhtml' elsif output_format == 'tif' output_format = 'tiff' end local_var_path = "/html/conversion/{from}-{to}".sub('{' + 'from' + '}', input_format.to_s).sub('{' + 'to' + '}', output_format.to_s) post_body = {} post_body[:'inputPath'] = file_in_storage.to_s post_body[:'outputFile'] = out_file.to_s post_body[:'storageName'] = storage_name.to_s unless .nil? post_body[:'options'] = {} post_body[:'options'][:'width'] = [:'width'] unless [:'width'].nil? post_body[:'options'][:'height'] = [:'height'] unless [:'height'].nil? post_body[:'options'][:'leftMargin'] = [:'left_margin'] unless [:'left_margin'].nil? post_body[:'options'][:'rightMargin'] = [:'right_margin'] unless [:'right_margin'].nil? post_body[:'options'][:'topMargin'] = [:'top_margin'] unless [:'top_margin'].nil? post_body[:'options'][:'bottomMargin'] = [:'bottom_margin'] unless [:'bottom_margin'].nil? post_body[:'options'][:'resolution'] = [:'resolution'] unless [:'resolution'].nil? post_body[:'options'][:'background'] = [:'background'] unless [:'background'].nil? post_body[:'options'][:'jpegquality'] = [:'jpeg_quality'] unless [:'jpeg_quality'].nil? post_body[:'options'][:'usegit'] = [:'use_git'] unless [:'use_git'].nil? post_body[:'options'][:'error_threshold'] = [:'error_threshold'] unless [:'error_threshold'].nil? post_body[:'options'][:'max_iterations'] = [:'max_iterations'] unless [:'max_iterations'].nil? post_body[:'options'][:'colors_limit'] = [:'colors_limit'] unless [:'colors_limit'].nil? post_body[:'options'][:'line_width'] = [:'line_width'] unless [:'line_width'].nil? end query_params = {} # header parameters header_params = {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) # HTTP header 'Content-Type' header_params['Content-Type'] = @api_client.select_header_content_type(['application/json']) # form parameters form_params = {} data, status_code, headers = @api_client.call_api(:POST, local_var_path, :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :return_type => 'OperationResult') if @api_client.config.debug @api_client.config.logger.debug "API called: Create task\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end if status_code != 200 fail ApiError.new('Conversion failed') end while true data, status_code, headers = get_status(data.id) fail ApiError.new('Conversion failed') if data.code != 200 or data.status == 'faulted' or data.status == 'canceled' break if data.status == 'completed' sleep 3 end if dst_in_local out_folder = File.dirname(dst) d = @storage_api.download_file(data.file) out_name = out_folder + '/' + File.basename(data.file) File.rename(d, out_name) data.file = out_name end data end |
#convert_local_to_local(src, dst, options = nil) ⇒ OperationResult
Converting a document from the local file and putting the result in the local file
54 55 56 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 54 def convert_local_to_local(src, dst, = nil) convert(src, dst, true, true, false, ) end |
#convert_local_to_storage(src, dst, storage, options = nil) ⇒ OperationResult
Converting a document from the local file and putting the result in the storage
71 72 73 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 71 def convert_local_to_storage(src, dst, storage, =nil) convert(src, dst, true, false, false, , storage) end |
#convert_storage_to_local(src, dst, storage, options = nil) ⇒ OperationResult
Converting a document from the storage and putting the result in the local file
88 89 90 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 88 def convert_storage_to_local(src, dst, storage, =nil) convert(src, dst, false, true, false, , storage) end |
#convert_storage_to_storage(src, dst, storage, options = nil) ⇒ OperationResult
Converting a document from the storage and putting the result in the storage
105 106 107 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 105 def convert_storage_to_storage(src, dst, storage, =nil) convert(src, dst, false, false, false, , storage) end |
#convert_url_to_local(src, dst, options = nil) ⇒ OperationResult
Converting the HTML page from URL and putting the result in the local file
121 122 123 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 121 def convert_url_to_local(src, dst, =nil) convert(src, dst, false, true, true, ) end |
#convert_url_to_storage(src, dst, storage, options = nil) ⇒ OperationResult
Converting the HTML page from URL and putting the result in the storage
138 139 140 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 138 def convert_url_to_storage(src, dst, storage, =nil) convert(src, dst, false, false, true, , storage) end |
#get_input_format(path) ⇒ Object
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 358 def get_input_format(path) ext = File.extname(path).downcase[1..-1] case ext when 'htm' return 'html' when 'mht' return 'mhtml' when 'xml' return 'xhtml' when 'jpg' return 'jpeg' when 'tif' return 'tiff' else ext end end |
#get_status(id) ⇒ Object
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 335 def get_status(id) local_var_path = "/html/conversion/{id}".sub('{' + 'id' + '}', id.to_s) # header parameters header_params = {} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept(['application/json']) # HTTP header 'Content-Type' header_params['Content-Type'] = @api_client.select_header_content_type(['application/json']) query_params = {} form_params = {} post_body = nil data, status_code, headers = @api_client.call_api(:GET, local_var_path, :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :return_type => 'OperationResult') end |
#vectorize(src, dst, src_in_local, dst_in_local, options = nil, storage_name = nil) ⇒ OperationResult
Vectorization an image from to SVG format
214 215 216 217 218 219 220 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 214 def vectorize(src, dst, src_in_local, dst_in_local, =nil, storage_name=nil) input_format = get_input_format(src) output_format = File.extname(dst).strip.downcase[1..-1] fail ApiError.new('Input format must be bmp, jpeg, gif, tiff, png') unless %w[bmp jpeg gif tiff png].include? input_format fail ApiError.new('Output format must be SVG') if output_format != 'svg' convert(src, dst, src_in_local, dst_in_local, false, , storage_name) end |
#vectorize_local_to_local(src, dst, options = nil) ⇒ OperationResult
Vectorization an image from the local file and putting the result in the local file
152 153 154 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 152 def vectorize_local_to_local(src, dst, = nil) vectorize(src, dst, true, true, ) end |
#vectorize_local_to_storage(src, dst, storage, options = nil) ⇒ OperationResult
Vectorization an image from the local file and putting the result in the storage
167 168 169 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 167 def vectorize_local_to_storage(src, dst, storage, =nil) vectorize(src, dst, true, false, , storage) end |
#vectorize_storage_to_local(src, dst, storage, options = nil) ⇒ OperationResult
Vectorization an image from the storage and putting the result in the local file
182 183 184 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 182 def vectorize_storage_to_local(src, dst, storage, =nil) vectorize(src, dst, false, true, , storage) end |
#vectorize_storage_to_storage(src, dst, storage, options = nil) ⇒ OperationResult
Vectorization an image from the storage and putting the result in the storage
197 198 199 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 197 def vectorize_storage_to_storage(src, dst, storage, =nil) vectorize(src, dst, false, false, , storage) end |