So in preparation for Rails Rumble I’ve been researching a lot of sexy little plugins. We have also had a need to test this plugins to make sure they’ll work not just locally but in a shared hosting environment (the first time you get burned and spend an entire weekend, 16 hours, trying to figure out why something that works perfectly on your local box dies horribly on shared hosts you learn to test everything). To accomplish this testing we’ve needed a small little app so I can get the bare minimum for the plugins in there. I’d like to post everything I did while I wait for Lynn to push everything up to test. Mostly this is just a quick run down because someone else has already done a far better job than I could explaining in depth how to install and configure all this stuff. This is also by no means how you should do any of this, this is solely for testing out various plugins and packages.
The plugins, gems, and kitchen sink
What I’ve got up and working on my local box so far is:
- Simple Email Notification with ActionMailer
- SMS Fu
- Twitter4r
- Gravatar Profile Image
- Juggernaut
- BackgrounDRB
- GoogleCalendar/ICal
Simple Email Notification
Won’t really go into this, it’s obvious and everyone has done it a million times
SMS Fu
- Clone it
- Include it
- Put this code in there:
Controller:
def index
@carriers = %w(alltell ameritech at&t bellsouthmobility blueskyfrog boost cellularsouth helio kajeet metropcs powertel pscwireless qwest southernlink suncom t-mobile virgin verizon)
end
def text_message
deliver_sms(params[:pages][:phone_number],params[:pages][:carrier],”Test Text Message”)
redirect_to :action => ‘index’
end
View:
<% form_for :pages, :url => {:action => :text_message} do |f| -%>
Phone Number: <%= f.text_field :phone_number %>
<br/>
Carrier: <%= f.select :carrier, @carriers %>
<br/>
<%= submit_tag "Send Text" %>
<% end -%>
Twitter4r
- Install the gem
- require the gem
- Use the following code
Controller
def twitter_message
client = Twitter::Client.new(:login => params[:pages][:user_name], :password => params[:pages][:password])
if client.authenticate?(params[:pages][:user_name], params[:pages][:password])
new_message = client.status(:post, params[:pages][:text_message])
return redirect_to :action => ‘index’
else
flash[:notice] = “Failed to authenticate”
return redirect_to :action => ‘index’
end
end
View
<% form_for :pages, :url => {:action => :twitter_message} do |f| -%>
Twitter User Name: <%= f.text_field :user_name %>
<br/>
Twitter Password: <%= f.password_field :password %>
<br/>
Text To Post: <%= f.text_field :text_message, :limit => 140 %>
<br/>
<%= submit_tag "Send Twitter" %>
<% end -%>
Gravatar
Just use the code in your application helper
Juggernaut
- Make sure you have json and eventmachine installed
- install the gem
- install the plugin
- juggernaut -g juggernaut.yml (to make the config file)
- Use the following code
- juggernaut -c juggernaut.yml (to start the push server)
Layout (or anywhere you want to use Juggernaut)
<%= javascript_include_tag 'juggernaut/swfobject' %>
<%= javascript_include_tag 'juggernaut/juggernaut' %>
<%= juggernaut(:channels => ['chat', 'notifications']) %>
View
<fieldset><legend>Chat</lengend>
<ul id="chat_data" style="list-style:none">
</ul>
</fieldset>
<%= form_remote_tag(
:url => { :action => :send_data },
:complete => "$('chat_input').value = '#{session.id}'" ) %>
<%= text_field_tag( 'chat_input', session.id, { :size => 20, :id => 'chat_input'} ) %>
<%= submit_tag "Chat" %>
</form>
<br/><br/>
<fieldset><legend>Notifications</legend>
<ul id="notification_data" style="list-style:none">
</ul>
</fieldset>
juggernaut_hosts.yml
:hosts:
- :port: 5001
:host: 127.0.0.1
:public_host: how_the_public_accesses_your_site.com
:public_port: 5001
BackgrounDRB
- install chronic and packet requirements
- Clone the code
- rake backgroundrb:setup
- ruby script/generate worker notifications
- use the following code
- ruby script/background start (to start the backgrounDRB)
backgroundrb.yml
:backgroundrb:
:ip: 0.0.0.0
:port: 11006
:schedules:
:notifications_worker:
:check_notifications:
:trigger_args:
:start: <%= Time.now + 5.seconds %>
:end: <%= Time.now + 1.year %>
:repeat_interval: <%= 5.minutes %>
notifications_worker.rb
class NotificationsWorker < BackgrounDRb::MetaWorker
set_worker_name :notifications_worker
def create(args = nil)
logger.info 'created worker'
end
def check_notifications
if true
logger.info 'sending notification'
Juggernaut.send_to_channel("new Insertion.Top(\"notification_data\", \"<li>Sending Notification at #{Time.now}<\/li>\");", "notifications")
end
end
end
View
<fieldset><legend>Notifications</legend>
<ul id="notification_data" style="list-style:none">
</ul>
</fieldset>
ICalendar
- Install the gem
- require the gem
- Use the following code
- Add to Google Calendar to check your work
View
def calendar
@cal = Icalendar::Calendar.new
[{:name => 'Meeting', :start => Time.now.beginning_of_day, :end => Time.now},
{:name => 'Greeting', :start => Time.now.beginning_of_day-1.day, :end => Time.now-1.day}].each do |comp|
event = Icalendar::Event.new
event.start = comp[:start].strftime(”%Y%m%dT%H%M%S”)
event.end = comp[:end].strftime(”%Y%m%dT%H%M%S”)
event.summary = comp[:name]
@cal.add event
end
@cal.publish
headers['Content-Type'] = “text/calendar; charset=UTF-8″
render :text => @cal.to_ical, :layout => false
end
What you will end up with is a very ugly little app that will look like this:




