Permalink
Browse files

added ruby example with content commander to push HTML content on dem…

…and.
  • Loading branch information...
1 parent f379a1d commit dfd395116c9210d96f4bea799689ac4f455d1077 @stephenlb stephenlb committed May 9, 2012
Showing with 88 additions and 4 deletions.
  1. +29 −0 ruby/commander/commander.rb
  2. +55 −0 ruby/commander/viewer.html
  3. +4 −4 ruby/lib/pubnub.rb
@@ -0,0 +1,29 @@
+require '../lib/pubnub'
+
+## -----------------------------------------
+## SETUP API KEYS
+## -----------------------------------------
+publish_key = "09e02e4d-5508-44fb-a615-8da69289b73c"
+subscribe_key = "a71204b3-ca89-11df-ba32-cfcef4a2b967"
+secret_key = ""
+
+## -----------------------------------------
+## Create Pubnub Client API (INITIALIZATION)
+## -----------------------------------------
+pubnub = Pubnub.new( publish_key, subscribe_key, secret_key, false )
+
+## ----------------------
+## Send Message (PUBLISH)
+## ----------------------
+while 1
+ puts('Sending a message with publish() To Content Viewer')
+ info = pubnub.publish({
+ 'channel' => 'content_commander',
+ 'message' => {
+ 'name' => 'arb_html',
+ 'data' => "Current Time: <h1>" + Time.now.inspect + "</h1>"
+ }
+ })
+ sleep(1.0)
+end
+
View
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8" />
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
+ <title>Content Commander </title>
+ <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
+ </head>
+ <body>
+ <div data-role="page" id="main">
+ <div data-theme="a" data-role="header">
+ <h3>
+ Content Commander - Viewer
+ </h3>
+ </div><!-- /header -->
+ <div data-role="content" id="viewer_box" class="box left">
+ <div id="content"></div>
+ </div><!-- /content #viewer_box" -->
+ </div>
+
+ <!-- JQUERY -->
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
+ <script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
+
+ <!-- PUBNUB -->
+ <div sub-key="a71204b3-ca89-11df-ba32-cfcef4a2b967" ssl="off" origin="pubsub.pubnub.com" id="pubnub"></div>
+ <script src="http://cdn.pubnub.com/pubnub-3.1.min.js"></script>
+ <script>(function(){
+ $(document).data('uuid', (((1+Math.random())*0x10000)|0).toString(16).substring(1));
+
+ PUBNUB.events.bind('arb_html', function(html) {
+ $("#content").remove();
+ $("#viewer_box").append("<div id='content'>"+ html + "</div>");
+ });
+
+ PUBNUB.subscribe({
+ channel : "content_commander",
+ restore : false,
+ callback : function(message) {
+ if (message.name) {
+ PUBNUB.events.fire(message.name, message.data);
+ }
+ },
+ disconnect : function() {
+ console.log("Connection Lost.");
+ },
+ reconnect : function() {
+ console.log("And we're Back!");
+ }
+
+ });
+
+ })();</script>
+ </body>
+</html>
View
@@ -12,7 +12,7 @@
require 'digest/md5'
require 'open-uri'
require 'uri'
-require 'net/http'
+require 'net/https'
require 'json'
require 'pp'
@@ -43,10 +43,10 @@ def initialize( publish_key, subscribe_key, secret_key, ssl_on = false)
@origin = 'http://' + @origin
end
- uri = URI.parse(@origin)
- http = Net::HTTP.new(uri.host, uri.port)
+ uri = URI.parse(@origin)
+ http = Net::HTTP.new( uri.host, uri.port )
http.use_ssl = ssl_on
- @connection = http.start()
+ @connection = http.start()
end
#**

0 comments on commit dfd3951

Please sign in to comment.