Server SDK · Ruby & Rails
Ruby SDK
Ruby 3.1+. Uses JSON, Net::HTTP and OpenSSL without external runtime gems.
Install from GitHub
The SDK source is public on the main branch. These instructions use Git or a locally built package; package registry releases are a separate step.
# In your Gemfile:
gem 'pubb', git: 'https://github.com/pubbio/sdk-ruby.git', branch: 'main'
# Then run bundle install.
Commit Gemfile.lock in your application to pin the resolved revision.
Publish an event
Set PUBB_APP_ID, PUBB_APP_KEY and PUBB_APP_SECRET in your server environment, then publish after checking the caller's permissions.
require 'pubb'
pubb = Pubb::Server.new(
app_id: ENV.fetch('PUBB_APP_ID'), app_key: ENV.fetch('PUBB_APP_KEY'),
app_secret: ENV.fetch('PUBB_APP_SECRET')
)
result = pubb.trigger(channel: 'notifications', name: 'message.sent',
data: {message: 'Hello from Pubb!'})
puts result.publication_id
trigger accepts optional socket_id and idempotency_key keywords. Calls are synchronous with separate connections. APIError exposes status and retry_after; ProtocolError indicates an invalid receipt. Network errors propagate from Net::HTTP.
HTTP 202 confirms acceptance for processing, not delivery. The response includes publicationId and duplicate. SDKs do not automatically retry publications; reuse an idempotency key when retrying the same event. The API accepts 1–100 channels and up to 10 KiB of UTF-8 JSON data.
Private and presence channels
Use authorize_channel(socket_id:, channel:) or authorize_presence_channel(socket_id:, channel:, user_id:, user_info:) after authenticating the user and verifying their channel access. Return the resulting hash as JSON.
Your backend receives socket_id and channel_name, checks the authenticated user’s access, and returns auth plus channel_data for presence. Derive the presence user ID from the session and forward the signed channel_data unchanged.
Keep the app secret on your trusted server. Public channels must not carry personal or restricted data. Read the channel access reference for the protocol.
Verify your integration
- Subscribe to
notificationsin your app or the dashboard’s Live console. - Publish
message.sentto the same application and channel from your backend. - Check the event payload, connection cleanup and recovery after a disconnect. Test denied access as well as successful private subscriptions.
The repositories include automated tests and examples. Verify end-to-end delivery with your own application before sending production traffic. Refetch durable state after reconnecting; missed events are not replayed.
Legacy pusher:* and pusher_internal:* control names are retained where required by the protocol. Their presence alone does not imply drop-in compatibility with every Pusher client or server.