gotenberg-client 0.1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0fbc15829e4c6309290aeaae51efed326b5615fc9a405bccd79148826e228565
4
+ data.tar.gz: 8790f7ed23f955b092a19e225816e600ae583fe5b4ee2015e2abfbd3602599ba
5
+ SHA512:
6
+ metadata.gz: 70af1f33853a717554fef28964f048deabf055d2d84f0ccacee782b7ffda1e69d6b22350e20f7f44f67db7a36df15d1c0497b8b953e8df73325ce9238860a897
7
+ data.tar.gz: b9e155dc85d125426cd29f5c41e26fce3b82b05a690f67646181bc0290e00d499144684c435669aed22a0945d4628f1b43b6ce7724ba4ac11d2c265db716fa74
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at maildejc@hotmail.be. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in gotenberg.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+ gem 'faraday'
10
+ gem 'faraday-multipart'
11
+
12
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gotenberg (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.5.0)
10
+ faraday (2.5.2)
11
+ faraday-net_http (>= 2.0, < 3.1)
12
+ ruby2_keywords (>= 0.0.4)
13
+ faraday-multipart (1.0.4)
14
+ multipart-post (~> 2)
15
+ faraday-net_http (3.0.0)
16
+ multipart-post (2.2.3)
17
+ rake (13.0.6)
18
+ rspec (3.11.0)
19
+ rspec-core (~> 3.11.0)
20
+ rspec-expectations (~> 3.11.0)
21
+ rspec-mocks (~> 3.11.0)
22
+ rspec-core (3.11.0)
23
+ rspec-support (~> 3.11.0)
24
+ rspec-expectations (3.11.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.11.0)
27
+ rspec-mocks (3.11.1)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.11.0)
30
+ rspec-support (3.11.0)
31
+ ruby2_keywords (0.0.5)
32
+
33
+ PLATFORMS
34
+ x86_64-linux
35
+
36
+ DEPENDENCIES
37
+ faraday
38
+ faraday-multipart
39
+ gotenberg!
40
+ rake (~> 13.0)
41
+ rspec (~> 3.0)
42
+
43
+ BUNDLED WITH
44
+ 2.2.19
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 jean-christophe bauduin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Gotenberg client for Ruby
2
+ Gotenberg is awesome, but using it with Ruby is complicated.
3
+ This gem is not intended to wrap the whole api of gotenberg but to make
4
+ the creation of pdf easy in ruby / ruby on rails.
5
+
6
+ this gem is young and needs a lot of updates and improvements. (work in progress, be patient, or contribute :-) )
7
+
8
+ ## install
9
+ First download and run gotenberg
10
+
11
+ $ docker run --rm -p 3000:3000 gotenberg/gotenberg:7
12
+
13
+ install gotenberg-client gem
14
+ $ gem install gotenberg-client
15
+
16
+ or add gotenberg-client to your gemfile
17
+
18
+ ## usage
19
+ you will probably use this gem in order to generate pdf in a ruby on rails background task / ruby file. Therefore, this gem do not (yet) integrate any Ruby on Rails tools.
20
+
21
+ ```ruby
22
+ require "gotenberg-client"
23
+
24
+ api_endpoint = "http://localhost:3000" # change it with your specific port and address.
25
+ gb = Gotenberg::Client.new(api_endpoint)
26
+
27
+ #check whether your endpoint is working
28
+ gb.up? #true if working
29
+
30
+ output_pdf = Tempfile.new("my-pdf.pdf")
31
+ html = "<h1> my html </h1>"
32
+ gb.html(html,output_pdf)
33
+
34
+ #do not forget to destroy your tempfile
35
+ output_pdf.close
36
+ output_pdf.unlink
37
+
38
+ ```
39
+
40
+ if you want to use rails views, the easiest way is to user "render_to_string" from `ActionController::Base`.
41
+ Let's image that you have a /app/views/test.html.erb in your project that use @customer variable.
42
+
43
+ ```ruby
44
+ gb = Gotenberg::Client.new(api_endpoint)
45
+
46
+ output_pdf = Tempfile.new("my-pdf.pdf")
47
+ ac = ActionController::Base.new()
48
+ ac.instance_variable_set(:@customer,Customer.find(params[:id]))
49
+ gb.html(ac.render_to_string("/test.html.erb"),output_pdf)
50
+
51
+ ```
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jbd0101/ruby-gotenberg-client.
56
+
57
+
58
+ ## License
59
+
60
+ do whatever you want with it
61
+
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "gotenberg"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
Binary file
Binary file
Binary file
data/gotenberg.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/gotenberg/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "gotenberg-client"
7
+ spec.version = Gotenberg::VERSION
8
+ spec.authors = ["jean-christophe bauduin"]
9
+ spec.email = ["maildejc@hotmail.be"]
10
+
11
+ spec.summary = "simple gotenberg client for ruby"
12
+ spec.description = "make the creation of pdf easy in ruby"
13
+ spec.homepage = "https://github.com/jbd0101/ruby-gotenberg-client"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.4.0"
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/jbd0101/ruby-gotenberg-client"
21
+ spec.metadata["changelog_uri"] = "https://github.com/jbd0101/ruby-gotenberg-client"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+
35
+ # For more information and examples about making a new gem, checkout our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
37
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gotenberg
4
+ VERSION = "0.1.1.3"
5
+ end
data/lib/gotenberg.rb ADDED
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'faraday'
5
+ require 'faraday/multipart'
6
+
7
+ Faraday.default_adapter = :net_http
8
+
9
+ require 'tempfile'
10
+ require_relative "gotenberg/version"
11
+
12
+ module Gotenberg
13
+ class Error < StandardError; end
14
+ # Your code goes here...
15
+ class Client
16
+ def initialize(api_url)
17
+ @api_url = api_url
18
+ end
19
+
20
+ =begin
21
+ write the pdf file in output
22
+ pre:
23
+ render, string, html that needs to be converted
24
+ output, output file
25
+ post:
26
+ pdf in the output file
27
+ true if everything ok
28
+
29
+ =end
30
+ def html(render,output)
31
+ return false unless self.up?
32
+
33
+
34
+ ind_html = Tempfile.new('index.html')
35
+ ind_html.write(render)
36
+ ind_html.rewind
37
+ payload = {
38
+ "index.html": Faraday::Multipart::FilePart.new(
39
+ File.open(ind_html),
40
+ 'text/html',
41
+ "index.html"
42
+ )
43
+ }
44
+ url= "#{@api_url}/forms/chromium/convert/html"
45
+
46
+ conn = Faraday.new(url) do |f|
47
+ f.request :multipart, flat_encode: true
48
+ f.adapter :net_http
49
+ end
50
+
51
+ response = conn.post(url, payload)
52
+ ind_html.close
53
+ ind_html.unlink
54
+ output.write(response.body.force_encoding("utf-8"))
55
+ return true
56
+
57
+ end
58
+
59
+ def up?
60
+ begin
61
+ uri = URI.parse("#{@api_url}/health")
62
+ request = Net::HTTP::Get.new(uri)
63
+ req_options = {use_ssl: uri.scheme == "https",}
64
+
65
+ response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
66
+ http.request(request)
67
+ end
68
+
69
+ if response.code == "200" && JSON.parse(response.body)["status"]=="up"
70
+ return true
71
+ end
72
+ rescue StandardError => e
73
+ return false
74
+ end
75
+ end
76
+ end
77
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gotenberg-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1.3
5
+ platform: ruby
6
+ authors:
7
+ - jean-christophe bauduin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-08-26 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: make the creation of pdf easy in ruby
14
+ email:
15
+ - maildejc@hotmail.be
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".rspec"
22
+ - CODE_OF_CONDUCT.md
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - bin/console
29
+ - bin/setup
30
+ - gotenberg-0.1.0.gem
31
+ - gotenberg-0.1.1.1.gem
32
+ - gotenberg-0.1.1.gem
33
+ - gotenberg.gemspec
34
+ - lib/gotenberg.rb
35
+ - lib/gotenberg/version.rb
36
+ homepage: https://github.com/jbd0101/ruby-gotenberg-client
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ allowed_push_host: https://rubygems.org
41
+ homepage_uri: https://github.com/jbd0101/ruby-gotenberg-client
42
+ source_code_uri: https://github.com/jbd0101/ruby-gotenberg-client
43
+ changelog_uri: https://github.com/jbd0101/ruby-gotenberg-client
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.4.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.0.4
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: simple gotenberg client for ruby
63
+ test_files: []