Permalink
Browse files

added support for rack-throttle

throttling set at 100 queries per hour
  • Loading branch information...
1 parent 0052f52 commit f3b7dd9ff96c3f82ce03f0d63a4532c7042f8cb8 @sflinter committed Feb 27, 2012
Showing with 53 additions and 24 deletions.
  1. +2 −4 .bundle/config
  2. +7 −1 Gemfile
  3. +27 −8 Gemfile.lock
  4. +7 −0 application.rb
  5. +1 −2 config.ru
  6. +1 −1 environment.rb
  7. +5 −5 spec/application_spec.rb
  8. +3 −3 spec/spec_helper.rb
View
@@ -1,4 +1,2 @@
----
-BUNDLE_FROZEN: "1"
-BUNDLE_DISABLE_SHARED_GEMS: "1"
-BUNDLE_PATH: vendor/bundle
+--- {}
+
View
@@ -1,6 +1,6 @@
source :rubygems
-gem "sinatra", "~> 1.1.2"
+gem "sinatra", "~> 1.3.2"
# Gems to manage authentication with Twitter
gem "twitter_oauth", "~> 0.4.3", :git => "git://github.com/bantamnet/twitter_oauth.git"
@@ -11,3 +11,9 @@ gem "RedCloth", "~> 4.2.3"
gem "mime-types", "~> 1.16"
gem "haml", "~> 2.2.22"
gem "builder", "~> 2.1.2"
+
+# Gems to handle rate throttling
+gem "rack-throttle", "~> 0.3.0"
+
+gem "rspec", "~> 2.8.0"
+gem "rack-test", "~> 0.6.1"
View
@@ -13,17 +13,33 @@ GEM
RedCloth (4.2.3)
builder (2.1.2)
crack (0.1.6)
+ diff-lcs (1.1.3)
haml (2.2.24)
httparty (0.5.2)
crack (= 0.1.6)
- json (1.5.1)
+ json (1.6.5)
mime-types (1.16)
- oauth (0.4.4)
- rack (1.2.1)
- sinatra (1.1.2)
- rack (~> 1.1)
- tilt (~> 1.2)
- tilt (1.2.2)
+ oauth (0.4.5)
+ rack (1.4.1)
+ rack-protection (1.2.0)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rack-throttle (0.3.0)
+ rack (>= 1.0.0)
+ rspec (2.8.0)
+ rspec-core (~> 2.8.0)
+ rspec-expectations (~> 2.8.0)
+ rspec-mocks (~> 2.8.0)
+ rspec-core (2.8.0)
+ rspec-expectations (2.8.0)
+ diff-lcs (~> 1.1.2)
+ rspec-mocks (2.8.0)
+ sinatra (1.3.2)
+ rack (~> 1.3, >= 1.3.6)
+ rack-protection (~> 1.2)
+ tilt (~> 1.3, >= 1.3.3)
+ tilt (1.3.3)
PLATFORMS
ruby
@@ -34,5 +50,8 @@ DEPENDENCIES
haml (~> 2.2.22)
httparty (~> 0.5.2)
mime-types (~> 1.16)
- sinatra (~> 1.1.2)
+ rack-test (~> 0.6.1)
+ rack-throttle (~> 0.3.0)
+ rspec (~> 2.8.0)
+ sinatra (~> 1.3.2)
twitter_oauth (~> 0.4.3)!
View
@@ -7,8 +7,15 @@
require 'geonames'
require 'uri'
+# Gems related to rate limiting
+require 'rack/throttle'
+require 'dbm'
+
mime_type :rdf, 'application/rdf+xml'
+# Throttle, with a max of 100 queries per hour
+use Rack::Throttle::Hourly, :max => 100, :cache => DBM.new('tmp/throttle')
+
helpers do
def valid_uri?(uri = "")
begin
View
@@ -1,5 +1,4 @@
-# Dir["vendor/gems/*/lib"].each { |path| $:.unshift path }
-
+require 'rubygems'
require 'bundler'
Bundler.require
View
@@ -1,4 +1,4 @@
-ENV['GEM_PATH'] = '/home/flintero/gems:/usr/lib/ruby/gems/1.8'
+# ENV['GEM_PATH'] = '/home/flintero/gems:/usr/lib/ruby/gems/1.8'
ENV['RACK_ENV'] ||= 'production'
require 'rubygems'
View
@@ -7,29 +7,29 @@ def app
Sinatra::Application.new
end
- specify 'should show the default index page' do
+ it 'should show the default index page' do
get '/'
last_response.should be_ok
end
- specify 'should show the semantictweet page' do
+ it 'should show the semantictweet page' do
get '/semantictweet'
last_response.status.should == 302
end
- specify 'should show the semantictweet friends page' do
+ it 'should show the semantictweet friends page' do
get '/semantictweet/friends'
last_response.should be_ok
last_response.body.should include 'foaf:PersonalProfileDocument'
end
- specify 'should show the semantictweet friends page' do
+ it 'should show the semantictweet friends page' do
get '/semantictweet/followers'
last_response.should be_ok
last_response.body.should include 'foaf:PersonalProfileDocument'
end
- specify 'should show the tag page' do
+ it 'should show the tag page' do
tags = "%23dev8d+%23bc"
get "/tags/#{tags}"
last_response.should be_ok
View
@@ -1,7 +1,7 @@
require 'rubygems'
require 'sinatra'
-require 'spec'
-require 'spec/interop/test'
+require 'rspec/core'
+# require 'rspec/interop/test'
require 'rack/test'
# set test environment
@@ -12,6 +12,6 @@
require 'application'
-Spec::Runner.configure do |config|
+RSpec.configure do |config|
end

0 comments on commit f3b7dd9

Please sign in to comment.