Read'n'Code - Flaviu Simihaian's Blog

How to Send User Signup Notifications to Campfire From Rails

Let’s say you have a user signup page, and you want to be notified whenever a user signs up in the Campfire chat.

tinder is the best library to interface with the Campfire API. I know that because it was last released today. So, gem install tinder.

Then, open your user.rb file and add the following:

1
after_save :announce_signup
1
2
3
4
5
def announce_signup
    campfire = Tinder::Campfire.new 'yoursubdomain', :token => 'your_token_here'
    room = campfire.find_room_by_id(enter_room_id)
     room.speak "#{name} signed up!"
end

The first line makes sure the announcement happens only after save.

Then, we initiate the connection to Campfire using tinder and our subdomain, key, and room id. The speak function assumes your User model has a name attribute, which would be printed in the Campfire chat.

Comments

Fork Flaviu on GitHub