Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

pubnub

  • Loading branch information...
commit cbda7cbf32a679b335583720348ebe33b0405972 1 parent 180d7c2
@jeremyjbarth authored
View
6 Gemfile
@@ -18,11 +18,7 @@ end
gem 'jquery-rails'
-# Use unicorn as the web server
-# gem 'unicorn'
-
-# Deploy with Capistrano
-# gem 'capistrano'
+gem 'pubnub-ruby'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
View
3  Gemfile.lock
@@ -58,6 +58,8 @@ GEM
mysql2 (0.3.11)
pg (0.13.2)
polyglot (0.3.3)
+ pubnub-ruby (0.0.5)
+ json
rack (1.3.6)
rack-cache (1.0.3)
rack (>= 0.4)
@@ -113,6 +115,7 @@ DEPENDENCIES
jquery-rails
mysql2
pg
+ pubnub-ruby
rails (= 3.1.0)
sass-rails (~> 3.1.0)
uglifier
View
24 app/controllers/answers_controller.rb
@@ -1,3 +1,5 @@
+require 'Pubnub'
+
class AnswersController < ApplicationController
# GET /answers
# GET /answers.json
@@ -42,6 +44,28 @@ def edit
def create
@answer = Answer.new(params[:answer])
+ publish_key = 'pub-9f81b327-36ba-4042-b239-bb966cecdd53'
+ subscribe_key = 'sub-699882c0-601d-11e1-a0df-35794172b2ae'
+ secret_key = 'sec-fae1f709-491f-45fa-b062-9295f7664cae'
+ ssl_on = false
+
+ puts('Creating new PubNub Client API')
+ pubnub = Pubnub.new(
+ publish_key,
+ subscribe_key,
+ secret_key,
+ ssl_on
+ )
+
+ puts('Broadcasting Message')
+ message = { 'some_data' => 'my data here' }
+ info = pubnub.publish({
+ 'channel' => 'hello_world',
+ 'message' => @answer.answer
+ })
+
+ puts info
+
respond_to do |format|
if @answer.save
format.html { redirect_to action: "new" }
View
BIN  app/views/answers/.index.html.erb.swp
Binary file not shown
View
14 app/views/answers/index.html.erb
@@ -1,5 +1,17 @@
+<script src='http://cdn.pubnub.com/pubnub-3.1.min.js'></script>
+<script>
+
+ // LISTEN
+ PUBNUB.subscribe({
+ channel : "hello_world",
+ callback : function(message) {
+ $('#answers').append('<li><a>' + message + '</a></li>');
+ }
+ })
+
+</script>
<div class="container">
-<ul class="nav nav-tabs nav-stacked">
+<ul id="answers" class="nav nav-tabs nav-stacked">
<% @answers.each do |answer| %>
<li><a><%= answer.answer %></a></li>
<% end %>
View
BIN  app/views/layouts/.application.html.erb.swp
Binary file not shown
View
4 app/views/layouts/application.html.erb
@@ -6,6 +6,7 @@
<link href="/css/bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="/css/custom.css" rel="stylesheet" type="text/css"/>
<link href="/css/docs.css" rel="stylesheet" type="text/css"/>
+ <link href="/js/google-code-prettify/prettify.css" rel="stylesheet" type="text/css"/>
<script src="/js/application.js" type="text/javascript"></script>
<script src="/js/bootstrap-alert.js" type="text/javascript"></script>
<script src="/js/bootstrap-button.js" type="text/javascript"></script>
@@ -19,12 +20,13 @@
<script src="/js/bootstrap-tooltip.js" type="text/javascript"></script>
<script src="/js/bootstrap-transition.js" type="text/javascript"></script>
<script src="/js/bootstrap-typeahead.js" type="text/javascript"></script>
- <script src="/js/google-code-prettify.js" type="text/javascript"></script>
+ <script src="/js/google-code-prettify/prettify.js" type="text/javascript"></script>
<script src="/js/jquery.js" type="text/javascript"></script>
<%= csrf_meta_tags %>
</head>
<body>
+<div pub-key="pub-9f81b327-36ba-4042-b239-bb966cecdd53" sub-key="sub-699882c0-601d-11e1-a0df-35794172b2ae" ssl="off" origin="pubsub.pubnub.com" id="pubnub"></div>
<%= yield %>
</body>
Please sign in to comment.
Something went wrong with that request. Please try again.