OddSockets Ruby SDK

Official Ruby SDK for OddSockets real-time messaging platform

RubyGems Ruby 3.0+ Thread Safe High Performance Promise-like

Overview & Features

The OddSockets Ruby SDK provides a powerful, thread-safe interface for real-time messaging with Ruby idioms and modern async support.

Ruby Idioms

Built with Ruby best practices including predicate methods, block syntax, and symbol keys.

Thread Safe

Uses concurrent-ruby for thread-safe collections and operations in multi-threaded environments.

Promise-like API

Async operations return Concurrent::Promises for clean asynchronous programming.

High Performance

Optimized for low latency with efficient WebSocket connections and smart routing.

Cost Effective

No per-message pricing, industry-standard 32KB message limits, transparent pricing.

Rails Ready

Perfect integration with Rails applications and Ruby web frameworks.

Installation

bash
bundle add oddsockets
bash
gem install oddsockets
ruby
# Gemfile
gem 'oddsockets'

Quick Start

Basic Usage

ruby
require 'oddsockets'

client = OddSockets::Client.new(
  api_key: 'ak_live_1234567890abcdef'
)

channel = client.channel('my-channel')

# Subscribe to messages
channel.subscribe do |message|
  puts "Received: #{message}"
end

# Publish a message
channel.publish('Hello, Ruby!')

Promise-like Async Operations

ruby
require 'oddsockets'

client = OddSockets::Client.new(api_key: 'ak_live_1234567890abcdef')
channel = client.channel('async-channel')

# Async operations with promises
channel.subscribe { |msg| puts msg }.wait
result = channel.publish('Hello, Async!').wait
history = channel.history(count: 10).wait

puts "Published: #{result['messageId']}"
puts "History: #{history.length} messages"

Rails Integration

ruby
# config/initializers/oddsockets.rb
OddSockets.configure do |config|
  config.manager_url = Rails.application.credentials.oddsockets_url
  config.log_level = Rails.env.production? ? :info : :debug
end

# app/controllers/messages_controller.rb
class MessagesController < ApplicationController
  def create
    client = OddSockets::Client.new(api_key: current_user.api_key)
    channel = client.channel("user_#{current_user.id}")
    
    channel.publish(message_params[:content])
    
    render json: { status