Project

pubnub

0.31
There's a lot of open issues
A long-lived project that still receives updates
Ruby anywhere in the world in 250ms with PubNub!
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
 Dependencies

Runtime

>= 2.0.0
~> 2.8, >= 2.8.3
>= 2.2.0, < 3
>= 4.3.0
 Project Readme

PubNub Ruby SDK

Codacy Badge Codacy Badge Build Status

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.

Configure PubNub

  1. Integrate PubNub into your project using RubyGems:

    gem install pubnub
  2. Create a new App.rb file and add the following code.

    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

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

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

Support

If you need help or have a general question, contact support@pubnub.com.