Ruby Examples for adaline.report
Ruby code examples for the Adaline Report API using the standard library.
All examples use Ruby's built-in net/http and json libraries. No gems required.
Setup
require "net/http"
require "json"
require "uri"
API_KEY = "your-api-key"
BASE_URL = "https://api.adaline.report"
def api_request(method, path, body = nil)
uri = URI("#{BASE_URL}#{path}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = case method
when :get then Net::HTTP::Get.new(uri)
when :post then Net::HTTP::Post.new(uri)
when :delete then Net::HTTP::Delete.new(uri)
end
request["X-API-Key"] = API_KEY
if body
request["Content-Type"] = "application/json"
request.body = body.to_json
end
response = http.request(request)
JSON.parse(response.body) unless response.body.nil? || response.body.empty?
end
Scan a Document
def scan_document(file_path)
uri = URI("#{BASE_URL}/api/v1/scan")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request["X-API-Key"] = API_KEY
form_data = [["file", File.open(file_path)]]
request.set_form(form_data, "multipart/form-data")
response = http.request(request)
JSON.parse(response.body)
end
result = scan_document("syllabus.pdf")
puts "Score: #{result['overall_score']}% (Grade #{result['grade']})"
puts "Compliant: #{result['compliant']}"
List Reports
def list_reports(page: 1, page_size: 20)
api_request(:get, "/api/v1/reports?page=#{page}&page_size=#{page_size}")
end
data = list_reports
data["items"].each do |report|
puts " #{report['filename']}: #{report['overall_score']}% (#{report['grade']})"
end
Get Report Details
def get_report(report_id)
api_request(:get, "/api/v1/reports/#{report_id}")
end
report = get_report("your-report-id")
report["categories"].each do |name, cat|
puts " #{name}: #{cat['score']}% (#{cat['passed']}/#{cat['total']})"
end
report["checks"].reject { |c| c["passed"] }.each do |check|
puts " [#{check['severity']}] #{check['details']}"
end
Create a Tag
def create_tag(name, color = nil)
body = { name: name }
body[:color] = color if color
api_request(:post, "/api/v1/tags", body)
end
tag = create_tag("needs-review", "red")
puts "Created tag: #{tag['id']}"
Tag a Report
def tag_report(tag_id, report_id)
api_request(:post, "/api/v1/tags/#{tag_id}/reports/#{report_id}")
end
tag_report(tag["id"], "your-report-id")
Share a Report
def share_report(report_id)
api_request(:post, "/api/v1/reports/#{report_id}/share")
end
share = share_report("your-report-id")
puts "Share URL: #{share['share_url']}"
Batch Scan
def batch_scan(directory)
Dir.glob(File.join(directory, "*.{pdf,docx,pptx}")).each do |file_path|
puts "Scanning #{File.basename(file_path)}..."
begin
result = scan_document(file_path)
puts " Score: #{result['overall_score']}% (#{result['grade']})"
rescue => e
puts " Error: #{e.message}"
end
end
end
batch_scan("./documents")
Error Handling
def safe_scan(file_path)
result = scan_document(file_path)
result
rescue Net::HTTPError => e
case e.response.code.to_i
when 401 then puts "Invalid API key"
when 429 then puts "Rate limited -- wait and retry"
when 400 then puts "Bad request -- check file format"
else puts "API error: #{e.response.code}"
end
nil
rescue StandardError => e
puts "Error: #{e.message}"
nil
end