PubNub - http://github/pubnub/ruby @pubnub on Twitter, @stephenlb on Github
www.pubnub.com - PubNub Real-time Push Service in the Cloud. http://www.pubnub.com/blog/ruby-push-api
PubNub is a Real-time Network for Mobile App, Web Apps for pushing updates and enabling real-time notifications and even games! This is a cloud-based service for broadcasting Real-time messages to thousands of web and mobile clients simultaneously.
and is NOT compatible with earlierversions of Pubnub Ruby Client.
Examine the tests in spec/lib/*
for many different examples!
Specifically, *_integration
. But here is a small sample:
require 'pubnub'
pubnub = Pubnub.new(
:publish_key => 'demo', # publish_key only required if publishing.
:subscribe_key => 'demo', # required
:secret_key => nil, # optional, if used, message signing is enabled
:cipher_key => nil, # optional, if used, encryption is enabled
:ssl => nil, # true or default is false
:logger => nil # optional, if used, you can pass your own logger, eg. Rails.logger
)
For message, you can just pass:
- a "String"
- a Number 123
- an array [ 1, 2, 3 ]
- an object { :a => "apple" }
it will be serialized as a JSON for the transport to your mobile and web apps.
@my_callback = lambda { |message| puts(message) }
pubnub.publish(
:channel => :hello_world,
:message => "hi",
:callback => @my_callback
)
pubnub.subscribe(
:channel => :hello_world,
:callback => @my_callback
)
pubnub.history(
:cipher_key => "enigma", ## OPTIONAL
:channel => @no_history_channel,
:limit => 10,
:callback => @my_callback
)
Archive messages of on a given channel. Optional start, end, and reverse option examples can be found in the tests.
pubnub.detailed_history(
:channel => channel,
:count => 10,
:callback => @my_callback
)
Realtime see who channel events, such as joins, leaves, and occupancy.
pubnub.presence(
:channel => :hello_world,
:callback => @my_callback
)
See who is online in a channel at this very moment.
pubnub.here_now(
:channel => channel,
:callback => @my_callback
)
Session-UUID is automatic, so you will probably not end up ever using this. But if you need a UUID...
pubnub.uuid
Get the current timetoken.
pubnub.time("callback" => @my_callback)