Class: Browserless::Client

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html:, options: {}, **kwargs) ⇒ Client

Returns a new instance of Client.



12
13
14
15
16
17
18
# File 'lib/browserless/client.rb', line 12

def initialize(html:, options: {}, **kwargs)
  @html = html
  @options = Options.new(**options).to_h
  @style_tag = StyleTag.new(kwargs[:style_tag]).to_h
  @emulate_media = config_value(:emulate_media, kwargs[:emulate_media]) || "screen"
  @url = Browserless.configuration.url
end

Instance Attribute Details

#emulate_mediaObject (readonly)

Returns the value of attribute emulate_media.



10
11
12
# File 'lib/browserless/client.rb', line 10

def emulate_media
  @emulate_media
end

#htmlObject (readonly)

Returns the value of attribute html.



10
11
12
# File 'lib/browserless/client.rb', line 10

def html
  @html
end

#optionsObject (readonly)

Returns the value of attribute options.



10
11
12
# File 'lib/browserless/client.rb', line 10

def options
  @options
end

#style_tagObject (readonly)

Returns the value of attribute style_tag.



10
11
12
# File 'lib/browserless/client.rb', line 10

def style_tag
  @style_tag
end

#urlObject (readonly)

Returns the value of attribute url.



10
11
12
# File 'lib/browserless/client.rb', line 10

def url
  @url
end

Class Method Details

.headersObject



79
80
81
82
83
84
# File 'lib/browserless/client.rb', line 79

def headers
  {
    "Cache-Control": "no-cache",
    "Content-Type": "application/json"
  }
end

Instance Method Details

#to_pdfObject



20
21
22
23
24
25
26
27
28
# File 'lib/browserless/client.rb', line 20

def to_pdf
  temp_file = Tempfile.new
  save_pdf_to_temp_file(temp_file)

  temp_file.read
ensure
  temp_file.close
  temp_file.unlink
end