-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_example.rb
More file actions
executable file
·64 lines (56 loc) · 1.91 KB
/
Copy pathtest_example.rb
File metadata and controls
executable file
·64 lines (56 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env ruby
# Quick test script for PDFify gem
# Make sure your PDFify server is running first (cd pdfify && rails s)
require_relative 'lib/pdfify'
# Configure PDFify
PDFify.configure do |config|
config.api_key = "pfy_test_demo" # Replace with your actual API key
config.base_url = "http://localhost:3000" # Local PDFify server
config.timeout = 30
end
puts "PDFify Gem Test"
puts "=" * 50
puts "Configuration:"
puts " API Key: #{PDFify.configuration.api_key}"
puts " Base URL: #{PDFify.configuration.base_url}"
puts " Timeout: #{PDFify.configuration.timeout}s"
puts
# Test 1: Simple HTML conversion in sandbox mode
puts "Test 1: Simple HTML conversion (sandbox mode)"
begin
html = <<~HTML
<html>
<head>
<style>
body { font-family: Arial, sans-serif; padding: 40px; }
h1 { color: #333; }
</style>
</head>
<body>
<h1>PDFify Gem Test</h1>
<p>This is a test PDF generated by the PDFify Ruby gem.</p>
<p>Generated at: #{Time.now}</p>
</body>
</html>
HTML
pdf = PDFify.convert(html: html, test: true)
filename = "test_output_#{Time.now.to_i}.pdf"
File.binwrite(filename, pdf)
puts " ✓ SUCCESS! PDF generated: #{filename}"
puts " ✓ Size: #{pdf.bytesize} bytes (#{(pdf.bytesize / 1024.0).round(2)} KB)"
rescue => e
puts " ✗ FAILED: #{e.class} - #{e.message}"
puts " Make sure:"
puts " 1. PDFify server is running (cd pdfify && rails s)"
puts " 2. You have a valid API token"
puts " 3. Run: cd pdfify && rails runner 'puts ApiToken.first.token' to get a token"
end
puts
puts "=" * 50
puts "Test completed!"
puts
puts "Next steps:"
puts " 1. Open the generated PDF to verify it worked"
puts " 2. Try with a real API token (not sandbox mode)"
puts " 3. Test error handling by using invalid HTML or wrong API key"
puts " 4. Build and publish: gem build pdfify.gemspec && gem push pdfify-0.1.0.gem"