Class: BuildVu
- Inherits:
-
Object
- Object
- BuildVu
- Defined in:
- lib/buildvu.rb,
lib/buildvu/version.rb
Overview
Used to interact with IDRsolutions’ BuildVu web service For detailed usage instructions, see GitHub
Constant Summary collapse
- DOWNLOAD =
'download'- UPLOAD =
'upload'- VERSION =
"2.0.1"
Instance Method Summary collapse
-
#convert(input_file_path, output_file_path: nil, input_type: UPLOAD) ⇒ Object
Converts the given file and returns the URL where the output can be previewed online.
-
#initialize(url, conversion_timeout = 30) ⇒ BuildVu
constructor
- Constructor, setup the converter details Params:
url -
string, the URL of the BuildVu web service.
- Constructor, setup the converter details Params:
Constructor Details
#initialize(url, conversion_timeout = 30) ⇒ BuildVu
Constructor, setup the converter details Params:
url-
string, the URL of the BuildVu web service.
conversion_timeout-
int, (optional) the time to wait (in seconds) before timing out. Set to 30 by default.
41 42 43 44 45 |
# File 'lib/buildvu.rb', line 41 def initialize(url, conversion_timeout = 30) @base_endpoint = url @endpoint = @base_endpoint + '/buildvu' @convert_timeout = conversion_timeout end |
Instance Method Details
#convert(input_file_path, output_file_path: nil, input_type: UPLOAD) ⇒ Object
Converts the given file and returns the URL where the output can be previewed online. If the output_file_path parameter is also passed in, a copy of the output will be downloaded to the specified location. Params:
input_file_path-
string, the location of the PDF to convert, i.e ‘path/to/input.pdf’
output_file_path-
string, (optional) the directory the output will be saved in, i.e ‘path/to/output/dir’
Returns: string, the URL where the HTML output can be previewed online
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/buildvu.rb', line 54 def convert(input_file_path, output_file_path: nil, input_type: UPLOAD) uuid = upload input_file_path, input_type response = nil # check conversion status once every second until complete or error / timeout (0..@convert_timeout).each do |i| sleep 1 response = poll_status uuid break if response['state'] == 'processed' raise('Server error getting conversion status, see server logs for details') if response['state'] == 'error' raise('Failed: File took longer than' + @convert_timeout.to_s + ' seconds to convert') if i == @convert_timeout end # download output unless output_file_path.nil? download_url = response['downloadUrl'] # get filename from input_file_path (downloaded file will be [filename].zip) output_file_path += '/' + File.basename(input_file_path)[0..-4] + 'zip' download(download_url, output_file_path) end response['previewUrl'] end |