Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sven Fuchs
committed
Mar 27, 2010
1 parent
9c25ba2
commit 677c9aa
Showing
18 changed files
with
257 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
sinatra | ||
rack-respond_to | ||
httparty | ||
mbbx6spp-twitter4r --source gems.github.com | ||
twibot | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require 'rack/respond_to' | ||
|
||
class Sinatra::Application | ||
include Rack::RespondTo | ||
|
||
def respond_to | ||
env['HTTP_ACCEPT'] ||= 'text/html' | ||
Rack::RespondTo.env = env | ||
|
||
super { |format| | ||
yield(format).tap do |response| | ||
type = Rack::RespondTo::Helpers.match(Rack::RespondTo.media_types, format).first | ||
content_type(type) if type | ||
end | ||
} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Identity::Helpers | ||
def identity_link_or_name(identity) | ||
identity.url ? | ||
%(<a class="name" href="#{identity.url}">#{identity.name}</a>) : | ||
%(<span class="name">#{identity.name}</span>) | ||
end | ||
|
||
def identity_links(identity) | ||
links = [identity_link(identity)] + profile_links(identity) | ||
links.compact | ||
end | ||
|
||
def identity_link(identity) | ||
%(<a class="name" href="#{identity.url}">#{identity.url}</a>) if identity.url | ||
end | ||
|
||
def profile_links(identity) | ||
identity.profiles.map { |name, profile| profile_link(name, profile_url(name, profile)) }.compact | ||
end | ||
|
||
def profile_link(name, url) | ||
%(<a href="#{url}" class="profile #{name}">#{url}</a>) if url | ||
end | ||
|
||
def profile_url(name, profile) | ||
Identity::Sources[name].profile_url(profile) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
require File.expand_path('../test_helper', __FILE__) | ||
|
||
require 'app' | ||
|
||
set :environment, :test | ||
|
||
class AppTest < Test::Unit::TestCase | ||
include Rack::Test::Methods | ||
|
||
def setup | ||
setup_stubs | ||
end | ||
|
||
test '/ping is protected through http auth' do | ||
Identity::Poller::Twitter.stubs(:new).returns(Object.new.tap { |o| o.stubs(:run!) }) | ||
authorized_get '/ping' | ||
assert_equal 200, last_response.status | ||
|
||
unauthorized_get '/ping' | ||
assert_equal 401, last_response.status | ||
end | ||
|
||
test '/ping is runs a twitter poller' do | ||
poller = Identity::Poller::Twitter.new(:reply, /#update/, :update, { :login => 'login', :process => 1 }) | ||
Identity::Poller::Twitter.stubs(:new).returns(poller) | ||
poller.twitter.expects(:timeline_for).with(:replies, :since_id => 1).returns([status('rugb_test', '3update')]) | ||
|
||
log = capture_stdout { authorized_get '/ping' } | ||
|
||
assert_match /imposing as @login/, log | ||
assert_match /Received 1 reply/, log | ||
end | ||
|
||
test '/ responding to :html' do | ||
setup_stubs | ||
command('update', 'rugb', 'svenfuchs', 'twitter:svenfuchs github:svenphoox').dispatch | ||
get '/' | ||
|
||
assert_equal 'text/html', last_response['Content-Type'] | ||
assert_match /svenfuchs/, last_response.body # TODO use some tag matcher | ||
end | ||
|
||
test '/ responding to :json' do | ||
Identity.new(:twitter => { :handle => 'svenfuchs' }).save | ||
get '/', {}, { 'HTTP_ACCEPT' => 'application/json' } | ||
|
||
assert_equal 'application/json', last_response['Content-Type'] | ||
assert_equal({ 'twitter' => { 'handle' => 'svenfuchs' } }, JSON.parse(last_response.body).first['profiles']) | ||
end | ||
|
||
protected | ||
|
||
def app | ||
Sinatra::Application | ||
end | ||
|
||
def authorized_get(path) | ||
get path, {}, { 'HTTP_AUTHORIZATION' => encode_credentials(ENV['twitter_login'], ENV['twitter_password']) } | ||
end | ||
|
||
def unauthorized_get(path) | ||
get path, {}, { 'HTTP_AUTHORIZATION' => encode_credentials('go', 'away') } | ||
end | ||
|
||
def encode_credentials(username, password) | ||
"Basic " + Base64.encode64("#{username}:#{password}") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.