Class: PDFactory::Client
- Inherits:
-
Object
- Object
- PDFactory::Client
- Defined in:
- lib/pdfactory/client.rb
Defined Under Namespace
Classes: ArgumentError
Instance Method Summary collapse
- #html2pdf(html) ⇒ Object
-
#initialize(url: ENV['PDFACTORY_URL'], user: ENV['PDFACTORY_USER'], password: ENV['PDFACTORY_PASSWORD']) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(url: ENV['PDFACTORY_URL'], user: ENV['PDFACTORY_USER'], password: ENV['PDFACTORY_PASSWORD']) ⇒ Client
Returns a new instance of Client.
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/pdfactory/client.rb', line 9 def initialize(url: ENV['PDFACTORY_URL'], user: ENV['PDFACTORY_USER'], password: ENV['PDFACTORY_PASSWORD']) url or raise ArgumentError.new('Service URL not set') if blank?(user) && blank?(password) # Allowed for open servers (eg: local) else user or raise ArgumentError.new('User must be set') password or raise ArgumentError.new('Password must be set') end @url = url @user = user @password = password end |
Instance Method Details
#html2pdf(html) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/pdfactory/client.rb', line 23 def html2pdf(html) pdf = call_api('/pdf', { html: html }) return unless pdf Base64.decode64(pdf) end |