buildvu 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7709b66d0f68e6574c3c74be9163a4ff9713b76e830905c8eb9078a8a6d8c9f1
4
+ data.tar.gz: ebe24a14074fbc26a98824a169674edf08154e468fc029ffd7a1b19890eb1bd3
5
+ SHA512:
6
+ metadata.gz: 77100ef564a08275aa19d78699eb2bca80929b6fd2c5c375bf983079fefe0200cb7baedcc1f7517c8337ff09e338d0b50a8ae44e5b5753c636dc207bbb3a55e9
7
+ data.tar.gz: 942e645c08032259065c69bf1ed94651cc2081e41fc499b345265ee546cb9591159441d5e5804a06e3c4b69438b285d5e50c186f15b64547dea9fa4da9f0288f
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.idea/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /bin/
7
+ /doc/
8
+ /exe/
9
+ /pkg/
10
+ /spec/reports/
11
+ /tmp/
12
+ Gemfile.lock
13
+ .travis.yml
14
+ /test/
15
+ /Rakefile
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team [here](https://idrsolutions.zendesk.com/hc/en-us/requests/new). All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
@@ -0,0 +1,89 @@
1
+ # BuildVu Ruby Client #
2
+
3
+ BuildVu Ruby Client is the Ruby API for IDRSolution's [BuildVu Microservice Example](https://github.com/idrsolutions/buildvu-microservice-example).
4
+
5
+ It functions as an easy to use, plug and play library that lets you use [BuildVu](https://www.idrsolutions.com/buildvu/) from Ruby.
6
+
7
+ -----
8
+
9
+ # Installation #
10
+
11
+ ## Using RubyGems: ##
12
+
13
+ Run the following command to install
14
+
15
+ $ gem install buildvu
16
+
17
+ Alternatively, add this line to your application's .gemspec file...
18
+
19
+ ```ruby
20
+ spec.add_runtime_dependency "buildvu"
21
+ ```
22
+
23
+ ...and then execute:
24
+
25
+ $ bundle install
26
+
27
+ ## Building the gem manually: ##
28
+
29
+ Run the following command to build the gem locally:
30
+
31
+ $ gem build buildvu.gemspec
32
+
33
+ You can then install it using:
34
+
35
+ $ gem install buildvu
36
+
37
+ -----
38
+
39
+ # Usage #
40
+
41
+ ## Basic: #
42
+
43
+ Setup the converter details by creating a new `BuildVu` object:
44
+ ```ruby
45
+ require 'buildvu'
46
+ buildvu = BuildVu.new('localhost:8080/microservice-example')
47
+ ```
48
+
49
+ You can now convert files by calling `convert`:
50
+ ```ruby
51
+ # returns a URL where you can view the converted output in your web browser
52
+ puts buildvu.convert('/path/to/input/file')
53
+
54
+ # you can optionally specify a directory to download the converted output to
55
+ buildvu.convert('/path/to/input/file', '/path/to/output/dir')
56
+ ```
57
+
58
+ See `example_usage.rb` for examples.
59
+
60
+ -----
61
+
62
+ # Who do I talk to? #
63
+
64
+ Found a bug, or have a suggestion / improvement? Let us know through the Issues page.
65
+
66
+ Got questions? You can contact us [here](https://idrsolutions.zendesk.com/hc/en-us/requests/new).
67
+
68
+ -----
69
+
70
+ # Code of Conduct #
71
+
72
+ Short version: Don't be an awful person.
73
+
74
+ Longer version: Everyone interacting in the BuildVu Ruby Client project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
75
+
76
+ -----
77
+ Copyright 2018 IDRsolutions
78
+
79
+ Licensed under the Apache License, Version 2.0 (the "License");
80
+ you may not use this file except in compliance with the License.
81
+ You may obtain a copy of the License at
82
+
83
+ [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
84
+
85
+ Unless required by applicable law or agreed to in writing, software
86
+ distributed under the License is distributed on an "AS IS" BASIS,
87
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
88
+ See the License for the specific language governing permissions and
89
+ limitations under the License.
@@ -0,0 +1,29 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'buildvu/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'buildvu'
7
+ spec.version = BuildVu::VERSION
8
+ spec.authors = ['IDRsolutions']
9
+ spec.email = ['support@idrsolutions.zendesk.com']
10
+ spec.date = Time.now.strftime('%Y-%m-%d')
11
+
12
+ spec.summary = 'Ruby API for IDRSolutions BuildVu Microservice'
13
+ spec.description = 'Ruby API for IDRSolutions BuildVu Microservice Example'
14
+ spec.homepage = 'https://github.com/idrsolutions/buildvu-ruby-client'
15
+ spec.license = 'Apache-2.0'
16
+
17
+ spec.required_ruby_version = '>= 2.0.0'
18
+
19
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
20
+ f.match(%r{^(test|spec|features)/})
21
+ end
22
+ spec.bindir = 'exe'
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ['lib']
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.16', '>= 1.16.1'
27
+ spec.add_runtime_dependency 'rest-client', '~> 2.0', '>= 2.0.2'
28
+ spec.add_runtime_dependency 'json', '~> 2.1', '>= 2.1'
29
+ end
@@ -0,0 +1,10 @@
1
+ require 'buildvu'
2
+
3
+ buildvu = BuildVu.new'localhost:8080/microservice-example'
4
+
5
+ # convert returns a URL (string) where you can view the converted output.
6
+ output_url = buildvu.convert 'C:/test/general/awjune2003.pdf', 'C:\\test\\out\\'
7
+ puts 'Converted: ' + output_url
8
+
9
+ # You can also specify a directory to download the converted output to:
10
+ # buildvu.convert('path/to/input.pdf', 'path/to/output/dir')
@@ -0,0 +1,120 @@
1
+ #--
2
+ # Copyright 2018 IDRsolutions
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ #
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #++
17
+ #
18
+ # Author:: IDRsolutions (mailto:support@idrsolutions.zendesk.com)
19
+ # Copyright:: IDRsolutions
20
+ # License:: Apache 2.0
21
+
22
+ require 'JSON'
23
+ require 'rest-client'
24
+
25
+ # Used to interact with IDRsolutions' BuildVu web service
26
+ # For detailed usage instructions, see GitHub[https://github.com/idrsolutions/buildvu-ruby-client]
27
+ class BuildVu
28
+ @base_endpoint = nil
29
+ @endpoint = nil
30
+ @convert_timeout = nil
31
+
32
+ # Constructor, setup the converter details
33
+ # Params:
34
+ # +url+:: string, the URL of the BuildVu web service.
35
+ # +conversion_timeout+:: int, (optional) the time to wait (in seconds) before timing out. Set to 30 by default.
36
+ def initialize(url, conversion_timeout = 30)
37
+ @base_endpoint = url
38
+ @endpoint = @base_endpoint + '/buildvu'
39
+ @convert_timeout = conversion_timeout
40
+ end
41
+
42
+ # Converts the given file and returns the URL where the output can be previewed online. If the output_file_path
43
+ # parameter is also passed in, a copy of the output will be downloaded to the specified location.
44
+ # Params:
45
+ # +input_file_path+:: string, the location of the PDF to convert, i.e 'path/to/input.pdf'
46
+ # +output_file_path+:: string, (optional) the directory the output will be saved in, i.e 'path/to/output/dir'
47
+ #
48
+ # Returns: string, the URL where the HTML output can be previewed online
49
+ def convert(input_file_path, output_file_path = nil)
50
+ uuid = upload input_file_path
51
+
52
+ response = nil
53
+
54
+ # check conversion status once every second until complete or error / timeout
55
+ (0..@convert_timeout).each do |i|
56
+ sleep 1
57
+ response = poll_status uuid
58
+
59
+ break if response['state'] == 'processed'
60
+
61
+ raise('Error checking conversion status') if response['state'] == 'error'
62
+
63
+ raise('Failed: File took longer than ' + @convert_timeout.to_s + ' seconds to convert') if i == @convert_timeout
64
+ end
65
+
66
+ # download output
67
+ unless output_file_path.nil?
68
+ download_url = @base_endpoint + '/' + response['downloadPath']
69
+ # get filename from input_file_path (downloaded file will be [filename].zip)
70
+ output_file_path += '/' + File.basename(input_file_path)[0..-4] + 'zip'
71
+ download(download_url, output_file_path)
72
+ end
73
+
74
+ @base_endpoint + '/' + response['previewPath']
75
+ end
76
+
77
+ private
78
+
79
+ # Upload file at given path to converter, return UUID if successful
80
+ def upload(input_file_path)
81
+ file = File.open(input_file_path, 'rb')
82
+
83
+ begin
84
+ r = RestClient.post(@endpoint, file: file)
85
+ rescue RestClient::ExceptionWithResponse => e
86
+ raise('Error uploading file:\n' + e.message)
87
+ end
88
+
89
+ r.code == 200 ? uuid = JSON.parse(r.body)['uuid'] : raise('Error uploading file')
90
+
91
+ uuid
92
+ end
93
+
94
+ # Check conversion status
95
+ def poll_status(uuid)
96
+ begin
97
+ r = RestClient.get(@endpoint + '?uuid=' + uuid)
98
+ rescue RestClient::ExceptionWithResponse => e
99
+ raise('Error checking conversion status:\n' + e.to_s)
100
+ end
101
+
102
+ r.code == 200 ? response = JSON.parse(r.body) : raise('Error checking conversion status')
103
+
104
+ response
105
+ end
106
+
107
+ # Download converted output to the given location
108
+ def download(download_url, output_file_path)
109
+ File.open(output_file_path, 'wb') do |output_file|
110
+ block = lambda { |r|
111
+ r.read_body do |data|
112
+ output_file.write data
113
+ end
114
+ }
115
+ RestClient::Request.new(method: :get, url: download_url, block_response: block).execute
116
+ end
117
+ rescue RestClient::ExceptionWithResponse => e
118
+ raise('Error downloading conversion output: ' + e.to_s)
119
+ end
120
+ end
@@ -0,0 +1,3 @@
1
+ class BuildVu
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: buildvu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - IDRsolutions
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.16.1
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.16'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.16.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: rest-client
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 2.0.2
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '2.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.0.2
53
+ - !ruby/object:Gem::Dependency
54
+ name: json
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '2.1'
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '2.1'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '2.1'
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '2.1'
73
+ description: Ruby API for IDRSolutions BuildVu Microservice Example
74
+ email:
75
+ - support@idrsolutions.zendesk.com
76
+ executables: []
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - ".gitignore"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - README.md
84
+ - buildvu.gemspec
85
+ - example_usage.rb
86
+ - lib/buildvu.rb
87
+ - lib/buildvu/version.rb
88
+ homepage: https://github.com/idrsolutions/buildvu-ruby-client
89
+ licenses:
90
+ - Apache-2.0
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 2.0.0
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.7.6
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Ruby API for IDRSolutions BuildVu Microservice
112
+ test_files: []