File tree 4 files changed +14
-0
lines changed
4 files changed +14
-0
lines changed Original file line number Diff line number Diff line change 1
1
source 'http://rubygems.org'
2
2
3
3
gem 'rails' , '3.0.0.beta4'
4
+ gem 'sinatra'
4
5
5
6
# async wrappers
6
7
gem '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.
4
4
5
5
* Hit localhost:3000/widgets to do a 1s async mysql query
6
6
* 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)
7
8
8
9
Requirements:
9
10
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 54
54
55
55
# This is a legacy wild controller route that's not recommended for RESTful applications.
56
56
# 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
+
57
61
match ':controller(/:action(/:id(.:format)))'
58
62
end
You can’t perform that action at this time.
0 commit comments