Silence is Foo Mental notes on Ruby, Git, Rails and whatever geeky thing

30Jun/10Off

Prowly, a Ruby API wrapper for Prowl (the Growl client for the iPhone)

What is Growl?

Growl lets Mac OS X applications unintrusively tell you when things happen.

What is Prowl?

Prowl is the Growl client for the iPhone OS. Prowl was made to send the Growl notifications to your iPhone when you are not in front of your computer, but since it has an API you can send notifications to your iPhone from where you want.

What is Prowly?

It's a gem and it's an API wrapper (in Ruby), meaning you will be able to send notifications to your iPhone from any Ruby application (Rails, Sinatra, etc.) or even from the terminal.

What do I need to use Prowl in my iPhone?

1. Install the Prowl app

2. Create a Prowl account in this page

Once you created your account, you can register your iPhone and get your  API Key (which is a 40-byte hexadecimal string) from the settings page, this API Key will be used by Prowly to send notifications to your iPhone.

Where can I get Prowly?

Source code: http://github.com/rafmagana/prowly

Installing the gem:

$ gem install prowly

Usage as a Gem (in a ruby application)

require 'rubygems'
require 'prowly'

Prowly.notify do |n|
     n.apikey = "your_apikey_here"
     n.priority = Prowly::Notification::Priority::MODERATE
     n.application = "My Site"
     n.event = "Alert"
     n.description = "Something went wrong!"
end

Another way.

notif = Prowly::Notification.new(:apikey => "your_apikey_here",
                                 :application => "My Site",
                                 :description => "Something went wrong")

api_keys = ["apikey_1", "apikey_2", "apikey_n"]

notif = Prowly::Notification.new(:apikeys => api_keys,
                                 :application => "Prowly",
                                 :description => "Testing...")

response = Prowly.notify(notif)

Usage as a command-line tool

To see the list of options issue the following command:

$ prowly -h

The help is pretty self-explanatory but here is an example:

$ prowly -k "your_apikey_here" -e "My Site" -d "Something went wrong" -p HIGH

Handling the Prowl API response

api_call = Prowly.notify(notif)

Most of the times you'd only have to check if the call failed or succeeded, Prowly has a method to know it:

puts "Cool" if api_call.succeeded?

puts "Oops" unless api_call.succeeded?

But if you want to know the details of the call:

api_call.status # "success" or "error"
api_call.code # 200 for success; 401 or others for error

#api_call.message would be an empty string if the call was successful, so
puts api_call.message if api_call.status == "error" # => Invalid API Key(s)

Since Prowl only allows 1000 calls per hour, it might come in handy you to know your remaining api calls:

puts api_call.remaining if api_call.status == "success" # => 980

puts api_call.remaining if api_call.succeeded? # => 980

Now, what about real-world usages?

* Server monitoring using the God gem (which uses Prowly)=> http://github.com/mojombo/god

get notifications in your iPhone when a process is using a lot of RAM or CPU, or when a process is not running, etc.

* Get notifications when your deployment process is done

*If you have a large set of tests in your application (unit tests, etc), get notifications after all the tests have finished.

* ... etc, etc, etc.

Hope it helps, see you!

Filed under: iPhone, ruby Leave a comment