Sha256: 148322f8c6f48ebe0a3951c9aaf82c5ef5a7619437edf7437d614e9f2ea88177
Contents?: true
Size: 741 Bytes
Versions: 4
Compression:
Stored size: 741 Bytes
Contents
# frozen_string_literal: true module Api module V1 module Helper # This class is responsible to convert a response to a pdf file. class PdfFromResponse def initialize(response) @response = response end def to_pdf(filename = Time.now.to_s) raise ArgumentError, 'Response is not a Faraday::Response' unless @response.is_a?(Faraday::Response) raise ArgumentError, 'Response is not a PDF file' unless response.body.start_with?('%PDF-1.4') file = Tempfile.new([filename.to_s, '.pdf'], binmode: true) file.write(response.body) file.close { response: @response, path_to_pdf_file: file.path } end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems