This is the equivalent of a 'Hello world' example, but for the basic functionality you need to implement a modern, socially-connected site. It's designed to be a minimal scaffold that you can easily insert your own application logic and styling into, while it handles authenticating users and allowing them to share your content on Twitter and Facebook. It's written in Ruby using the Sinatra web framework.
What it does
Users sign in using either a Twitter or Facebook account.
Once signed in, either an existing User database record is found, or a new one is created.
This record has custom application data for each user. In our case, it's just a favorite color.
Signed in users can edit this color preference
They can also tweet or wall post directly from our site
How to install
Ensure you have Ruby and RubyGems installed.
$> cd Downloads/hellosocialworld/
$> bundle install --without production
$> sudo gem install heroku
$> heroku createyour app's name, eg 'hellosocialworld_petewarden' (but it must be unique)
Edit apikeys.rb to add your own keys, after creating apps on Twitter and Facebook
$> git push heroku master
Visit the site yourappname.heroku.com to see if you can log in
If nothing shows up, run
$> heroku logs -n 100to look at the error logs
To simplify the code and the user interface, there's no way to link Twitter and Facebook accounts. The same person logging in via a different service is treated as a different user.
There's no email verification or other traditional account creation process. It's assumed that the Twitter or Facebook sign-in process is all that's needed.
Only Facebook and Twitter logins are supported. It should be easy enough to add additional services if needed, but this combination is enough for my purposes.
The code for the application is comparatively short thanks to the hard work of these projects that provide great functionality as pre-packaged gems:
- Sinatra - Elegant and lightweight web framework
- OmniAuth - Flexible and comprehensive authentication system
- DataMapper - Occasionally maddening, but very clean and easy persistent database storage
- twitter_oauth - Solid library for calling the Twitter API
- rack/csrf - A simple way of guarding against CSRF attacks
- fb_graph - A good Facebook API library
Drop me an email at firstname.lastname@example.org with any questions, bug reports or suggestions.
Follow me on Twitter - @petewarden