Ruby SDK

Ruby SDK

View Markdown

The Ittybit Ruby library provides convenient access to the Ittybit API from Ruby applications.


Installation

Add this line to your application's Gemfile:

gem 'ittybit'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install ittybit

Usage

Basic Usage

require 'ittybit'

# Initialize the client
ittybit = Ittybit::Client.new(
  token: "ITTYBIT_API_KEY",
)

# Create a new media item
media = ittybit.media.create(
  title: "My Video",
  metadata: { "credit": "gtv-videos-bucket" }
)

# Upload a file
file = ittybit.files.create(
  url: "https://ittyb.it/sample.mp4",
  filename: "video.mp4",
  folder: "example",
  metadata: { "customKey": "your custom value" }
)

# Create a signed URL
signature = ittybit.signatures.create(
  filename: "video.mp4",
  folder: "private/user_123",
  expiry: 1735689600,
  method: "GET"
)

Async Usage

The SDK also provides async clients for non-blocking operations:

require 'ittybit'
require 'async'

Async do
  ittybit = Ittybit::AsyncClient.new(
    token: "ITTYBIT_API_KEY",
  )

  # Async operations
  media = ittybit.media.create(
    title: "My Video",
    metadata: { "credit": "gtv-videos-bucket" }
  )
end

Features

Media Management

# List all media
media_list = ittybit.media.list(limit: 10)

# Get specific media
media = ittybit.media.get(id: "media_id")

# Update media
updated_media = ittybit.media.update(
  id: "media_id",
  title: "New Title",
  metadata: { "new_key": "new_value" }
)

# Delete media
ittybit.media.delete(id: "media_id")

File Management

# List files
files = ittybit.files.list(limit: 10)

# Get file details
file = ittybit.files.get(id: "file_id")

# Upload file from URL
file = ittybit.files.create(
  url: "https://example.com/video.mp4",
  filename: "video.mp4",
  folder: "videos",
  metadata: { "source": "example" }
)

Task Management

# Get task configuration
config = ittybit.tasks.get_task_config

# Create a new task
task = ittybit.tasks.create(
  kind: "ingest",
  url: "https://example.com/video.mp4",
  input: { "format": "mp4" }
)

# Get task status
task = ittybit.tasks.get(id: "task_id")

# List tasks
tasks = ittybit.tasks.list(
  limit: 10,
  status: "completed",
  kind: "ingest"
)

Signed URLs

# Generate a signed URL
signature = ittybit.signatures.create(
  filename: "video.mp4",
  folder: "private/user_123",
  expiry: Time.now.to_i + 3600, # 1 hour from now
  method: "GET"
)

Advanced Features

Request Options

You can customize individual requests with additional options:

# Custom timeout
ittybit.media.create(
  title: "My Video",
  request_options: Ittybit::RequestOptions.new(
    timeout_in_seconds: 30
  )
)

The SDK only accepts the following headers:

  • Authorization: Bearer token for authentication (required)

Error Handling

The SDK raises exceptions for API errors:

begin
  ittybit.media.get(id: "non_existent_id")
rescue Ittybit::Error => e
  puts "Error: #{e.message}"
  puts "Status code: #{e.status_code}"
  puts "Response body: #{e.body}"
end

On this page