Mashup University: Tapping The Portable Social Network
This is a presentation. If you'd like to view all the slides like a normal web page, you can.
Tapping the Portable Social Network
- I'm tired of starting over.
- What if I could bring my social network with me to every new site I go to?
- This is all Jeremy Keith's fault
Ingredients
- Ruby on Rails
- The following gems:
- MySQL
- jquery
- A page with an OpenID delegate, an hcard and a blogroll with XFN
- I mean, who doesn't have that?
Getting Started
- Create a rails app:
rails mashup_u
- Make the changes in the README
- Configure the database in config/database.yml
- run
script/server to make sure things work.
The Routine Stuff
- delete public/index.html
- put jquery.js in public/javascript
- create a layout
- add that layout to application.rb
Create Your Model
script/generate model User
Create Your Controllers
script/generate controller users
script/generate controller signin
Now, It's Time To Create a Signin Page!
- open up controllers/signin_controller.rb
- We need a few methods: index, aol_signin, aol_signedin, openid_signin, openid_signedin
- We'll start with OpenID...
Configuring
- We need to tell Rails where to store OpenID stuff
- In environment.rb (at the bottom):
require "openid"
$OPENID_STORE = OpenID::FilesystemStore.new("#{RAILS_ROOT}/tmp/cache")
$OPENID_RETURN = "http://HOST:PORT/signin/openid_signedin"
Handling OpenID
- We need to create the form in
app/views/signin/index.rhtml
- Then we need to create the action!
Logging In With OpenID
- We need to create the openid_signin method in
app/controllers/signin_controller.rb
Let's Log In!
- Woo-hoo! (I'm being hopeful)
Let's Add OpenAuth!
- Go get a key
- Add some config to
environment.rb
- And then add some code to
signin_controller.rb!
Let's Log In!
- Woo-hoo! (again with the hope)
Time to make a User
- We've logged in, now what?
- We need to define what's in our users table.
- Open up
db/migrate/001_create_users.rb and add some columns
Create Some Relationships
- Yet another model:
script/generate model Relationship
Now, We Need Some Users!
- We need some to play with, so let's fake some.
- Run
script/generate migration create_dummy_users
- And let's make some friends!
- When you do this, you should use folks from your buddy list or who are on your blog roll.
We Need to do Something About the Login Process
- Let's make it do something special if you're a new user...
Now, we're ready to do something cool!
- I know, finally!
- Now, we have two different user types, and need to do slightly different things with them.
- We can also assume slightly different things from the data we have about them.
For OpenID Users
- We have an URL.
- What's there?
- What can we infer about the user from the data we find there?
Enter Microformats!
- Let's look for an hcard
- Let's look for some XFN links
- Yes, mofo is that cool.
For AOL Users
- We have a screenname and a display name
- We have a buddy list, so we know who their friends are.
- This version uses javascript to pull in the buddy list that I stole from another project. There is a way to do it server-side.
Back to the Code!
- We need to handle those new users, so into users_controller.rb we go!
- We need to define a
new method.
- And then do something different based on their identity_type.
Creating a Form
- Now we need a form so they an tell us stuff we either don't know, or change the stuff we do.
- Then we need to do something smart when they hit Save.
Finding the Network
- Let's show OpenID first.
- We go grab the identity url
- crawl for XFN links
- then do a lookup and see if they're in our network
- display them to the user and let them choose who to keep and who to ignore.
Find the AOL Network
- It's all built into the buddy list, so we have to do some extra stuff to get to it.
- Sprinkle in some javascript
- A little JSON web service
- And voila, the people in your buddy list who are here already!
Creating Your User
- In users_controller.rb, we need a create method!
- It creates the user, then adds the relationships they checked off from the form.
Possibilities
- It would be trivial to turn these two things into widgets so you could put in your blog URL and have it pre-fill the contacts, even if that's not your identity URL. Same thing with the buddy list stuff.
- What other places are there on the web that aggregate this data in:
- Predictable formats
- With enough "reputation" to make it reliable and accurate
- That don't require Yet Another Network to maintain?
Questions
- Gimme a minute, I need to catch my breath...