adamcooke / twitterfications

A Rails plugin which allows you to send tweets to alert you of specific activities within your app with considerable ease

This URL has Read+Write access

adamcooke (author)
Sat Jun 06 08:20:48 -0700 2009
commit  77abb2288a74c21eac2fa0d0221de01fe0258e28
tree    ba1f4de04c19fa67baa1f5ec881502b7999c5c3f
parent  ad4a882f03d329e1384cb4f95c6589a34e109e32
name age message
file README.markdown Loading commit data...
file init.rb
directory lib/
README.markdown

Twitterfications

Twitterfications allows you to easily setup twitter notifications from your Rails application.

script/plugin install git://github.com/adamcooke/twitterfications.git

Once installed, simply configure by adding the config below to config/initializers/twitterfications.rb

Twitterfications.method = :direct
Twitterfications::Twitter.username = 'my_username'
Twitterfications::Twitter.password = 'my_password'

The method can be set to :direct or :background. Direct requests are sent in the current thread where as background are forked into another process. To use background processing, you will need to install the spawn plugin.

script/plugin install git://github.com/tra/spawn

ActiveRecord Usage

This plugin can be directly embedded with your ActiveRecord models.

class Person < ActiveRecord::Base

  ## Automatically update twitter on create, update, destroy or save
  tweet(:create)    { |p| "#{p.full_name} has been created in the application"}
  tweet(:destroy)   { |p| "#{p.full_name} has been removed from the application"}
  tweet(:update)    { |p| "#{p.full_name} has been updated in the application"}

  ## Alternatively, include twitter notifications in your own callbacks
  after_create :my_callback

  private

  def my_callback
    tweet "This is a tweet about #{self.full_name} from my own callback"
  end
end

ActionController Usage

You can also use the tweet(status) method in any of your controller actions.

Direct usage

If you'd like to tweet from anywhere else in your application, you can post directly, by calling:

Twitterfications.post("Your tweet here")