buildvu 3.0.1 → 3.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 596d7ac9d31dcd3fe525fdecae64df05845eb9cd
4
- data.tar.gz: a230a0f3fa2ddeb9fda5a9e88386d56db6024043
2
+ SHA256:
3
+ metadata.gz: 2736428d3a17ab25da60ecb457f7c12bc082f7abeb76c90a3a5f2916a6456913
4
+ data.tar.gz: 4ff8b3bbe028c40134d1be7193f84fea2a9b63ad06ed20b2bc652ba08081e6df
5
5
  SHA512:
6
- metadata.gz: 11f28cb021db265b6a23fa53c13cc0ae7dcc70d50b0a74292c0b3df24110e0c335f03d6c60407e134dd1e40e8d94abb49fbd79259aeeba3a8c62680d59a720f1
7
- data.tar.gz: 4025e542479fc1a612bf0929c8c5e49801838557305623c985314ed9855272c095e927016ae3412632ba2fb9ee03a99fed4491eba6d23d74671c1cbebfa3e095
6
+ metadata.gz: 83a0521c1003437e9fb0c42150f0087a00d37ea88b37e64a524a63c8a22f55b71758762daaa0dd108aec6a74e3e9fb129cb23f4154f7a9ae0ca6fd00021b51be
7
+ data.tar.gz: ea0ff7ecb21520422121b935cee631f05815482502175224d94c72ea627192663752dec81c3d3b795a20fb144c852f1cde425b6c00eb13ae012a9d8a78c6e1f4
data/README.md CHANGED
@@ -4,6 +4,8 @@ Convert PDF to HTML5 or SVG with Ruby using the BuildVu Ruby Client to interact
4
4
 
