ruby-libnio

Library for writing Notify.io(notify.io) applications

Dependencies

You’ll need the HTTParty gem

Setting up Notifiers

To use ruby-libnio, include the LibNio module in the class you want to send notifications from and set your Notify.io API key:

class Notifier
  include LibNio
  notify_api_key '[key]'
end

LibNio will include HTTParty in the Notification class and set the base_uri to ‘notify.io

To set up your notifier you’ll want to set defaults for some of the parameters that the Notify.io is expecting:

n = Notifier.new do |n|
  n.title = "GHNotify Message"
  n.link = "http://ghnotiy.com"
  n.sticky = true
  n.icon = "http://a3.twimg.com/profile_images/517037601/notifyio-icon.png"
end

Note that you can override these defaults on a per notification basis if you would like later.

Sending Notifications

To send notifications to users using Notify.io you will need the md5 hash of the Gmail address that they signed up with Notify.io with.

Note that the md5 hash of [email protected] and [email protected] will be different, so it is important that you use the correct casing. In the future, the Notify.io API may include a method to verify user hashes, but for now you might need to explicitly ask for them to ensure notifications are sent.

With that in mind, here is how we might send a message to someone, given we know their userhash:

userhash_1 = "a9d9e4fd104a3ae26793ca155c6ee872"
n1.notify(userhash_1, :text => "some text")

This will POST to the Notify.io API, and send the default parameters you set earlier, as well as the text parameter you send in the method call. Notify’s API will return ‘OK’ if the POST is successful.

As mentioned, you can override the defaults on a per-notification basis if you want:

userhash_1 = "a9d9e4fd104a3ae26793ca155c6ee872"
n1.notify(userhash_1, :text => "some text", :title => "new title", :sticky => false)

Lastly, it is possible to send the same notification to a number of users:

userhash_1 = "a9d9e4fd104a3ae26793ca155c6ee872"
userhash_2 = "5add5f77c09f4c639293e7254a1faf77"
users = [userhash_1, userhash_2]
n2.notify_all(users, :text => "Tell everyone")

This will return an array of the responses codes from the Notify.io API.

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2010 Hunter Gillane. See LICENSE for details.