https://github.com/pubnub/ruby
PubNub Ruby-based APIs
https://github.com/pubnub/ruby
Last synced: 3 months ago
JSON representation
PubNub Ruby-based APIs
- Host: GitHub
- URL: https://github.com/pubnub/ruby
- Owner: pubnub
- License: other
- Created: 2013-02-25T21:07:42.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2025-10-03T18:41:55.000Z (3 months ago)
- Last Synced: 2025-10-11T05:11:46.410Z (3 months ago)
- Language: Ruby
- Homepage:
- Size: 24 MB
- Stars: 123
- Watchers: 30
- Forks: 90
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome-ruby - PubNub - Real-time Push Service in the Cloud. (Mobile Development)
- fucking-awesome-ruby - PubNub - Real-time Push Service in the Cloud. (Mobile Development)
README
# PubNub Ruby SDK

This is the official PubNub Ruby SDK repository.
PubNub takes care of the infrastructure and APIs needed for the realtime communication layer of your application. Work on your app's logic and let PubNub handle sending and receiving data across the world in less than 100ms.
## Get keys
You will need the publish and subscribe keys to authenticate your app. Get your keys from the [Admin Portal](https://dashboard.pubnub.com/).
## Configure PubNub
1. Integrate PubNub into your project using RubyGems:
```bash
gem install pubnub
```
1. Create a new `App.rb` file and add the following code.
```ruby
require 'pubnub'
pubnub = Pubnub.new(
subscribe_key: :mySubscribeKey,
publish_key: :myPublishKey,
uuid: :myUniqueUUID
)
```
This is the minimum configuration you need to send and receive messages with PubNub.
## Add event listeners
```ruby
callback = Pubnub::SubscribeCallback.new(
message: ->(envelope) {
puts "MESSAGE: #{puts envelope.result[:data][:message]['msg']}"
},
presence: ->(envelope) {
puts "PRESENCE: #{envelope.result[:data]}"
}
)
pubnub.add_listener(callback: callback)
```
## Publish and subscribe
```ruby
pubnub.subscribe(
channels: ['my_channel'],
with_presence: true
)
pubnub.publish(
channel: 'my_channel',
message: { text: 'Hello world' }
) do |envelope|
puts envelope.status
end
```
## Documentation
[API reference for Ruby](https://www.pubnub.com/docs/ruby/pubnub-ruby-sdk)
## Support
If you **need help** or have a **general question**, contact .