Class: BreezyPDFLite::RenderRequest
- Inherits:
-
Object
- Object
- BreezyPDFLite::RenderRequest
- Defined in:
- lib/breezy_pdf_lite/render_request.rb
Overview
Request conversion of a HTML string to PDF If the response isn’t a 201, raise an error
Instance Method Summary collapse
-
#initialize(body) ⇒ RenderRequest
constructor
A new instance of RenderRequest.
- #response ⇒ Object
- #to_file ⇒ Object
Constructor Details
#initialize(body) ⇒ RenderRequest
Returns a new instance of RenderRequest.
7 8 9 |
# File 'lib/breezy_pdf_lite/render_request.rb', line 7 def initialize(body) @body = body end |
Instance Method Details
#response ⇒ Object
11 12 13 14 15 |
# 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 ⇒ Object
17 18 19 20 21 22 23 24 |
# 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 |