Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ keywords: ["changelog", "API updates", "release notes", "what's new", "API chang
To subscribe to updates, please [**“Turn on notifications”**](https://help.x.com/en/managing-your-account/notifications-on-mobile-devices#:~:text=In%20the%20top%20menu,%20you,you%20would%20like%20to%20receive) for [**@API**](https://x.com/api). You can also follow this changelog in your feed reader via the [**RSS feed**](https://docs.x.com/changelog/rss.xml).

<Update label="Dec 3, 2026" description="SDKs">
### Ruby bindings for Chat XDK (`chat_xdk`)
### Official Ruby XDK (`xdk`) and Ruby Chat XDK (`chat_xdk`)

Official **Ruby** bindings for the X Chat encryption SDK are now available as the [`chat_xdk`](https://rubygems.org/gems/chat_xdk) gem (Ruby 3.0+):
Both official **Ruby** libraries (Ruby 3.0+) are now live on RubyGems:

- **Prebuilt native libraries:** Platform gems bundle `libchat_xdk_ffi` for macOS (`arm64-darwin`, `x86_64-darwin`), Linux (`x86_64-linux`, `aarch64-linux`), and Windows (`x64-mingw-ucrt`) with no Rust toolchain required.
- **Full API parity:** Key generation, Juicebox PIN-backed storage (`setup` / `unlock`), raw key export/import (`export_keys` / `import_keys`), batch and single-event decryption (`decrypt_events` / `decrypt_event`), automatic public-key resolution (`set_resolve_public_keys`), message and file encryption, and signed group/conversation actions.
- **Ruby XDK ([`xdk`](https://rubygems.org/gems/xdk) `0.1.0`):** Official X API v2 client with zero runtime dependencies (stdlib `net/http`), full v2 resource coverage (including `/2/chat/*`), Bearer Token / OAuth 2.0 PKCE / OAuth 1.0a authentication, lazy `Enumerator` pagination, and real-time streaming with keep-alive callbacks and idle-timeout recovery. See [Ruby XDK](/xdks/ruby/overview) and [xdevplatform/xdk-ruby](https://github.com/xdevplatform/xdk-ruby).
- **Ruby Chat XDK ([`chat_xdk`](https://rubygems.org/gems/chat_xdk) `0.7.10`):** End-to-end encryption SDK for X Chat DMs bundling `libchat_xdk_ffi` for macOS (`arm64-darwin`, `x86_64-darwin`), Linux (`x86_64-linux`, `aarch64-linux`), and Windows (`x64-mingw-ucrt`). See [Chat XDK](/xchat/xchat-xdk) and [`chat-xdk/examples/ruby`](https://github.com/xdevplatform/chat-xdk/tree/main/examples/ruby).

Install with `gem install chat_xdk` and see [Chat XDK](/xchat/xchat-xdk) and [`chat-xdk/examples/ruby`](https://github.com/xdevplatform/chat-xdk/tree/main/examples/ruby).
Install both with `gem install xdk chat_xdk`.
</Update>

<Update label="Dec 2, 2026" description="SDKs">
Expand Down
18 changes: 18 additions & 0 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1292,6 +1292,24 @@
]
}
]
},
{
"dropdown": "Ruby",
"description": "xdk gem",
"icon": "gem",
"groups": [
{
"group": "Guides",
"pages": [
"xdks/ruby/overview",
"xdks/ruby/install",
"xdks/ruby/quickstart",
"xdks/ruby/authentication",
"xdks/ruby/pagination",
"xdks/ruby/streaming"
]
}
]
}
]
},
Expand Down
6 changes: 3 additions & 3 deletions xchat/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ X Chat apps use two pieces together:
| Component | Role |
|:----------|:-----|
| **[Chat XDK](/xchat/xchat-xdk)** | Encryption, decryption, signing, and private key storage (secure key backup or a key blob) |
| **X API** | Public keys, conversation keys, messages, and events: via the [Python](/xdks/python/overview), [TypeScript](/xdks/typescript/overview), [Java](/xdks/java/overview), or [C#](/xdks/csharp/overview) XDK, or HTTPS with a user access token |
| **X API** | Public keys, conversation keys, messages, and events: via the [Python](/xdks/python/overview), [TypeScript](/xdks/typescript/overview), [Java](/xdks/java/overview), [C#](/xdks/csharp/overview), or [Ruby](/xdks/ruby/overview) XDK, or HTTPS with a user access token |

<Note>
**Prerequisites**
Expand Down Expand Up @@ -84,10 +84,10 @@ X Chat apps use two pieces together:
</Tab>
<Tab title="Ruby">
```bash
gem install chat_xdk
gem install chat_xdk xdk
```

Available on RubyGems. Published platform gems bundle the native library for macOS (`arm64-darwin`, `x86_64-darwin`), Linux (`x86_64-linux`, `aarch64-linux`), and Windows (`x64-mingw-ucrt`). Import with `require "chat_xdk"`. Requires Ruby 3.0+.
Available on RubyGems. `chat_xdk` platform gems bundle the native library for macOS (`arm64-darwin`, `x86_64-darwin`), Linux (`x86_64-linux`, `aarch64-linux`), and Windows (`x64-mingw-ucrt`), and `xdk` has zero runtime dependencies. Requires Ruby 3.0+.
</Tab>
</Tabs>

Expand Down
2 changes: 1 addition & 1 deletion xchat/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The **X Chat API** lets you send and receive **encrypted** direct messages on X.
| Piece | Responsibility |
|:------|:---------------|
| **[Chat XDK](/xchat/xchat-xdk)** | Generate keys, encrypt/decrypt, sign/verify, optional passcode-protected secure key backup (Python, JS, Rust, Go, C#, Java, Ruby) |
| **X API access** | Public keys, conversation keys, messages, events, media: via **[XDK](/xdks/overview)** ([Python](/xdks/python/overview), [TypeScript](/xdks/typescript/overview), [Java](/xdks/java/overview), [C#](/xdks/csharp/overview)) or HTTPS |
| **X API access** | Public keys, conversation keys, messages, events, media: via **[XDK](/xdks/overview)** ([Python](/xdks/python/overview), [TypeScript](/xdks/typescript/overview), [Java](/xdks/java/overview), [C#](/xdks/csharp/overview), [Ruby](/xdks/ruby/overview)) or HTTPS |
| **Delivery** | [Webhooks or activity stream](/xchat/real-time-events) for live events; events API for history |

Follow **[Getting Started](/xchat/getting-started)** for a full implementation. For concepts only, see the **[Cryptography primer](/xchat/cryptography-primer)**.
Expand Down
2 changes: 1 addition & 1 deletion xchat/xchat-xdk.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: "Meet the Chat XDK, the library that handles keys, encryption, decr
keywords: ["Chat XDK", "chat-xdk", "encryption SDK", "key management", "signing", "SDK reference"]
---

The **Chat XDK** handles key management, encryption, decryption, and signing for X Chat. It does **not** call the X HTTP API: pair it with the [Python](/xdks/python/overview), [TypeScript](/xdks/typescript/overview), [Java](/xdks/java/overview), or [C#](/xdks/csharp/overview) **XDK**, or with HTTPS and a user access token.
The **Chat XDK** handles key management, encryption, decryption, and signing for X Chat. It does **not** call the X HTTP API: pair it with the [Python](/xdks/python/overview), [TypeScript](/xdks/typescript/overview), [Java](/xdks/java/overview), [C#](/xdks/csharp/overview), or [Ruby](/xdks/ruby/overview) **XDK**, or with HTTPS and a user access token.

App walkthrough: [Getting Started](/xchat/getting-started). Sample bots: [chat-xdk/examples](https://github.com/xdevplatform/chat-xdk/tree/main/examples).

Expand Down
28 changes: 24 additions & 4 deletions xdks/overview.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
---
title: XDKs
sidebarTitle: All SDKs
description: Official client libraries for the X API v2 in Python, TypeScript, Java, and C#.
keywords: ["XDK", "X SDK", "Python SDK", "TypeScript SDK", "Java SDK", "C# SDK", ".NET SDK", "X API v2", "client libraries"]
description: Official client libraries for the X API v2 in Python, TypeScript, Java, C#, and Ruby.
keywords: ["XDK", "X SDK", "Python SDK", "TypeScript SDK", "Java SDK", "C# SDK", ".NET SDK", "Ruby SDK", "X API v2", "client libraries"]
---

The X Developer Kits (XDKs) are X's client libraries for the X API v2, generated from the [X API OpenAPI spec](https://api.x.com/2/openapi.json).
Expand All @@ -20,6 +20,9 @@ The X Developer Kits (XDKs) are X's client libraries for the X API v2, generated
<Card title="C# / .NET" icon="code" href="/xdks/csharp/overview">
`dotnet add package XDevPlatform.Xdk` · .NET 8+
</Card>
<Card title="Ruby" icon="gem" href="/xdks/ruby/overview">
`gem install xdk` · Ruby 3.0+
</Card>
</CardGroup>

---
Expand All @@ -32,6 +35,7 @@ The X Developer Kits (XDKs) are X's client libraries for the X API v2, generated
| **TypeScript / JS** | `@xdevplatform/xdk` | Node.js 18+ | [npm](https://www.npmjs.com/package/@xdevplatform/xdk) | [xdk-typescript](https://github.com/xdevplatform/xdk-typescript) |
| **Java** | `com.x:xdk:0.4.0` | Java 8+ | [Maven Central](https://central.sonatype.com/artifact/com.x/xdk) | [xdk-java](https://github.com/xdevplatform/xdk-java) |
| **C# / .NET** | `XDevPlatform.Xdk` | .NET 8.0+ | [NuGet](https://www.nuget.org/packages/XDevPlatform.Xdk) | [xdk-csharp](https://github.com/xdevplatform/xdk-csharp) |
| **Ruby** | `xdk` | Ruby 3.0+ | [RubyGems](https://rubygems.org/gems/xdk) | [xdk-ruby](https://github.com/xdevplatform/xdk-ruby) |

---

Expand Down Expand Up @@ -121,6 +125,22 @@ var response = await client.Users.GetByUsernameAsync(
UserFields = new List<string> { "created_at", "public_metrics" },
});
Console.WriteLine(response.Data);
```
</Tab>
<Tab title="Ruby">
```bash
gem install xdk
```

```ruby
require "xdk"

client = Xdk::Client.new(bearer_token: ENV.fetch("X_BEARER_TOKEN"))
response = client.users.get_by_username(
username: "XDevelopers",
user_fields: %w[created_at public_metrics]
)
puts response["data"]
```
</Tab>
</Tabs>
Expand All @@ -131,9 +151,9 @@ Console.WriteLine(response.Data);

- **Typed clients** — One sub-client per X API v2 resource (`posts`, `users`, `stream`, `direct_messages`, `spaces`, `lists`, `media`, `webhooks`, `chat`, and more).
- **Authentication** — Bearer Token, OAuth 2.0 with PKCE and token refresh, and OAuth 1.0a.
- **Pagination** — Cursor handling via Python generators, TypeScript `Paginator`, Java `Paginator<T>`, and C# `IAsyncEnumerable<T>`.
- **Pagination** — Cursor handling via Python generators, TypeScript `Paginator`, Java `Paginator<T>`, C# `IAsyncEnumerable<T>`, and Ruby `Enumerator`.
- **Streaming** — Live event streams for Filtered Stream, Sample Streams, Firehose, Compliance, and Activity.

<Tip>
For encrypted X Chat messages, see the [Chat XDK](/xchat/xchat-xdk) (Python, TypeScript, Java, C#, Go, and Rust).
For encrypted X Chat messages, see the [Chat XDK](/xchat/xchat-xdk) (Python, TypeScript, Java, C#, Ruby, Go, and Rust).
</Tip>
70 changes: 70 additions & 0 deletions xdks/ruby/authentication.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
title: Authentication in Ruby XDK
sidebarTitle: Authentication
description: Configure Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a authentication with the Ruby XDK.
keywords: ["Ruby XDK auth", "OAuth 2.0 PKCE Ruby", "OAuth 1.0a Ruby", "Bearer Token Ruby"]
---

`Xdk::Client` supports all three X API authentication schemes and automatically chooses the appropriate header for each endpoint (preferring user context on write endpoints and Bearer Token on read endpoints when multiple credentials are supplied).

## Bearer Token (App-Only)

```ruby
client = Xdk::Client.new(bearer_token: ENV.fetch("X_BEARER_TOKEN"))
```

## OAuth 2.0 User Context (PKCE)

### With an existing user access token

```ruby
client = Xdk::Client.new(access_token: ENV.fetch("X_ACCESS_TOKEN"))
```

### Full PKCE authorization & refresh flow

```ruby
client = Xdk::Client.new(
client_id: ENV.fetch("X_CLIENT_ID"),
client_secret: ENV["X_CLIENT_SECRET"], # omit for public clients
redirect_uri: "http://localhost:8080/callback",
scope: %w[tweet.read tweet.write users.read dm.read dm.write offline.access]
)

# 1. Redirect user to the authorization URL
auth_url = client.get_authorization_url(state: "csrf-state")

# 2. Exchange the authorization code returned to your callback
token = client.exchange_code(params[:code])

# 3. Refresh when expired (the client also refreshes automatically before requests)
token = client.refresh_token if client.token_expired?
```

## OAuth 1.0a (HMAC-SHA1)

```ruby
oauth1 = Xdk::OAuth1.new(
api_key: ENV.fetch("X_API_KEY"),
api_secret: ENV.fetch("X_API_SECRET"),
access_token: ENV.fetch("X_ACCESS_TOKEN"),
access_token_secret: ENV.fetch("X_ACCESS_TOKEN_SECRET")
)

client = Xdk::Client.new(auth: oauth1)
```

For 3-legged OAuth 1.0a login:

```ruby
oauth1 = Xdk::OAuth1.new(
api_key: ENV.fetch("X_API_KEY"),
api_secret: ENV.fetch("X_API_SECRET"),
callback: "http://localhost:8080/callback"
)

oauth1.get_request_token
redirect_url = oauth1.get_authorization_url
# After callback with oauth_verifier:
oauth1.get_access_token(verifier)
```
44 changes: 44 additions & 0 deletions xdks/ruby/install.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
title: Install Ruby XDK
sidebarTitle: Install
description: Install the official Ruby XDK (xdk) gem from RubyGems.
keywords: ["xdk", "gem install xdk", "Ruby XDK install"]
---

## Requirements

- **Ruby 3.0+**
- No runtime gem dependencies (uses Ruby's built-in `net/http`, `openssl`, and `json` standard library)

## RubyGems

```bash
gem install xdk
```

## Bundler (`Gemfile`)

```ruby
gem "xdk"
```

Then run:

```bash
bundle install
```

## Encrypted X Chat DMs (optional)

If your app uses the encrypted [X Chat API](/xchat/introduction), install the companion `chat_xdk` encryption gem as well:

```bash
gem install xdk chat_xdk
```

## Verify installation

```ruby
require "xdk"
puts Xdk::VERSION
```
31 changes: 31 additions & 0 deletions xdks/ruby/overview.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Ruby XDK
sidebarTitle: Overview
description: Official Ruby SDK for the X API v2 — zero runtime dependencies, Ruby 3.0+, Bearer/OAuth 2.0 PKCE/OAuth 1.0a auth, pagination, and streaming.
keywords: ["XDK", "Ruby SDK", "X API Ruby", "xdk gem", "Ruby X API v2"]
---

The **Ruby XDK** (`xdk`) is the official Ruby client library for the X API v2, generated from the [X API OpenAPI specification](https://api.x.com/2/openapi.json).

- **Package:** [`xdk`](https://rubygems.org/gems/xdk) on RubyGems (`0.1.0`)
- **Repository:** [xdevplatform/xdk-ruby](https://github.com/xdevplatform/xdk-ruby)
- **Runtime:** Ruby 3.0+ with **zero runtime gem dependencies** (pure stdlib `net/http`, `openssl`, `json`)

<CardGroup cols={2}>
<Card title="Install" icon="download" href="/xdks/ruby/install">
Add `xdk` via RubyGems or Bundler
</Card>
<Card title="Quickstart" icon="rocket" href="/xdks/ruby/quickstart">
Make your first X API v2 call in Ruby
</Card>
<Card title="Authentication" icon="key" href="/xdks/ruby/authentication">
Bearer Token, OAuth 2.0 PKCE, and OAuth 1.0a
</Card>
<Card title="Pagination & Streaming" icon="arrows-rotate" href="/xdks/ruby/pagination">
Lazy Enumerators and resilient real-time streams
</Card>
</CardGroup>

## Encrypted X Chat DMs

Pair `xdk` with the official Ruby **[Chat XDK](/xchat/xchat-xdk)** (`gem install chat_xdk`) to handle X Chat end-to-end encryption, decryption, and signing alongside `/2/chat/*` REST calls.
38 changes: 38 additions & 0 deletions xdks/ruby/pagination.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: Pagination in Ruby XDK
sidebarTitle: Pagination
description: Paginate through X API v2 results lazily using Ruby Enumerators.
keywords: ["Ruby XDK pagination", "X API next_token Ruby", "Enumerator"]
---

Endpoints that accept `pagination_token` or `next_token` return a lazy Ruby `Enumerator` that fetches each page on demand until `meta.next_token` is absent.

## Iterating with an `Enumerator`

```ruby
require "xdk"

client = Xdk::Client.new(bearer_token: ENV.fetch("X_BEARER_TOKEN"))

# Fetch at most 3 pages lazily
client.posts.search_recent(query: "ruby lang:en", max_results: 25).take(3).each do |page|
(page["data"] || []).each do |post|
puts "#{post['id']}: #{post['text']}"
end
end
```

## Fetching just the first page

```ruby
first_page = client.posts.search_recent(query: "ruby lang:en", max_results: 10).first
```

## Passing a block directly

```ruby
client.posts.search_recent(query: "ruby lang:en", max_results: 25) do |page|
puts "Got #{(page['data'] || []).length} posts"
break if page.dig("meta", "result_count").to_i < 25
end
```
51 changes: 51 additions & 0 deletions xdks/ruby/quickstart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: Ruby XDK Quickstart
sidebarTitle: Quickstart
description: Make your first X API v2 requests in Ruby with the official xdk gem.
keywords: ["Ruby XDK quickstart", "X API Ruby example", "xdk gem"]
---

## Look up a user (Bearer Token)

```ruby
require "xdk"

client = Xdk::Client.new(bearer_token: ENV.fetch("X_BEARER_TOKEN"))

response = client.users.get_by_username(
username: "XDevelopers",
user_fields: %w[created_at description public_metrics]
)

puts response["data"]
```

## Create a Post (OAuth 2.0 User Context)

```ruby
require "xdk"

client = Xdk::Client.new(access_token: ENV.fetch("X_ACCESS_TOKEN"))

created = client.posts.create(body: { text: "Hello from the Ruby XDK!" })
puts "Created Post ID: #{created.dig('data', 'id')}"
```

## Error handling & automatic retries

Configure transient retries for `429` / `5xx` responses (honoring `Retry-After`) and rescue `Xdk::ApiError`:

```ruby
client = Xdk::Client.new(
bearer_token: ENV.fetch("X_BEARER_TOKEN"),
timeout: 15,
max_retries: 3,
retry_backoff: 0.5
)

begin
user = client.users.get_by_username(username: "XDevelopers")
rescue Xdk::ApiError => e
warn "HTTP #{e.status} (request_id=#{e.request_id}, retry_after=#{e.retry_after}): #{e.message}"
end
```
Loading
Loading