example/pragmatic.rb in breezy_pdf_lite-0.0.1 vs example/pragmatic.rb in breezy_pdf_lite-0.0.2

- old
+ new

@@ -10,22 +10,15 @@ config.secret_api_key = ENV["BREEZYPDF_SECRET_API_KEY"] config.base_url = ENV.fetch("BREEZYPDF_BASE_URL", "http://localhost:5001") config.middleware_path_matchers = [/as-pdf.pdf/] end -response = BreezyPDFLite::RenderRequest.new(html).submit +render_request = BreezyPDFLite::RenderRequest.new(html) -if response.code.to_i == 201 - path = File.expand_path("example.pdf", __dir__) - - FileUtils.rm(File.expand_path("example.pdf", __dir__)) if File.exist?(path) - File.new(path, "w").tap do |file| - file.write(response.body) - - file.flush - file.close - end - - puts "Downloaded to #{path}" -else - puts "Unable to render to PDF, server responded with #{response.code}" +begin + tempfile = render_request.to_file + puts tempfile.path + puts "Enter to remove..." + gets +rescue BreezyPDFLite::BreezyPDFLiteError => e + puts "Unable to render PDF: #{e.message}" end