Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: 072512_ruby_v2

This branch is 1005 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

..
Failed to load latest commit information.
examples
lib
spec
tests
.gitignore
.project
README.md
Rakefile
VERSION
pubnub-0.1.12.gem
pubnub.gemspec

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.1 Real-time Cloud Push API - RUBY

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.

Ruby Push API

Ruby: (Init)

pubnub = Pubnub.new(
    "demo",  ## PUBLISH_KEY
    "demo",  ## SUBSCRIBE_KEY
    "demo",  ## SECRET_KEY
    "",      ## CIPHER_KEY (Cipher key is Optional)
    false    ## SSL_ON?
)

Ruby: (Publish)

Send Message in String Format
pubnub.publish({
    'channel' => 'hello_world',
    'message' => 'hey what is up?',
    'callback' => lambda do |message|
       puts(message)
     end
})
Send Message in Array Format
pubnub.publish({
    'channel' => 'hello_world',
    'message' => { ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"] },
    'callback' => lambda do |message|
       puts(message)
     end
})
Send Message in Dictionary Format
pubnub.publish({
    'channel' => 'hello_world',
    'message' => { 'text' => 'some text data' },
    'callback' => lambda do |message|
       puts(message)
     end
})

Ruby: (Subscribe)

Listen for Messages
pubnub.subscribe({
    'channel'  => 'hello_world',
    'callback' => lambda do |message|
        puts(message)    ## get and print message
        return true      ## keep listening?
    end
})

Ruby: (History)

Load Previously Published Messages
pubnub.history({
    'channel' => 'hello_world',
    'limit'   => 10,
    'callback' => lambda do |message|
       puts(message)
     end
})

Ruby: (UUID)

Generate UUID
uuid = pubnub.UUID()
puts(uuid)
Something went wrong with that request. Please try again.