Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.
/ pubnub-ruby Public archive
forked from pubnub/ruby

PubNub Ruby-based APIs

License

Notifications You must be signed in to change notification settings

htdc/pubnub-ruby

 
 

Repository files navigation

PubNub Ruby SDK

Tests 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 [email protected].

About

PubNub Ruby-based APIs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%