SDKs
Ruby SDK
Ruby gem with Rails integration
Ruby SDK
The Ruby SDK is coming soon. Sign up for updates at allscreenshots.com.
Installation
# Gemfile
gem 'allscreenshots'bundle installOr install directly:
gem install allscreenshotsQuick start
require 'allscreenshots'
client = AllScreenshots::Client.new(api_key: ENV['ALLSCREENSHOTS_API_KEY'])
# Capture a screenshot
screenshot = client.screenshots.capture(url: 'https://example.com')
# Save to file
File.binwrite('screenshot.png', screenshot)Capture options
screenshot = client.screenshots.capture(
url: 'https://example.com',
viewport: { width: 1920, height: 1080 },
full_page: true,
dark_mode: true,
block_ads: true,
block_cookie_banners: true
)
# JSON response
result = client.screenshots.capture(
url: 'https://example.com',
response_type: :json
)
puts result.urlDevice presets
screenshot = client.screenshots.capture(
url: 'https://example.com',
device: :iphone_15
)Bulk capture
bulk_job = client.screenshots.bulk(
urls: [
{ url: 'https://example1.com' },
{ url: 'https://example2.com' },
{ url: 'https://example3.com' }
],
defaults: {
format: :png,
viewport: { width: 1280, height: 720 }
}
)
results = client.bulk.wait_for(bulk_job.bulk_job_id)Composition
composed = client.screenshots.compose(
url: 'https://example.com',
variants: [
{ device: :desktop_hd, label: 'Desktop' },
{ device: :iphone_15, label: 'Mobile' }
],
output: {
layout: :horizontal,
spacing: 20
}
)Rails integration
# config/initializers/allscreenshots.rb
AllScreenshots.configure do |config|
config.api_key = Rails.application.credentials.allscreenshots_api_key
end
# In your controller or service
class ScreenshotService
def capture(url)
AllScreenshots.client.screenshots.capture(url: url)
end
endWebhook verification
# app/controllers/webhooks_controller.rb
class WebhooksController < ApplicationController
skip_before_action :verify_authenticity_token
def allscreenshots
signature = request.headers['X-Allscreenshots-Signature']
payload = request.raw_post
unless AllScreenshots::Webhook.verify(payload, signature, webhook_secret)
head :unauthorized
return
end
event = JSON.parse(payload)
# Process webhook...
head :ok
end
private
def webhook_secret
Rails.application.credentials.allscreenshots_webhook_secret
end
endError handling
begin
screenshot = client.screenshots.capture(url: 'https://example.com')
rescue AllScreenshots::RateLimitError => e
puts "Rate limited. Retry after #{e.retry_after}s"
rescue AllScreenshots::APIError => e
puts "API error: #{e.message}"
endConfiguration
client = AllScreenshots::Client.new(
api_key: 'your-api-key',
base_url: 'https://api.allscreenshots.com',
timeout: 60,
max_retries: 3
)