Associate models with profiles on other websites
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
generators/profile_validator_migration
lib
tasks
test
.gitignore
MIT-LICENSE
README.rdoc
Rakefile
init.rb
install.rb
uninstall.rb

README.rdoc

ProfileValidator

This plugin allows ActiveRecord models to be associated with profiles on other websites. In order to confirm ownership, it checks the profile for the presence of specified URL, which the user will have to add. Currently, any website that uses the HCard microformat (microformats.org/wiki/hcard) is supported, but it's possible to work with other sites by subclassing the Profile model. It's been tested with LinkedIn, Flickr, and Twitter.

Installation

In order to create the Profile database table, run the following generator:

script/generate profile_validator_migration

Examples

To add ProfileValidator to your model, simply add 'validates_profile':

class User < ActiveRecord::Base
  validates_profile
end

This will create the association with the Profile model, and add a new method, url_for_profile, which you'll probably want to overload to match the user's page within your application. The user will need to put this URL in his/her profile in order to claim it. A Profile has two properties: the URL of the profile page and a Profileable model, which is connected with a polymorphic association. validates_profile accepts an optional :url_format paramter which specifies a regular expression (or array of regular expressions) that the profile URL must match:

class User < ActiveRecord::Base
  validates_profile :url_format => /^http:\/\/www\.flickr\.com\/people\/\w+$/
end

By default, validates_profile adds a has_one relationship with Profile. If you would like to associate multiple profiles with your model, use the multiple option:

class User < ActiveRecord::Base
  validates_profile :multiple => true
end

If you'd like to associate users with sites that don't support HCard, you can subclass the Profile model and overload the protected data method, which is used to fetch profile information, and the is_owned? method, which checks if the profile is owned by the associated model. You would then specify the new Profile like this (for a FacebookProfile):

class User < ActiveRecord::Base
  validates_profile :site => 'facebook'
end

Libraries

ProfileValidator uses mofo (mofo.rubyforge.org/) to retrieve microformat data from websites. The test suite uses Shoulda (thoughtbot.com/projects/shoulda) for contexts and Mocha (mocha.rubyforge.org/) for mocking and stubbing.

Todo

  • Make validation optional

  • Define a better default URL


Copyright © 2008 Viget Labs, released under the MIT license