Skip to content
Browse files

fixing paths

  • Loading branch information...
1 parent 73a9beb commit e2a7b7b2b47a6cc48285c2caf26439ef9c523a76 @slim2000 committed Oct 21, 2012
Showing with 73 additions and 0 deletions.
  1. +5 −0 config.rb
  2. +68 −0 notify.rb
View
5 config.rb
@@ -0,0 +1,5 @@
+require 'pusher'
+
+Pusher.app_id = '30086'
+Pusher.key = 'c098fd0ea035d82a56b5'
+Pusher.secret = 'ae8639f60016286c5179'
View
68 notify.rb
@@ -0,0 +1,68 @@
+require 'config.rb'
+
+require 'sinatra'
+require 'pusher'
+require 'json'
+
+include Rack::Utils
+
+set :public_folder, 'examples/'
+
+get '/' do
+ send_file('examples/index.html')
+end
+
+get '/notify' do
+
+ message = params[:message]
+
+ if( !message )
+ status 400
+ body 'message must be provided'
+ end
+
+ message = sanitise_input(message)
+ data = {'message' => message}
+ response = Pusher['my_notifications'].trigger('notification', data)
+
+ result = {'activity' => data, 'pusherResponse' => response}
+
+ status 200
+ headers \
+ 'Cache-Control' => 'no-cache, must-revalidate',
+ 'Content-Type' => 'application/json'
+
+ body result.to_json
+end
+
+get '/src/*' do
+ path = params[:splat].join()
+ path = path.gsub(/(\.\.)|~/, '') # remove ../ and ~
+ path = 'src/' + path
+ type = path[path.rindex('.')+1, path.length]
+ puts('getting: ' + path + ' type: ' + type)
+ if(File.exists?(path))
+ status 200
+ headers \
+ 'Cache-Control' => 'no-cache, must-revalidate',
+ 'Content-Type' => get_content_type(type)
+ File.read(path)
+ else
+ status 404
+ end
+end
+
+def get_content_type(type)
+ case type
+ when "css"
+ return 'text/css'
+ when "js"
+ return 'text/javascript'
+ else
+ return 'text/plain'
+ end
+end
+
+def sanitise_input(message)
+ return escape_html(message).slice(0, 300)
+end

0 comments on commit e2a7b7b

Please sign in to comment.
Something went wrong with that request. Please try again.