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) ⇒ ConversionResult
Converting the HTML document to various formats.
-
#convert_local_to_local(src, dst, options = nil) ⇒ ConversionResult
Converting the HTML, EPUB document from the local file and putting the result in the local file.
-
#convert_local_to_storage(src, dst, storage, options = nil) ⇒ ConversionResult
Converting the HTML, EPUB document from the local file and putting the result in the storage.
-
#convert_storage_to_local(src, dst, storage, options = nil) ⇒ ConversionResult
Converting the HTML, EPUB document from the storage and putting the result in the local file.
-
#convert_storage_to_storage(src, dst, storage, options = nil) ⇒ ConversionResult
Converting the HTML, EPUB document from the storage and putting the result in the storage.
-
#convert_url_to_local(src, dst, options = nil) ⇒ ConversionResult
Converting the HTML page from URL and putting the result in the local file.
-
#convert_url_to_storage(src, dst, storage, options = nil) ⇒ ConversionResult
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.
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) ⇒ ConversionResult
Converting the HTML document to various formats
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 158 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? 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 => 'ConversionResult') 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) ⇒ ConversionResult
Converting the HTML, EPUB 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) ⇒ ConversionResult
Converting the HTML, EPUB 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) ⇒ ConversionResult
Converting the HTML, EPUB 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) ⇒ ConversionResult
Converting the HTML, EPUB 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) ⇒ ConversionResult
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) ⇒ ConversionResult
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
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 270 def get_input_format(path) ext = File.extname(path).upcase case ext when '.HTML', '.HTM' return 'html' when '.MHT', '.MHTML' return 'mhtml' when '.XHTML', '.XML' return 'xhtml' when '.EPUB' return 'epub' when '.SVG' return 'svg' when '.MD' return 'md' else return nil end end |
#get_status(id) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/aspose_html_cloud/api/html_api.rb', line 247 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 => 'ConversionResult') end |