Class: Gotenberg::Rails::Client

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

Constant Summary collapse

HTML_PATH =
"/forms/chromium/convert/html"
URL_PATH =
"/forms/chromium/convert/url"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint:, open_timeout:, request_timeout:, headers: {}) ⇒ Client

Returns a new instance of Client.



16
17
18
19
20
21
# File 'lib/gotenberg/rails/client.rb', line 16

def initialize(endpoint:, open_timeout:, request_timeout:, headers: {})
  @endpoint = endpoint.to_s.delete_suffix("/")
  @open_timeout = open_timeout
  @request_timeout = request_timeout
  @headers = headers
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



14
15
16
# File 'lib/gotenberg/rails/client.rb', line 14

def endpoint
  @endpoint
end

#headersObject (readonly)

Returns the value of attribute headers.



14
15
16
# File 'lib/gotenberg/rails/client.rb', line 14

def headers
  @headers
end

#open_timeoutObject (readonly)

Returns the value of attribute open_timeout.



14
15
16
# File 'lib/gotenberg/rails/client.rb', line 14

def open_timeout
  @open_timeout
end

#request_timeoutObject (readonly)

Returns the value of attribute request_timeout.



14
15
16
# File 'lib/gotenberg/rails/client.rb', line 14

def request_timeout
  @request_timeout
end

Instance Method Details

#render_pdf(html: nil, url: nil, pdf_options: {}, filename: nil, trace: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gotenberg/rails/client.rb', line 23

def render_pdf(html: nil, url: nil, pdf_options: {}, filename: nil, trace: nil)
  if html && url
    raise ArgumentError, "Provide either :html or :url, not both"
  elsif html
    post(HTML_PATH, html_form(html, pdf_options), filename:, trace:)
  elsif url
    post(URL_PATH, url_form(url, pdf_options), filename:, trace:)
  else
    raise ArgumentError, "Provide :html or :url"
  end
end