Permalink
Browse files

Updated data processing. Added flash policy handling. Removed empty c…

…ode files. Improved logging. Updated application template.
  • Loading branch information...
Dan Simpson
Dan Simpson committed Apr 23, 2010
1 parent 50ab5d8 commit 72345b22967e70b10727e32c1643c686bb91afca
View
25 README.markdown 100644 → 100755
@@ -6,22 +6,25 @@
##Creating a project
- funnel myapp
+ funnel example
+ cd example
+ ruby script/server
+
##Project Hierarchy
/config
boot.rb
- routes.rb
- config.rb
+ routes.rb (define your handler routes)
+ settings.yml (host, port, accepted sources, etc)
/handlers -> your real time resource handlers
- time.rb
- game.rb
- xmpp.rb
- amqp.rb
+ game_handler.rb
+ chat_handler.rb
/script
server
-
+ /htdocs
+ test.html -> a simple page to test that your server is running
+
## your first "handler"
@@ -52,5 +55,7 @@ set up the route in config/routes.rb
##Dependencies
- eventmachine http://github.com/eventmachine/eventmachine
-
-# tired... more info coming soon
+##Coming soon
+- Plugins for various real time things (amqp, xmpp, twitter, etc)
+- Client side libraries to enable cross browser development
+- Client side plugins
View
@@ -12,7 +12,7 @@ OptionParser.new do |opts|
opts.banner = "Usage: funnel [options] application_name"
options[:verbose] = false
-
+
opts.on( '-v', '--verbose', 'Output more information' ) do
options[:verbose] = true
end
@@ -21,24 +21,12 @@ OptionParser.new do |opts|
puts opts
exit
end
-
- opts.on( '-w amqp', '--with-amqp', 'Include amqp proxy handler' ) do
- options[:amqp] = true
- end
-
- opts.on( '-w xmpp', '--with-xmpp', 'Include xmpp proxy handler' ) do
- options[:xmpp] = true
- end
-
- opts.on( '-w twitter', '--with-twitter', 'Include twitter stream proxy handler' ) do
- options[:twitter] = true
- end
-
+
if ARGV.length < 1
puts opts
exit
end
-
+
end.parse!
app = Funnel::Generators::Application.new
View
@@ -1,6 +1,6 @@
spec = Gem::Specification.new do |s|
s.name = 'funnel'
- s.version = '0.1.5'
+ s.version = '0.1.8'
s.date = '2009-12-30'
s.summary = 'A realtime resource-centric application framework'
s.email = 'dan.simpson@gmail.com'
@@ -14,31 +14,26 @@ spec = Gem::Specification.new do |s|
s.authors = ['Dan Simpson']
s.add_dependency('eventmachine', '>= 0.12.4')
-
s.files = [
- 'README.markdown',
- 'funnel.gemspec',
- 'lib/funnel.rb',
- 'lib/funnel/logger.rb',
+ 'README.markdown',
+ 'funnel.gemspec',
+ 'lib/funnel.rb',
+ 'lib/funnel/log.rb',
+ 'lib/funnel/configuration.rb',
+ 'lib/funnel/flash/policy.rb',
'lib/funnel/web_socket/frame.rb',
'lib/funnel/web_socket/headers.rb',
'lib/funnel/web_socket/connection.rb',
'lib/funnel/routing/route.rb',
'lib/funnel/routing/routes.rb',
'lib/funnel/routing/router.rb',
'lib/funnel/server.rb',
- 'lib/funnel/servers/dummy_server.rb',
'lib/funnel/generators/application.rb',
'templates/application/config/boot.rb',
- 'templates/application/config/config.rb',
+ 'templates/application/config/settings.yml',
'templates/application/config/routes.rb',
- 'templates/application/script/run',
- 'templates/application/handlers/echo_handler.rb',
- 'templates/amqp/config/amqp.rb',
- 'templates/amqp/handlers/amqp.rb',
- 'templates/xmpp/config/xmpp.rb',
- 'templates/xmpp/handlers/xmpp.rb',
- 'templates/twitter/config/twitter.rb',
- 'templates/twitter/handlers/twitter.rb'
+ 'templates/application/script/server',
+ 'templates/application/htdocs/test.html',
+ 'templates/application/handlers/debug_handler.rb',
]
end
View
8 lib/funnel.rb 100644 → 100755
@@ -1,19 +1,19 @@
require 'rubygems'
require 'eventmachine'
-require 'pp'
module Funnel
module WebSocket
end
end
-require 'funnel/logger.rb'
+require 'funnel/configuration.rb'
+require 'funnel/log.rb'
+require 'funnel/flash/policy.rb'
require 'funnel/generators/application.rb'
require 'funnel/web_socket/frame.rb'
require 'funnel/web_socket/headers.rb'
require 'funnel/web_socket/connection.rb'
require 'funnel/routing/route.rb'
require 'funnel/routing/routes.rb'
require 'funnel/routing/router.rb'
-require 'funnel/server.rb'
-require 'funnel/servers/dummy_server.rb'
+require 'funnel/server.rb'
@@ -0,0 +1,32 @@
+module Funnel
+
+ class Configuration
+
+ @@map = {
+ :host => "0.0.0.0",
+ :port => 4000,
+ :accepted_origins => []
+ }
+
+ def self.get key
+ @@map[key.to_sym]
+ end
+
+ def self.put key, val
+ @@map[key.to_sym] = val
+ end
+
+ def self.load file
+ begin
+ settings = YAML.load_file(File.join(FUNNEL_ROOT, file))
+ settings.each do |key, val|
+ put key, val
+ end
+ rescue
+ raise IOError, "#{File.join(FUNNEL_ROOT, file)} could not be loaded."
+ end
+ end
+
+ end
+
+end
View
@@ -0,0 +1,35 @@
+module Funnel
+ module Flash
+ class Policy
+
+ def self.response
+ settings = Funnel::Configuration
+ accepted = settings.get(:accepted_origins)
+
+ response = "<?xml version=\"1.0\"?>"
+ response << "<!DOCTYPE cross-domain-policy SYSTEM \"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd\">"
+ response << "<cross-domain-policy>"
+
+ # use the configuration settings to determine who
+ # can connect via the flash socket
+ if accepted.empty?
+ response << allow_tag("*")
+ else
+ accepted.each do |domain|
+ response << allow_tag(domain)
+ end
+ end
+
+ response << "</cross-domain-policy>"
+ response
+ end
+
+ private
+
+ def self.allow_tag domain
+ "<allow-access-from domain=\"#{domain}\" to-ports=\"#{settings.get(:port)}\"/>"
+ end
+
+ end
+ end
+end
View
@@ -3,26 +3,13 @@
module Funnel
module Generators
class Application
-
-
+
def generate destination, options={}
FileUtils.cp_r(template_dir, destination)
-
- if options[:amqp]
- FileUtils.cp_r(template_dir("amqp"), destination)
- end
-
- if options[:xmpp]
- FileUtils.cp_r(template_dir("xmpp"), destination)
- end
-
- if options[:twitter]
- FileUtils.cp_r(template_dir("twitter"), destination)
- end
end
-
+
private
-
+
def template_dir tpl="application"
File.expand_path("../../../../templates/#{tpl}", __FILE__)
end
View
@@ -0,0 +1,49 @@
+module Funnel
+ class Log
+
+ @@threshhold = 1
+
+ # TODO (Maybe): all this can be made way more
+ # meta... at the cost of readibility
+ @@descriptor = {
+ 1 => "DBUG",
+ 2 => "WARN",
+ 3 => "INFO"
+ }
+
+ def self.debug msg
+ log(msg,1) if @@threshhold <= 1
+ end
+
+ def self.warning msg
+ log(msg,2) if @@threshhold <= 2
+ end
+
+ def self.info msg
+ log(msg,3) if @@threshhold <= 3
+ end
+
+ def self.debug!
+ @@threshhold = 1
+ end
+
+ def self.warn!
+ @@threshhold = 2
+ end
+
+ def self.info!
+ @@threshhold = 3
+ end
+
+ def self.shutthefuckup!
+ @@threshhold = 4
+ end
+
+ private
+
+ def self.log msg, level
+ puts "[#{@@descriptor[level]}] #{Time.now} - #{msg}"
+ end
+
+ end
+end
View
@@ -1,24 +0,0 @@
-class Logger
-
- @@threshhold = 3
-
- def self.info msg
- log msg if @@threshhold <= 3
- end
-
- def self.debug msf
- log msg if @@threshhold <= 1
- end
-
- def self.warning msg
- log msg if @@threshhold <= 2
- end
-
- private
-
- def self.log msg
- puts "#{Time.now} - #{msg}"
- end
-
-
-end
View
7 lib/funnel/routing/route.rb 100644 → 100755
@@ -1,19 +1,16 @@
module Funnel
module Routing
-
class Route
-
def initialize path, opts
@opts = opts || {}
@opts[:path] = path
end
-
+
def handler
@opts[:handler]
end
-
-
+
end
end
end
Oops, something went wrong.

0 comments on commit 72345b2

Please sign in to comment.