hellhound
Hellhound is a Sinatra application gem to connect to facebook, twitter adn in the future other service.
It use memcached to store the user if the variable hellhound_cache is enable
How to use it
Configure the gem for facebook:
configure do
set :fb_api_key, 'your key'
set :fb_app_secret, 'your secret'
enable :hellhound_cache
end
Configure the gem for twitter:
configure do
include Rack::OAuth::Methods
use Rack::OAuth, :key => 'your key',
:secret => 'your secret',
:site => 'http://twitter.com'
enable :hellhound_cache
end
There are two more things that you should do include the helpers methods and implement get_user that is a method that retrieve the user from your data store
helpers do include Sinatra::Hellhound::TwitterHelpers
def get_user id
# i.e. using DataMapper
User.fist :twitter_id => session[:user]
end
end
You will need to override the method get user. This method will search the user in the database in case that the user is not in the cache or the cache was not enabled
def get_user id
User.search(:twitter_id => id)
end
Hellhound provides some helpers:
- current_user
- logged_in?
logout!
create_or_retrive_xxx_user(&block) ** create_or_retrieve_twitter_user(&block) ** create_or_retrieve_facebook_user(&block) ** ... (more in the future)
Also provide some routes
get /oauth_login # => redirect to /oauth_complete (twitter)
get /auth/facebook # => redirect to /auth/facebook/callback (facebook)
Both of the redirect the user to /oauth_complete
# The block should return the user in case the cache is on.
get "/oauth_complete" do
create_or_retrieve_twitter_user do |user_data|
User.first_or_create({
:user_name => user_data["name"],
:screen_name => user_data["screen_name"],
:twitter_id => user_data["id"]
})
end
redirect "/oauth_login"
end
== Copyright
Copyright (c) 2010 Pedro Del Gallego. See LICENSE for details.