Twitter Notifier application for Linux in Ruby: Overhauled

Last month, I spent a weekend writing a short application to retrieve updates from Twitter and display notifications using libnotify in Ubuntu. Although it “worked” after that weekend, I’ve put a great deal of effort during my free time over the last month toward completely rewriting it to be much more of an application, instead of just a functional script.

Over the last month, I’ve made drastic changes and improvements to the functionality, the code structure, and have made numerous bug fixes. I might has well have ripped out its guts and started over, but it has been absolutely worth it. (code at the end of the post)

For starters, instead of having a config file defining which feed to follow, I’ve turned it into a daemon that can be started and stopped, and to which new requests can be added to a stack (so that you can have multiple lists or feeds being followed).

$ ~/social-notifier/application.rb start
$ ~/social-notifier/application.rb add twitter home
[0] Twitter: home: []

$ ~/social-notifier/application.rb add twitter list the_nerdery our-nerds
[0] Twitter: home: []
[1] Twitter: list: ["the_nerdery", "our-nerds"]

$ ~/social-notifier/application.rb add twitter search "#webchallenge"
[0] Twitter: home: []
[1] Twitter: list: ["the_nerdery", "our-nerds"]
[2] Twitter: search: ["#webchallenge"]

$ ~/social-notifier/application.rb delete 1
[0] Twitter: home: []
[2] Twitter: search: ["#webchallenge"]

$ ~/social-notifier/application.rb stop

Because this was my first experience with a real desktop application (except for a window-based calculator application over the Christmas holidays) I spent many hours away from the computer thinking about how it could be better written, learning and discovering the considerations that must be made of a desktop applications, and have made countless revisions. I’ve rewritten each facet of the application outside of the main process (the messenger, the notifier, and the requests) to behave as interfaces, thereby allowing a developer to add their own messenger, notifier, or request classes and extend the functionality of the system, without having to modify the existing classes or the main process whatsoever.

The base notifier class can now be extended to use a notification system other than libnotify (even if that were to mean email or SMS notifications — not likely, I know).

# require the notifier class you'd like to use (only one)
require_relative 'lib/notifier/libnotify'

The TCP-based messenger (which allows interaction with the daemon process) can be switched with the existing file-based messenger, or replaced with some other system for communication between the processes (POSIX didn’t work out, but maybe it can be threatened harshly and thereby forced to work down the road).

# require the messenger class you'd like to use (only one)
# require_relative 'lib/messenger/file-queue'
require_relative 'lib/messenger/tcp'

Different types of requests can be added, thereby allowing users to listen for more than just Twitter updates (e.g. Facebook, RSS/ATOM, email). (I’ve already started plans on adding Facebook requests, but recent changes to the Facebook API have slowed me down.) Since the stack doesn’t care what types of requests it has in it, it won’t make any difference what you put in it, so long as it has the required functions that the main process calls on each request.

# require any request classes you'd like to use (multiple)
# require_relative 'lib/request/facebook' ## Not working yet.
require_relative 'lib/request/twitter'

Granted, to some extent, Twitter, email, RSS, and Facebook notifiers already exist–even for Linux–but usually not in one application nor in one so light-weight (a few window-based applications can notify you of Twitter and/or Facebook updates, for example, and there have to be numerous RSS readers). The goal hasn’t been to write something to replace or to be better than such applications, but simply to write a program that I would actually use, and to hopefully learn from the experience.

Especially in its latest phases, this “Social Notifier” application has already become something that I actually WANT to use. That being said, it has accomplished its first goal: filling a need that I had. (I even had it running at on my workstation for 24 straight hours during the Nerdery’s Overnight Web Challenge this past weekend so that I could follow the event hashtag alongside my home feed. I also keep it scanning my home feed and The Nerdery’s “Our Nerds” list constantly at work and at home.)

At any rate, the new version is available here. The README file has full instructions, and you’ll still need to get Twitter access and application tokens (see instructions in config-dist.rb) to retrieve Twitter status updates.

Comments and criticism on the code and methodology would be greatly appreciated.

UPDATE: source code link to point to github.

1 thought on “Twitter Notifier application for Linux in Ruby: Overhauled”

Leave a Reply