Class: Postdoc::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/postdoc/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientObject

Returns the value of attribute client.



8
9
10
# File 'lib/postdoc/client.rb', line 8

def client
  @client
end

Instance Method Details



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

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