Sha256: 880e01e4e86175988527ba3f943bac68d8d96e1ef607ea530c5635361f0b4d1a

Contents?: true

Size: 649 Bytes

Versions: 2

Compression:

Stored size: 649 Bytes

Contents

# frozen_string_literal: true

module BreezyPDFLite
  # Request conversion of a HTML string to PDF
  class RenderRequest
    def initialize(body)
      @body = body
    end

    def submit
      client.post("/render/html", @body)
    end

    def to_file
      raise RenderError, "#{response.code}: #{response.body}" if response.code != "201"

      @to_file ||= Tempfile.new(%w[response .pdf]).tap do |file|
        file.binmode
        file.write response.body
        file.flush
        file.rewind
      end
    end

    private

    def response
      @response ||= submit
    end

    def client
      @client ||= Client.new
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
breezy_pdf_lite-0.0.7 lib/breezy_pdf_lite/render_request.rb
breezy_pdf_lite-0.0.6 lib/breezy_pdf_lite/render_request.rb