Ruby SDK

Ruby SDK

View Markdown

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


Installation

$ gem install ittybit

Usage

Instantiate and use the client with the following:

require 'ittybit'

ittybit = Ittybit::Client.new(
  api_key: "ITTYBIT_API_KEY",
)

Then you can use the client to make requests to the API.

response = ittybit.files.list()
print(response.data)

Async Usage

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

require 'ittybit'
require 'async'

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

  response = ittybit.files.list()
  print(response.data)
end

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
  )
)

Error Handling

The SDK raises exceptions for API errors:

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

On this page