class BreezyPDFLite::RenderRequest

Request conversion of a HTML string to PDF If the response isn't a 201, raise an error

Public Class Methods

new(body) click to toggle source
# File lib/breezy_pdf_lite/render_request.rb, line 7
def initialize(body)
  @body = body
end

Public Instance Methods

response() click to toggle source
# File lib/breezy_pdf_lite/render_request.rb, line 11
def response
  @response ||= submit.tap do |resp|
    raise RenderError, "#{resp.code}: #{resp.body}" if resp.code != "201"
  end
end
to_file() click to toggle source
# File lib/breezy_pdf_lite/render_request.rb, line 17
def to_file
  @to_file ||= Tempfile.new(%w[response .pdf]).tap do |file|
    file.binmode
    file.write response.body
    file.flush
    file.rewind
  end
end

Private Instance Methods

client() click to toggle source
# File lib/breezy_pdf_lite/render_request.rb, line 32
def client
  @client ||= Client.new
end
submit() click to toggle source
# File lib/breezy_pdf_lite/render_request.rb, line 28
def submit
  client.post("/render/html", @body)
end