Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 75394f1047
Fetching contributors…

Cannot retrieve contributors at this time

104 lines (80 sloc) 2.029 kb

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)
Jump to Line
Something went wrong with that request. Please try again.