File tree Expand file tree Collapse file tree 4 files changed +14
-0
lines changed
Expand file tree Collapse file tree 4 files changed +14
-0
lines changed Original file line number Diff line number Diff line change 11source 'http://rubygems.org'
22
33gem 'rails' , '3.0.0.beta4'
4+ gem 'sinatra'
45
56# async wrappers
67gem 'rack-fiber_pool' , :require => 'rack/fiber_pool'
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ Simple async demo stack with Rails 3 + EventMachine and Fibers.
44
55 * Hit localhost:3000/widgets to do a 1s async mysql query
66 * Hit localhost:3000/widgets/http to make an HTTP call back to /widgets - recursive! :-)
7+ * Hit localhost:3000/twitter to load a mounted async Sinatra app (reports latests rails 3 tweets)
78
89Requirements:
910
Original file line number Diff line number Diff line change 1+ class Twitter < Sinatra ::Base
2+ get '/twitter' do
3+ http = EM ::HttpRequest . new ( "http://search.twitter.com/search?q=rails+3&format=json" ) . get
4+ tweets = ActiveSupport ::JSON . decode ( http . response )
5+ tweets = tweets [ 'results' ] . collect { |t | t [ 'text' ] } . join ( "</br>" )
6+ tweets
7+ end
8+ end
Original file line number Diff line number Diff line change 5454
5555 # This is a legacy wild controller route that's not recommended for RESTful applications.
5656 # Note: This route will make all actions in every controller accessible via GET requests.
57+
58+ # mount async sinatra app (in metal folder)
59+ match '/twitter' , :to => Twitter
60+
5761 match ':controller(/:action(/:id(.:format)))'
5862end
You can’t perform that action at this time.
0 commit comments