5
5
  The BuildVu Microservice Example is an open source project that allows you to convert PDF to HTML5 or SVG by running [BuildVu](https://www.idrsolutions.com/buildvu/) as a web service in the cloud or on-premise.
6
6
 
7
+ IDRsolutions offer a free trial service for running BuildVu with Ruby, more infomation on this can be found [here](https://www.idrsolutions.com/buildvu/convert-pdf-in-ruby/).
8
+
7
9
  -----
8
10
 
9
11
  # Installation #
@@ -43,24 +45,31 @@ You can then install it using:
43
45
  Setup the converter details by creating a new `BuildVu` object:
44
46
  ```ruby
45
47
  require 'buildvu'
46
- buildvu = BuildVu.new('localhost:8080/microservice-example')
48
+ buildvu = BuildVu.new('http://localhost:8080/buildvu-microservice')
49
+ ```
50
+
51
+ If your BuildVu service requires authentication, you can provide credentials when you create the `BuildVu` object:
52
+
53
+ ```ruby
54
+ buildvu = BuildVu.new('http://localhost:8080/buildvu-microservice', auth: {login: 'username', pass: 'password'})
47
55
  ```
48
56
 
57
+
49
58
  You can now convert files by calling the methods available. `convert()` will start the conversion process. For example to convert to html5:
50
59
  ```ruby
51
60
  # Convert the file with the input method specified
52
61
  results = buildvu.convert(input: BuildVu::UPLOAD, file: "path/to/file.pdf")
53
62
 
54
- # Return a URL where you can view the converted output in your web browser
55
- puts results['previewUrl']
63
+ # Return a URL where you can download the converted output
64
+ puts results['downloadUrl']
56
65
  ```
57
66
  Alternatively, you can specify a url as the input source.
58
67
  ```ruby
59
68
  # Convert the file with the input method specified
60
69
  results = buildvu.convert(input: BuildVu::UPLOAD, url: 'http://link.to/file.pdf')
61
70
 
62
- # Return a URL where you can view the converted output in your web browser
63
- puts results['previewUrl']
71
+ # Return a URL where you can download the converted output
72
+ puts results['downloadUrl']
64
73
  ```
65
74
  See additional parameters for `convert()` at our [API](https://github.com/idrsolutions/buildvu-microservice-example/blob/master/API.md).
66
75
 
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
17
17
  spec.homepage = 'https://github.com/idrsolutions/buildvu-ruby-client'
18
18
  spec.license = 'Apache-2.0'
19
19
 
20
- spec.required_ruby_version = '>= 2.0.0'
20
+ spec.required_ruby_version = '>= 2.3.0'
21
21
 
22
22
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
23
23
  f.match(%r{^(test|spec|features)/})
@@ -26,6 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ['lib']
28
28
 
29
- spec.add_runtime_dependency 'rest-client', '~> 2.0', '>= 2.0.2'
29
+ spec.add_runtime_dependency 'faraday', '~> 0.17'
30
30
  spec.add_runtime_dependency 'json', '~> 2.1', '>= 2.1'
31
31
  end
@@ -1,6 +1,6 @@
1
1
  require 'buildvu'
2
2
 
3
- buildvu = BuildVu.new'localhost:8080/microservice-example'
3
+ buildvu = BuildVu.new'localhost:8080/buildvu-microservice'
4
4
 
5
5
  # Upload a local file to the BuildVu microservice
6
6
  # convert() returns a hash collection with the conversion results.
@@ -15,7 +15,7 @@ conversion_results = buildvu.convert input: BuildVu::UPLOAD, file: 'path/to/file
15
15
  # Alternatively, you can specify a url from which the server will download the file to convert.
16
16
  #conversion_results = buildvu.convert url: 'http://link.to/filename', input: BuildVu::DOWNLOAD
17
17
 
18
- output_url = conversion_results['previewUrl']
18
+ output_url = conversion_results['downloadUrl']
19
19
 
20
20
  # After the conversion you can also specify a directory to download the output to:
21
21
  #buildvu.download_result conversion_results, 'path/to/output/dir'
@@ -20,7 +20,8 @@
20
20
  # License:: Apache 2.0
21
21
 
22
22
  require 'json'
23
- require 'rest-client'
23
+ require 'Faraday'
24
+
24
25
 
25
26
  # Used to interact with IDRsolutions' BuildVu web service
26
27
  # For detailed usage instructions, see GitHub[https://github.com/idrsolutions/buildvu-ruby-client]
@@ -32,18 +33,21 @@ class BuildVu
32
33
  @base_endpoint = nil
33
34
  @endpoint = nil
34
35
  @convert_timeout = nil
36
+ @auth = nil
35
37
 
36
38
  # Constructor, setup the converter details
37
39
  # Params:
38
40
  # +url+:: string, the URL of the BuildVu web service.
39
41
  # +conversion_timeout+:: int, (optional) the time to wait (in seconds) before timing out. Set to 30 by default.
40
- def initialize(url, conversion_timeout = 30)
42
+ # +auth+:: array, (optional) the username and password to use for HTTP Authentication. Set to nil by default
43
+ def initialize(url, conversion_timeout: 30, auth: nil)
41
44
  @base_endpoint = url
42
45
  @endpoint = @base_endpoint + '/buildvu'
43
46
  @convert_timeout = conversion_timeout
47
+ @auth = auth
44
48
  end
45
49
 
46
- # Converts the given file and returns a hash collection with the conversion results. Requires the 'input' and either 'url' or
50
+ # Converts the given file and returns a hash collection with the conversion results. Requires the 'input' and either 'url' or
47
51
  # 'file' parameters to run. You can then use the values from the hash, or use methods like download_result().
48
52
  # Params:
49
53
  # +input+:: string, the method of inputting a file. Examples are BuildVu::UPLOAD or BuildVu::DOWNLOAD
@@ -61,7 +65,7 @@ class BuildVu
61
65
  response = poll_status uuid
62
66
 
63
67
  break if response['state'] == 'processed'
64
-
68
+
65
69
  break unless params[:callbackUrl].nil?
66
70
 
67
71
  raise('Server error getting conversion status, see server logs for details') if response['state'] == 'error'
@@ -72,22 +76,22 @@ class BuildVu
72
76
  response
73
77
  end
74
78
 
75
- # Downloads the zip file produced by the microservice. Provide '.' as the output_file_path if you wish to use the
79
+ # Downloads the zip file produced by the microservice. Provide '.' as the output_file_path if you wish to use the
76
80
  # current directory. Will use the filename of the zip on the server if none is specified.
77
81
  # Params:
78
82
  # +output_file_path+:: string, the output location to save the zip file
79
83
  # +file_name+:: string, (optional) the custom name for the zip file. This should not include .zip
80
84
  def download_result(results, output_file_path, file_name=nil)
81
85
  download_url = results['downloadUrl']
82
-
86
+
83
87
  raise('Error: downloadUrl parameter is empty') if download_url.nil?
84
-
88
+
85
89
  if file_name.nil?
86
90
  output_file_path += '/' + download_url.split('/').last
87
91
  else
88
- output_file_path += '/' + file_name + '.zip'
92
+ output_file_path += '/' + file_name + '.zip'
89
93
  end
90
-
94
+
91
95
  download download_url, output_file_path
92
96
  end
93
97
 
@@ -95,47 +99,65 @@ class BuildVu
95
99
 
96
100
  # Upload file at given path to converter, return UUID if successful
97
101
  def upload(params)
98
-
99
- file_path = params.delete(:file);
100
- params[:file] = File.open(file_path, 'rb') if !file_path.nil?
102
+
103
+ file_path = params.delete(:file)
104
+ params[:file] = Faraday::UploadIO.new(file_path, 'application/pdf') if !file_path.nil?
105
+
106
+ uri = URI(@endpoint)
107
+ host = uri.scheme + "://" + uri.host + ':' + uri.port.to_s;
101
108
 
102
109
  begin
103
- r = RestClient.post(@endpoint, params)
104
- rescue RestClient::ExceptionWithResponse => e
110
+ conn = Faraday.new(host) do |f|
111
+ f.request :multipart
112
+ f.request :url_encoded
113
+ f.adapter Faraday.default_adapter
114
+ f.basic_auth @auth[:login], @auth[:pass] unless @auth.nil?
115
+ end
116
+
117
+ r = conn.post(uri.path, params)
118
+
119
+ rescue StandardError => e
105
120
  raise("Error sending url:\n" + e.to_s)
106
121
  end
107
122
 
108
- r.code == 200 ? uuid = JSON.parse(r.body)['uuid'] : raise("Error uploading file:\n Server returned response\n" +
109
- r.code)
123
+ raise "Error uploading file:\n Server returned 401 - Unauthorized" if r.status == 401
124
+ r.status == 200 ? uuid = JSON.parse(r.body)['uuid'] : raise("Error uploading file:\n Server returned response\n" + r.status.to_s + " - " + JSON.parse(r.body)['error'])
110
125
 
111
126
  uuid.nil? ? raise("Error uploading file:\nServer returned null UUID") : uuid
112
127
  end
113
128
 
114
129
  # Check conversion status
115
130
  def poll_status(uuid)
131
+ uri = URI(@endpoint)
132
+ host = uri.scheme + "://" + uri.host + ':' + uri.port.to_s;
133
+
116
134
  begin
117
- r = RestClient.get(@endpoint + '?uuid=' + uuid)
118
- rescue RestClient::ExceptionWithResponse => e
135
+ conn = Faraday.new(host) do |req|
136
+ req.params['uuid'] = uuid
137
+ req.request :url_encoded
138
+ req.adapter Faraday.default_adapter
139
+ req.basic_auth @auth[:login], @auth[:pass] unless @auth.nil?
140
+ end
141
+ r = conn.get(uri.path)
142
+ rescue StandardError => e
119
143
  raise("Error checking conversion status:\n" + e.to_s)
120
144
  end
121
145
 
122
- r.code == 200 ? response = JSON.parse(r.body) : raise("Error checking conversion status:\n Server returned " +
123
- "response\n" + r.code)
146
+ r.status == 200 ? response = JSON.parse(r.body) : raise("Error checking conversion status:\n Server returned response\n" + r.status.to_s + " - " + JSON.parse(r.body)['error'])
124
147
 
125
148
  response
126
149
  end
127
150
 
128
151
  # Download converted output to the given location
129
152
  def download(download_url, output_file_path)
130
- File.open(output_file_path, 'wb') do |output_file|
131
- block = lambda { |r|
132
- r.read_body do |data|
133
- output_file.write data
134
- end
135
- }
136
- RestClient::Request.new(method: :get, url: download_url, block_response: block).execute
153
+ conn = Faraday.new download_url do |req|
154
+ req.adapter Faraday.default_adapter
155
+ req.basic_auth @auth[:login], @auth[:pass] unless @auth.nil?
137
156
  end
138
- rescue RestClient::ExceptionWithResponse => e
157
+ response = conn.get(download_url)
158
+ File.open(output_file_path, 'wb') { |fp| fp.write(response.body) }
159
+
160
+ rescue StandardError => e
139
161
  raise('Error downloading conversion output: ' + e.to_s)
140
162
  end
141
163
  end
@@ -1,3 +1,3 @@
1
1
  class BuildVu
2
- VERSION = "3.0.1"
2
+ VERSION = "3.1.3"
3
3
  end
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: 3.0.1
4
+ version: 3.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Foley
@@ -9,46 +9,40 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-06-13 00:00:00.000000000 Z
12
+ date: 2019-12-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rest-client
15
+ name: faraday
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '2.0'
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: 2.0.2
20
+ version: '0.17'
24
21
  type: :runtime
25
22
  prerelease: false
26
23
  version_requirements: !ruby/object:Gem::Requirement
27
24
  requirements:
28
25
  - - "~>"
29
26
  - !ruby/object:Gem::Version
30
- version: '2.0'
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 2.0.2
27
+ version: '0.17'
34
28
  - !ruby/object:Gem::Dependency
35
29
  name: json
36
30
  requirement: !ruby/object:Gem::Requirement
37
31
  requirements:
38
- - - "~>"
32
+ - - ">="
39
33
  - !ruby/object:Gem::Version
40
34
  version: '2.1'
41
- - - ">="
35
+ - - "~>"
42
36
  - !ruby/object:Gem::Version
43
37
  version: '2.1'
44
38
  type: :runtime
45
39
  prerelease: false
46
40
  version_requirements: !ruby/object:Gem::Requirement
47
41
  requirements:
48
- - - "~>"
42
+ - - ">="
49
43
  - !ruby/object:Gem::Version
50
44
  version: '2.1'
51
- - - ">="
45
+ - - "~>"
52
46
  - !ruby/object:Gem::Version
53
47
  version: '2.1'
54
48
  description: "Convert PDF to HTML5 or SVG with Ruby, using the BuildVu Ruby Client
@@ -87,15 +81,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
87
81
  requirements:
88
82
  - - ">="
89
83
  - !ruby/object:Gem::Version
90
- version: 2.0.0
84
+ version: 2.3.0
91
85
  required_rubygems_version: !ruby/object:Gem::Requirement
92
86
  requirements:
93
87
  - - ">="
94
88
  - !ruby/object:Gem::Version
95
89
  version: '0'
96
90
  requirements: []
97
- rubyforge_project:
98
- rubygems_version: 2.6.14.1
91
+ rubygems_version: 3.0.3
99
92
  signing_key:
100
93
  specification_version: 4
101
94
  summary: Ruby API for IDRSolutions BuildVu Microservice