Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Pull request Compare This branch is 679 commits behind pubnub:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

..
Failed to load latest commit information.
3.3
README.md

README.md

Pubnub - http://github/pubnub/pubnub-api @poptartinc on Twitter, @poptart on Github

YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API.
http://www.pubnub.com/account

PubNub 3.3 Real-time Cloud Push API - Ruby on Sinatra

www.pubnub.com - PubNub Real-time Push Service in the Cloud. http://www.pubnub.com/blog/ruby-push-api

PubNub is a Massively Scalable Real-time Service for Web and Mobile Games. This is a cloud-based service for broadcasting Real-time messages to thousands of web and mobile clients simultaneously.

Pubnub 3.3 for Ruby is a complete rewrite, and is NOT compatible with earlier versions of Pubnub Ruby Client.

Checkout the included hello.rb for a quick usage example

Usage Examples

Examine the tests in spec/lib/* for many different scenarios! Specifically, *_integration. But here is a small sample:

Instantiate a new PN Object

    pn = Pubnub.new(:publish_key => @publish_key, # publish_key only required if publishing.
        :subscribe_key => @subscribe_key,         # required
        :secret_key => @secret_key,               # optional, if used, message signing is enabled
        :cipher_key => @cipher_key,               # optional, if used, encryption is enabled
        :ssl => @ssl_enabled)                     # true or default is false 

Publish

For message, you can just pass it a string, a hash, an array, an object -- it will be serialized as a JSON object, and urlencoded automatically for you.

    @my_callback = lambda { |message| puts(message) }

    pn.publish(:channel => :hello_world,
        :message => "hi",
        :callback => @my_callback)

Subscribe

    pn.subscribe(:channel => :hello_world,
        :callback => @my_callback)

History (deprecated, use new detailed_history)

    pn.history(:cipher_key => "enigma",
        :channel => @no_history_channel,
        :limit => 10,
        :callback => @my_callback)

Detailed Message History

Archive messages of on a given channel. Optional start, end, and reverse option examples can be found in the tests.

    pn.detailed_history(:channel => channel,
        :count => 10, 
        :callback => @my_callback)

Presence

Realtime see who channel events, such as joins, leaves, and occupancy.

    pn.presence(:channel => :hello_world,
        :callback => @my_callback)

Here_now

See who is online in a channel at this very moment.

    pn.here_now(:channel => channel,
    :callback => @my_callback)

UUID

Session-UUID is automatic, so you will probably not end up ever using this. But if you need a UUID...

    Pubnub.new(:subscribe_key => :demo).uuid

Time

Get the current timetoken.

    pn.time("callback" => @my_callback)
Something went wrong with that request. Please try again.