Class: Postdoc::Client
- Inherits:
-
Object
- Object
- Postdoc::Client
- Defined in:
- lib/postdoc/client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(port) ⇒ Client
constructor
A new instance of Client.
- #print_document(file_path, settings: PrintSettings.new) ⇒ Object
-
#print_pdf_from_html(file_path, settings: PrintSettings.new) ⇒ Object
We should move away from passing options like this and collect them in the prinbt settings.
Constructor Details
#initialize(port) ⇒ Client
Returns a new instance of Client.
10 11 12 13 14 |
# File 'lib/postdoc/client.rb', line 10 def initialize(port) @port = port 100.times { setup_connection_or_wait && break } raise 'ChromeClient couldn\'t launch' if @client.blank? end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
8 9 10 |
# File 'lib/postdoc/client.rb', line 8 def client @client end |
Instance Method Details
#print_document(file_path, settings: PrintSettings.new) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/postdoc/client.rb', line 30 def print_document(file_path, settings: PrintSettings.new) client.send_cmd 'Page.enable' client.send_cmd 'Page.navigate', url: "file://#{file_path}" client.wait_for 'Page.loadEventFired' response = client.send_cmd 'Page.printToPDF', settings.to_cmd Base64.decode64 response['data'] end |
#print_pdf_from_html(file_path, settings: PrintSettings.new) ⇒ Object
We should move away from passing options like this and collect them in the prinbt settings.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/postdoc/client.rb', line 18 def print_pdf_from_html(file_path, settings: PrintSettings.new) client.send_cmd 'Page.enable' client.send_cmd 'Page.navigate', url: "file://#{file_path}" client.wait_for 'Page.loadEventFired' response = client.send_cmd 'Page.printToPDF', settings.to_cmd Base64.decode64 response['data'] end |