buildvu 2.0.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +19 -7
- data/example_usage.rb +14 -19
- data/lib/buildvu.rb +37 -53
- data/lib/buildvu/version.rb +1 -1
- metadata +7 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9c8b9419f655c4e74c509c236a54ff38198811c66403799450eab9998018365d
|
|
4
|
+
data.tar.gz: ac4f73d748d450cab1418c5cbc7f8cad199fa38d3c223dc9caefcdba17858790
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 32af19cd10bfab86a2ee869499921723f3d5888ffdbd7d25f80d9f8492e8d16817847638bbbe14c78a0afed2dbff9a3a1b232916f0a314ea523a589ebf609561
|
|
7
|
+
data.tar.gz: 612e0e8f0ffe61f371428916df691ac37a715ce71e78ed0c21a1d4397fb2a18392d5d2edfd208cafba4f26ccd0e05cb91441e4f3ed3f6a80f1d9cd0b035c9d5f
|
data/README.md
CHANGED
|
@@ -46,16 +46,28 @@ require 'buildvu'
|
|
|
46
46
|
buildvu = BuildVu.new('localhost:8080/microservice-example')
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
You can now convert files by calling `convert
|
|
49
|
+
You can now convert files by calling the methods available. `convert()` will start the conversion process. For example to convert to html5:
|
|
50
50
|
```ruby
|
|
51
|
-
#
|
|
52
|
-
|
|
51
|
+
# Convert the file with the input method specified
|
|
52
|
+
results = buildvu.convert(input: BuildVu::UPLOAD)
|
|
53
53
|
|
|
54
|
-
#
|
|
55
|
-
|
|
54
|
+
# Return a URL where you can view the converted output in your web browser
|
|
55
|
+
puts results['previewUrl']
|
|
56
|
+
```
|
|
57
|
+
Alternatively, you can specify a url as the input source. This method does not require the prepare_file() method.
|
|
58
|
+
```ruby
|
|
59
|
+
# Convert the file with the input method specified
|
|
60
|
+
results = buildvu.convert(input: BuildVu::UPLOAD, url: 'http://link.to/file.pdf')
|
|
56
61
|
|
|
57
|
-
#
|
|
58
|
-
puts
|
|
62
|
+
# Return a URL where you can view the converted output in your web browser
|
|
63
|
+
puts results['previewUrl']
|
|
64
|
+
```
|
|
65
|
+
See additional parameters for `convert()` at our [API](https://github.com/idrsolutions/buildvu-microservice-example/blob/master/API.md).
|
|
66
|
+
|
|
67
|
+
Once you have converted the file you can also specify a directory to download the converted output to:
|
|
68
|
+
```ruby
|
|
69
|
+
# Optionally specify a directory to download the converted output to
|
|
70
|
+
buildvu.download_result(conversion_results, 'path/to/output/dir')
|
|
59
71
|
```
|
|
60
72
|
|
|
61
73
|
See `example_usage.rb` for examples.
|
data/example_usage.rb
CHANGED
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
require 'buildvu'
|
|
2
2
|
|
|
3
3
|
buildvu = BuildVu.new'localhost:8080/microservice-example'
|
|
4
|
-
# buildvu = BuildVu.new'https://requestinspector.com/inspect/rf41test'
|
|
5
4
|
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
|
|
9
|
-
# puts 'Converted: ' + output_url
|
|
5
|
+
# Upload a local file to the BuildVu microservice
|
|
6
|
+
# convert() returns a hash collection with the conversion results.
|
|
7
|
+
conversion_results = buildvu.convert input: BuildVu::UPLOAD, file: 'path/to/file.pdf'
|
|
10
8
|
|
|
11
|
-
|
|
9
|
+
# You can specify other parameters for the API as named parameters, for example
|
|
10
|
+
# here is the use of the callbackUrl parameter which is a URL that you want to
|
|
11
|
+
# be updated when the conversion finishes.
|
|
12
|
+
# See https://github.com/idrsolutions/buildvu-microservice-example/blob/master/API.md
|
|
13
|
+
#conversion_results = buildvu.convert input: BuildVu::UPLOAD, callbackUrl: 'http://listener.url'
|
|
12
14
|
|
|
13
|
-
#
|
|
14
|
-
|
|
15
|
-
CGI::escape uri
|
|
16
|
-
end
|
|
15
|
+
# Alternatively, you can specify a url from which the server will download the file to convert.
|
|
16
|
+
#conversion_results = buildvu.convert url: 'http://link.to/filename', input: BuildVu::DOWNLOAD
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
def decode_uri(uri)
|
|
20
|
-
CGI::unescape uri
|
|
21
|
-
end
|
|
18
|
+
output_url = conversion_results['previewUrl']
|
|
22
19
|
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
# puts 'ENCODED: ' + filename
|
|
20
|
+
# After the conversion you can also specify a directory to download the output to:
|
|
21
|
+
#buildvu.download_result conversion_results, 'path/to/output/dir'
|
|
26
22
|
|
|
27
|
-
|
|
28
|
-
# buildvu.convert('path/to/input.pdf', output_file_path: 'path/to/output/dir')
|
|
23
|
+
puts 'Converted: ' + output_url
|
data/lib/buildvu.rb
CHANGED
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
# Copyright:: IDRsolutions
|
|
20
20
|
# License:: Apache 2.0
|
|
21
21
|
|
|
22
|
-
require 'CGI'
|
|
23
22
|
require 'json'
|
|
24
23
|
require 'rest-client'
|
|
25
24
|
|
|
@@ -44,76 +43,71 @@ class BuildVu
|
|
|
44
43
|
@convert_timeout = conversion_timeout
|
|
45
44
|
end
|
|
46
45
|
|
|
47
|
-
# Converts the given file and returns
|
|
48
|
-
#
|
|
46
|
+
# Converts the given file and returns a hash collection with the conversion results. Requires the 'input' and either 'url' or
|
|
47
|
+
# 'file' parameters to run. You can then use the values from the hash, or use methods like download_result().
|
|
49
48
|
# Params:
|
|
50
|
-
# +
|
|
51
|
-
# +
|
|
49
|
+
# +input+:: string, the method of inputting a file. Examples are BuildVu::UPLOAD or BuildVu::DOWNLOAD
|
|
50
|
+
# +file+:: string, (optional) Location of the PDF to convert, i.e 'path/to/input.pdf'
|
|
51
|
+
# +url+:: string, (optional) the url for the server to download a PDF from
|
|
52
52
|
#
|
|
53
|
-
# Returns: string,
|
|
54
|
-
def convert(
|
|
55
|
-
uuid = upload
|
|
53
|
+
# Returns: hash [string: string], The results of the conversion
|
|
54
|
+
def convert(**params)
|
|
55
|
+
uuid = upload params
|
|
56
56
|
|
|
57
57
|
response = nil
|
|
58
|
-
|
|
59
58
|
# check conversion status once every second until complete or error / timeout
|
|
60
59
|
(0..@convert_timeout).each do |i|
|
|
61
60
|
sleep 1
|
|
62
61
|
response = poll_status uuid
|
|
63
62
|
|
|
64
63
|
break if response['state'] == 'processed'
|
|
64
|
+
|
|
65
|
+
break unless params['callbackUrl'].nil?
|
|
65
66
|
|
|
66
67
|
raise('Server error getting conversion status, see server logs for details') if response['state'] == 'error'
|
|
67
68
|
|
|
68
|
-
raise('Failed: File took longer than' + @convert_timeout.to_s + ' seconds to convert') if i == @convert_timeout
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
# download output
|
|
72
|
-
unless output_file_path.nil?
|
|
73
|
-
download_url = response['downloadUrl']
|
|
74
|
-
# get filename from input_file_path (downloaded file will be [filename].zip)
|
|
75
|
-
output_file_path += '/' + File.basename(input_file_path)[0..-4] + 'zip'
|
|
76
|
-
download(download_url, output_file_path)
|
|
69
|
+
raise('Failed: File took longer than ' + @convert_timeout.to_s + ' seconds to convert') if i == @convert_timeout
|
|
77
70
|
end
|
|
78
71
|
|
|
79
|
-
|
|
72
|
+
reset_files
|
|
73
|
+
response
|
|
80
74
|
end
|
|
81
75
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
#
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
76
|
+
# Downloads the zip file produced by the microservice. Provide '.' as the output_file_path if you wish to use the
|
|
77
|
+
# current directory. Will use the filename of the zip on the server if none is specified.
|
|
78
|
+
# Params:
|
|
79
|
+
# +output_file_path+:: string, the output location to save the zip file
|
|
80
|
+
# +file_name+:: string, (optional) the custom name for the zip file. This should not include .zip
|
|
81
|
+
def download_result(results, output_file_path, file_name=nil)
|
|
82
|
+
download_url = results['downloadUrl']
|
|
83
|
+
|
|
84
|
+
raise('Error: downloadUrl parameter is empty') if download_url.nil?
|
|
85
|
+
|
|
86
|
+
if file_name.nil?
|
|
87
|
+
output_file_path += '/' + download_url.split('/').last
|
|
94
88
|
else
|
|
95
|
-
|
|
89
|
+
output_file_path += '/' + file_name + '.zip'
|
|
96
90
|
end
|
|
91
|
+
|
|
92
|
+
download download_url, output_file_path
|
|
93
|
+
end
|
|
97
94
|
|
|
98
|
-
|
|
99
|
-
filename = encode_uri File.basename(input_file_path)
|
|
95
|
+
private
|
|
100
96
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
97
|
+
# Upload file at given path to converter, return UUID if successful
|
|
98
|
+
def upload(params)
|
|
99
|
+
|
|
100
|
+
file_path = params.delete('file');
|
|
101
|
+
params[:file] = File.open(file_path, 'rb') if !file_path.nil?
|
|
106
102
|
|
|
107
103
|
begin
|
|
108
|
-
# r = RestClient.post(@endpoint, {file: file}, {Content_Disposition: 'form-data; name="file"; filename:"' + filename + '"'}) # THIS WORKS?
|
|
109
|
-
# r = RestClient::Request.execute(method: :post, url: @endpoint, payload: { file: file }, headers: { Content_Disposition: 'form-data; filename:"' + filename + '"', Content_Type: 'application/pdf' })
|
|
110
104
|
r = RestClient.post(@endpoint, params)
|
|
111
105
|
rescue RestClient::ExceptionWithResponse => e
|
|
112
106
|
raise('Error sending url:\n' + e.to_s)
|
|
113
107
|
end
|
|
114
108
|
|
|
115
109
|
r.code == 200 ? uuid = JSON.parse(r.body)['uuid'] : raise('Error uploading file:\n Server returned response\n' +
|
|
116
|
-
|
|
110
|
+
r.code)
|
|
117
111
|
|
|
118
112
|
uuid.nil? ? raise('Error uploading file:\nServer returned null UUID') : uuid
|
|
119
113
|
end
|
|
@@ -127,7 +121,7 @@ class BuildVu
|
|
|
127
121
|
end
|
|
128
122
|
|
|
129
123
|
r.code == 200 ? response = JSON.parse(r.body) : raise('Error checking conversion status:\n Server returned ' +
|
|
130
|
-
|
|
124
|
+
'response\n' + r.code)
|
|
131
125
|
|
|
132
126
|
response
|
|
133
127
|
end
|
|
@@ -146,13 +140,3 @@ class BuildVu
|
|
|
146
140
|
raise('Error downloading conversion output: ' + e.to_s)
|
|
147
141
|
end
|
|
148
142
|
end
|
|
149
|
-
|
|
150
|
-
# Encode URI as per RFC-3986
|
|
151
|
-
def encode_uri(uri)
|
|
152
|
-
CGI::escape uri
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
# Decode URI as per RFC-3986
|
|
156
|
-
def decode_uri(uri)
|
|
157
|
-
CGI::unescape uri
|
|
158
|
-
end
|
data/lib/buildvu/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: buildvu
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rob Foley
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2019-05-14 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rest-client
|
|
@@ -35,20 +35,20 @@ dependencies:
|
|
|
35
35
|
name: json
|
|
36
36
|
requirement: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- - "
|
|
38
|
+
- - ">="
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: '2.1'
|
|
41
|
-
- - "
|
|
41
|
+
- - "~>"
|
|
42
42
|
- !ruby/object:Gem::Version
|
|
43
43
|
version: '2.1'
|
|
44
44
|
type: :runtime
|
|
45
45
|
prerelease: false
|
|
46
46
|
version_requirements: !ruby/object:Gem::Requirement
|
|
47
47
|
requirements:
|
|
48
|
-
- - "
|
|
48
|
+
- - ">="
|
|
49
49
|
- !ruby/object:Gem::Version
|
|
50
50
|
version: '2.1'
|
|
51
|
-
- - "
|
|
51
|
+
- - "~>"
|
|
52
52
|
- !ruby/object:Gem::Version
|
|
53
53
|
version: '2.1'
|
|
54
54
|
description: "Convert PDF to HTML5 or SVG with Ruby, using the BuildVu Ruby Client
|
|
@@ -94,8 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
94
94
|
- !ruby/object:Gem::Version
|
|
95
95
|
version: '0'
|
|
96
96
|
requirements: []
|
|
97
|
-
|
|
98
|
-
rubygems_version: 2.7.6
|
|
97
|
+
rubygems_version: 3.0.3
|
|
99
98
|
signing_key:
|
|
100
99
|
specification_version: 4
|
|
101
100
|
summary: Ruby API for IDRSolutions BuildVu Microservice
|