PubNub

This add-on is operated by PubNub

Data Push for Any Device (Mobile, Tablet, Browser, Desktop, Server)

PubNub

Last Updated: 28 April 2014

api

Table of Contents

Using Publish Subscribe could not be simpler.

PubNub Ruby SDK on Heroku

PubNub provides a web-service API for businesses to build scalable Data Push communication apps on Mobile, Tablet and Web. Use PubNub to send/receive messages in real-time across multiple platforms and devices with two simple API calls (Publish/Subscribe - Send/Receive).

PubNub Ruby SDK Documentation

Get PubNub gem

Ruby Gems link to registered Ruby Gem.

> gem install pubnub

Use PubNub RUBY SDK on Heroku

    require 'pubnub'

    publish_key   = ENV['PUBNUB_PUBLISH_KEY'] || 'demo'
    subscribe_key = ENV['PUBNUB_SUBSCRIBE_KEY'] || 'demo'

    ## -----------------------------------------
    ## Create Pubnub Client API (INITIALIZATION)
    ## -----------------------------------------
    puts('Creating new PubNub Client API')

    pubnub = Pubnub.new(
         :subscribe_key    => 'demo',
         :publish_key      => 'demo',
         :error_callback   => lambda { |msg|
            puts "ERROR: #{msg.inspect}"
         },
         :connect_callback => lambda { |msg|
            puts "CONNECTED: #{msg.inspect}"
         }
    )

    ## ----------------------
    ## Send Message (PUBLISH)
    ## ----------------------
    puts('Broadcasting Message')
    message = { 'some_data' => 'my data here' }

    info = pubnub.publish(
        :channel => "hello_world",
        :message => message
    ) { |envelope|
       puts("\nchannel: #{envelope.channel}
            \nmsg: #{envelope.message}")
    }

    ## Publish Success?
    puts(info)

    ## --------------------------------
    ## Request Past Publishes (HISTORY)
    ## --------------------------------
    puts('Requesting History')
    messages = pubnub.history(
        :channel => 'hello_world',
        :count   => 100
    ){ |envelope|
       puts("\nchannel: #{envelope.channel}:
       \nmsg: #{envelope.message}")
    }

    puts(messages)

PubNub PHP SDK on Heroku

Developers can use Publish/Subscribe from a terminal or web server like Apache/NginX/lighttpd. PubNub PHP Push API provides real time Publish and Subscribe for PHP Developers. - See more at: http://www.pubnub.com/blog/php-push-api-walkthrough/#sthash.iXsCmJNC.dpuf

PHP Examples

# Initialize
$pubnub = new Pubnub(
    "demo",  ## PUBLISH_KEY
    "demo",  ## SUBSCRIBE_KEY
    "",      ## SECRET_KEY
    false    ## SSL_ON?
);

# Publish
$info = $pubnub->publish(array(
    'channel' => 'hello_world', ## REQUIRED Channel to Send
    'message' => 'Hey World!'   ## REQUIRED Message String/Array
));
print_r($info);

# Subscribe
$pubnub->subscribe(array(
    'channel'  => 'hello_world',        ## REQUIRED Channel to Listen
    'callback' => function($message) {  ## REQUIRED Callback With Response
        var_dump($message);  ## Print Message
        return true;         ## Keep listening (return false to stop)
    }
));

# Realtime Join/Leave Presence Events
$pubnub->presence(array(
    'channel'  => $channel,
    'callback' => function($message) {
        print_r($message);
        echo "\r\n";
        return true;
    }
));

# Channel Occupancy
$here_now = $pubnub->here_now(array(
    'channel' => $channel
));

# Message History
$history = $pubnub->detailedHistory(array(
    'channel' => $channel,
    'count'   => 10,
    'end'   => "13466530169226760"
));

Other PubNub SDKs