Sha256: 4d672b36719b6c703a93daf3fce69a1cfdb3f2139d7e21b457323be74b86ed4d

Contents?: true

Size: 725 Bytes

Versions: 4

Compression:

Stored size: 725 Bytes

Contents

# frozen_string_literal: true

module BreezyPDFLite
  # RenderRequest -> Net::HTTPResponse wrapper that is streaming compatable
  class Response
    def initialize(response)
      @response = response
    end

    def status
      @status ||= @response.code.to_i
    end

    def headers
      {
        "Content-Type" => "application/pdf",
        "Content-Length" => @response.header["Content-Length"],
        "Content-Disposition" => @response.header["Content-Disposition"]
      }
    end

    def each(&blk)
      @response.read_body(&blk)
    end

    def body
      io = StringIO.new
      io.binmode

      each do |chunk|
        io.write chunk
      end

      io.flush
      io.rewind

      io
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
breezy_pdf_lite-0.1.1 lib/breezy_pdf_lite/response.rb
breezy_pdf_lite-0.1.0 lib/breezy_pdf_lite/response.rb
breezy_pdf_lite-0.0.7 lib/breezy_pdf_lite/response.rb
breezy_pdf_lite-0.0.6 lib/breezy_pdf_lite/response.rb