Sha256: f7b9ee1c7c2e3331053fde8fd4c2576928b0925b3e5cf925b03b1d5ef646ebfc

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

## -----------------------------------
## PubNub Ruby API Subscribe Example
## -----------------------------------

## including required libraries
require 'rubygems'
require 'pubnub'

## declaring publish_key, subscribe_key, secret_key, cipher_key, ssl flag
publish_key   = 'demo'
subscribe_key = 'demo'
secret_key    = 'demo'
cipher_key    = 'demo'
ssl_on        = false
channel       = 'hello_world'

## Print usage if missing info.
if !subscribe_key
  puts('
    Get API Keys at http://www.pubnub.com/account
    ==============
    EXAMPLE USAGE:
    ==============
    ruby subscribe-example.rb PUBLISH-KEY SUBSCRIBE-KEY SSL-ON
    ruby subscribe-example.rb demo demo true
    ')
  exit()
end

## Create Pubnub Client API (INITIALIZATION)
puts('Initializing new Pubnub state')
pubnub = Pubnub.new(publish_key,subscribe_key,secret_key,cipher_key,ssl_on)

## Listen for Messages (SUBSCRIBE)
puts('Listening for new messages with subscribe() Function')
puts('Press CTRL+C to quit.')
pubnub.subscribe({
  'channel'  => channel,
  'callback' => lambda do |message|
  puts(message) ## print message
  return true   ## keep listening?
  end
})

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pubnub-0.1.10 examples/subscribe_example.rb
pubnub-0.1.9 examples/subscribe_example.rb
pubnub-0.1.8 examples/subscribe_example.rb
pubnub-0.1.7 examples/subscribe_example.rb