0.0
The project is in a healthy, maintained state
Official Ruby SDK for Capture (capture.page). Capture screenshots, generate PDFs, extract content and metadata from web pages.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

Capture Ruby SDK

Official Ruby SDK for Capture - Screenshot and content extraction API.

Installation

Add to your Gemfile:

gem "capture_page"

Or install directly:

gem install capture_page

Quick Start

require "capture"

client = Capture.new("your-api-key", "your-api-secret")

image_url = client.build_image_url("https://example.com")
puts image_url

Features

  • Screenshot Capture: Capture full-page or viewport screenshots as PNG/JPG
  • PDF Generation: Convert web pages to PDF documents
  • Content Extraction: Extract HTML and text content from web pages
  • Metadata Extraction: Get page metadata (title, description, og tags, etc.)
  • Animated GIFs: Create animated GIFs of page interactions
  • Browser Sessions: Create stateful browser sessions and run actions
  • Zero Dependencies: Uses only Ruby standard library

Usage

Initialize the Client

require "capture"

client = Capture.new("your-api-key", "your-api-secret")

# Use edge endpoint for faster response times
client = Capture.new("your-api-key", "your-api-secret", use_edge: true)

Building URLs

Image Capture

image_url = client.build_image_url("https://example.com")

image_url = client.build_image_url("https://example.com", {
  "full" => true,
  "delay" => 2,
  "vw" => 1920,
  "vh" => 1080
})

PDF Capture

pdf_url = client.build_pdf_url("https://example.com")

pdf_url = client.build_pdf_url("https://example.com", {
  "format" => "A4",
  "landscape" => true
})

Content Extraction

content_url = client.build_content_url("https://example.com")

Metadata Extraction

metadata_url = client.build_metadata_url("https://example.com")

Animated GIF

animated_url = client.build_animated_url("https://example.com")

Fetching Data

Fetch Image

image_data = client.fetch_image("https://example.com")
File.binwrite("screenshot.png", image_data)

Fetch PDF

pdf_data = client.fetch_pdf("https://example.com", { "full" => true })
File.binwrite("page.pdf", pdf_data)

Fetch Content

content = client.fetch_content("https://example.com")
puts content["html"]
puts content["textContent"]
puts content["markdown"]

Fetch Metadata

metadata = client.fetch_metadata("https://example.com")
puts metadata["metadata"]

Fetch Animated GIF

gif_data = client.fetch_animated("https://example.com")
File.binwrite("animation.gif", gif_data)

Browser Sessions

session = client.sessions.create("maxTtlSeconds" => 300)
session_id = session["session"]["id"]

client.sessions.action(session_id, "goto", "url" => "https://example.com")
screenshot = client.sessions.action(session_id, "screenshot", "fullPage" => true)

client.sessions.close(session_id)

Configuration Options

Constructor Options

  • use_edge (boolean): Use edge.capture.page instead of cdn.capture.page for faster response times

API Endpoints

The SDK supports two base URLs:

  • CDN: https://cdn.capture.page (default)
  • Edge: https://edge.capture.page (when use_edge: true)

License

MIT

Links

Support

For support, please visit capture.page or open an issue on GitHub.