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 =
"3.1.4"
Instance Method Summary collapse
-
#convert(**params) ⇒ Object
Converts the given file and returns a hash collection with the conversion results.
-
#download_result(results, output_file_path, file_name = nil) ⇒ Object
Downloads the zip file produced by the microservice.
-
#initialize(url, conversion_timeout: 30, auth: nil) ⇒ 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, auth: nil) ⇒ 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.
auth
-
array, (optional) the username and password to use for HTTP Authentication. Set to nil by default
43 44 45 46 47 48 |
# File 'lib/buildvu.rb', line 43 def initialize(url, conversion_timeout: 30, auth: nil) @base_endpoint = url @endpoint = @base_endpoint + '/buildvu' @convert_timeout = conversion_timeout @auth = auth end |
Instance Method Details
#convert(**params) ⇒ Object
Converts the given file and returns a hash collection with the conversion results. Requires the ‘input’ and either ‘url’ or ‘file’ parameters to run. You can then use the values from the hash, or use methods like download_result(). Params:
input
-
string, the method of inputting a file. Examples are BuildVu::UPLOAD or BuildVu::DOWNLOAD
file
-
string, (optional) Location of the PDF to convert, i.e ‘path/to/input.pdf’
url
-
string, (optional) the url for the server to download a PDF from
Returns: hash [string: string], The results of the conversion
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/buildvu.rb', line 58 def convert(**params) uuid = upload params 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' break unless params[:callbackUrl].nil? 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 response end |
#download_result(results, output_file_path, file_name = nil) ⇒ Object
Downloads the zip file produced by the microservice. Provide ‘.’ as the output_file_path if you wish to use the current directory. Will use the filename of the zip on the server if none is specified. Params:
output_file_path
-
string, the output location to save the zip file
file_name
-
string, (optional) the custom name for the zip file. This should not include .zip
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/buildvu.rb', line 84 def download_result(results, output_file_path, file_name=nil) download_url = results['downloadUrl'] raise('Error: downloadUrl parameter is empty') if download_url.nil? if file_name.nil? output_file_path += '/' + download_url.split('/').last else output_file_path += '/' + file_name + '.zip' end download download_url, output_file_path end |