Sha256: 40e4544cefc3ee1383072831b415495e47fe7300dc2107be9d3158ef6f7a08a1

Contents?: true

Size: 950 Bytes

Versions: 23

Compression:

Stored size: 950 Bytes

Contents

require 'sinatra'
require 'json'
require 'slim'
require 'coffee-script'
require 'sass'
require 'pubnub'

set :root, File.dirname(__FILE__)
set :public_folder, 'public'

pubnub = Pubnub.new(
    :publish_key   => 'demo',
    :subscribe_key => 'demo'
)

get '/' do
  slim :index
end

post '/get_messages' do
  content_type :json

  msgs = pubnub.subscribe(
             :channel => 'pubnub_chat',
             :http_sync => true
         )

  msgs.map { |envelope| {
          :message => envelope.msg['message'],
          :author => envelope.msg['author']
      }
  }.to_json
end

post '/publish' do
  content_type :json
  pubnub.publish(
      :http_sync => true,
      :channel => 'pubnub_chat',
      :message => {
          :message => params[:message],
          :author  => params[:author]
      }
  ).to_json
end

get '/application.css' do
  sass :application
end

get '/streamer.js' do
  content_type 'text/javascript'
  coffee :streamer
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
pubnub-3.7.12 examples/sinatra/main.rb
pubnub-3.7.11 examples/sinatra/main.rb
pubnub-3.7.10 examples/sinatra/main.rb
pubnub-3.7.9 examples/sinatra/main.rb
pubnub-3.7.7 examples/sinatra/main.rb
pubnub-3.7.5 examples/sinatra/main.rb
pubnub-3.7.1 examples/sinatra/main.rb
pubnub-3.7.0 examples/sinatra/main.rb
pubnub-3.6.10 examples/sinatra/main.rb
pubnub-3.6.9 examples/sinatra/main.rb
pubnub-3.6.7 examples/sinatra/main.rb
pubnub-3.5.14 examples/sinatra/main.rb
pubnub-3.5.12 examples/sinatra/main.rb
pubnub-3.5.8 examples/sinatra/main.rb
pubnub-3.5.7 examples/sinatra/main.rb
pubnub-3.5.6 examples/sinatra/main.rb
pubnub-3.5.5 examples/sinatra/main.rb
pubnub-3.5.3 examples/sinatra/main.rb
pubnub-ruby-3.4.1 examples/sinatra/main.rb
pubnub-3.5.1 examples/sinatra/main.rb