Switch branches/tags
Nothing to show
Find file History
Latest commit a8fe8cc Jul 16, 2013 @geremyCohen geremyCohen Create LICENSE
Permalink
..
Failed to load latest commit information.
LICENSE Create LICENSE Jul 16, 2013
README
pubnub.rb added RhoMobile PubNub Ruby Library by David Greene Jul 28, 2011

README

PubNub - http://github/pubnub/pubnub-api

David Greene
https://github.com/trumpetx
http://davidgreene.me/
Austin, TX

## ------------------------------------------
## PubNub 3.0 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
## -------------
pubnub = Pubnub.new(
    "demo",  ## PUBLISH_KEY
    "demo",  ## SUBSCRIBE_KEY
    "",      ## SECRET_KEY
    false    ## SSL_ON?
)

# -------
# PUBLISH
# -------
# Send Message
info = pubnub.publish({
    'channel' => 'hello_world',
    'message' => { 'text' => 'some text data' }
})
puts(info)


# ---------
# SUBSCRIBE
# ---------
def on_activate_app
    require 'helpers/pubnub'
    puts('Creating new Pubnub Client API')

    # sub, pub, secret, ssl on or off
    pubnub = Pubnub.new( 'demo', 'demo', nil, false )

    t1 = Thread.new do
        pubnub.subscribe({
            'channel'  => 'hello_world',
            'callback' => lambda do |message| 
                WebView.execute_js("alert('#{message}');")
                return true
            end
        })
    end
end

# -------
# HISTORY
# -------
# Load Previously Published Messages
messages = pubnub.history({
    'channel' => 'hello_world',
    'limit'   => 10
})
puts(messages)