Browse files

changed from dbm to gdbm

  • Loading branch information...
1 parent ec57953 commit 65c557923c20fdaea584cc59f9a8d30f03f1e56b @sflinter committed Feb 28, 2012
Showing with 68 additions and 66 deletions.
  1. +67 −65 application.rb
  2. +1 −1 config.ru
View
132 application.rb
@@ -9,87 +9,89 @@
# Gems related to rate limiting
require 'rack/throttle'
-require 'dbm'
+require 'gdbm'
-mime_type :rdf, 'application/rdf+xml'
+class SemanticTweet < Sinatra::Application
-# Throttle, with a max of 100 queries per hour
-use Rack::Throttle::Hourly, :max => 100, :cache => DBM.new('tmp/throttle')
+ # Throttle, with a max of 100 queries per hour
+ use Rack::Throttle::Hourly, :max => 100, :cache => GDBM.new('tmp/throttle.db')
-helpers do
- def valid_uri?(uri = "")
- begin
- URI.parse(uri)
- true
- rescue URI::InvalidURIError
- false
+ helpers do
+ def valid_uri?(uri = "")
+ begin
+ URI.parse(uri)
+ true
+ rescue URI::InvalidURIError
+ false
+ end
end
end
-end
-configure do
- set :views, "#{File.dirname(__FILE__)}/views"
-end
+ configure do
+ mime_type :rdf, 'application/rdf+xml'
+ set :views, "#{File.dirname(__FILE__)}/views"
+ end
-before do
- next if request.path_info =~ /ping$/
- @client = TwitterOAuth::Client.new(
- :consumer_key => ENV['CONSUMER_KEY'] || APP_CONFIG[:twitter][:consumer_key],
- :consumer_secret => ENV['CONSUMER_SECRET'] || APP_CONFIG[:twitter][:consumer_secret],
- :token => APP_CONFIG[:twitter][:access_token],
- :secret => APP_CONFIG[:twitter][:access_token_secret]
- )
-end
+ before do
+ next if request.path_info =~ /ping$/
+ @client = TwitterOAuth::Client.new(
+ :consumer_key => ENV['CONSUMER_KEY'] || APP_CONFIG[:twitter][:consumer_key],
+ :consumer_secret => ENV['CONSUMER_SECRET'] || APP_CONFIG[:twitter][:consumer_secret],
+ :token => APP_CONFIG[:twitter][:access_token],
+ :secret => APP_CONFIG[:twitter][:access_token_secret]
+ )
+ end
-get '/' do
- haml :index
-end
+ get '/' do
+ haml :index
+ end
-get '/about' do
- haml :about
-end
+ get '/about' do
+ haml :about
+ end
-get '/contact' do
- haml :contact
-end
+ get '/contact' do
+ haml :contact
+ end
-get '/favicon.ico' do
-end
+ get '/favicon.ico' do
+ end
-# Note the formulation of a specific regexp is required here. The
-# preferred option of '/tag/:tags' doesn't match all URIs properly
-get %r{\A/tags/(.*)} do |tags|
- @tags = tags.split(' ')
- content_type :rdf
- builder :tags
-end
+ # Note the formulation of a specific regexp is required here. The
+ # preferred option of '/tag/:tags' doesn't match all URIs properly
+ get %r{\A/tags/(.*)} do |tags|
+ @tags = tags.split(' ')
+ content_type :rdf
+ builder :tags
+ end
-get '/screen_name' do
- redirect "/#{params[:screen_name]}"
-end
+ get '/screen_name' do
+ redirect "/#{params[:screen_name]}"
+ end
-get '/:screen_name/:who' do
- @tweeter = Tweeter.new(@client, params[:screen_name], params[:who])
- if @tweeter.exists?
- content_type :rdf
- builder :foaf
- else
- raise not_found
+ get '/:screen_name/:who' do
+ @tweeter = Tweeter.new(@client, params[:screen_name], params[:who])
+ if @tweeter.exists?
+ content_type :rdf
+ builder :foaf
+ else
+ raise not_found
+ end
end
-end
-get '/:screen_name' do
- redirect "/#{params[:screen_name]}/friends"
-end
+ get '/:screen_name' do
+ redirect "/#{params[:screen_name]}/friends"
+ end
-error do
- e = request.env['sinatra.error']
- Kernel.puts e.backtrace.join("\n")
- content_type :html
- 'Oops, we messed up!'
-end
+ error do
+ e = request.env['sinatra.error']
+ Kernel.puts e.backtrace.join("\n")
+ content_type :html
+ 'Oops, we messed up!'
+ end
-not_found do
- @screen_name = params[:screen_name]
- haml :'404'
+ not_found do
+ @screen_name = params[:screen_name]
+ haml :'404'
+ end
end
View
2 config.ru
@@ -13,4 +13,4 @@ log = File.new("log/sinatra.log", "a")
$stdout.reopen(log)
$stderr.reopen(log)
-run Sinatra::Application
+run SemanticTweet

0 comments on commit 65c5579

Please sign in to comment.