Working with Twitterizer

I’ve been working on a custom FTP application for the past few days. The application is designed to read a list of remote resource files and go and download each file.

This application will be automated once its setup in production. No one will have to interact with it on a daily basis – it will just go and do the job it was designed for. Part of that job is to log its actions, so that the IT staff can review what’s happened and track down any issues that may come up.

Twitter
Twitter

If you’re on the web at all these days, you’ve no doubt, heard of Twitter. Its simple format makes it a great tool for sharing status information. It seemed to me that having the application tweet its status would be an easy, fun way to use Twitter and provide some semi-useful information.

Twitter exposes an extensive application programming interface, API, for third party developers to use. I briefly considered rolling my own wrappers for the Twitter API. However, that really wasn’t in the best interest my small project’s time line.

Instead, I decided to do a little searching for a pre-written, community supported, API wrapper for .Net. That’s when I found Twitterizer. The project is hosted on Google Code, so getting the files was a snap.

I downloaded the most recent, stable release (1.0.1.99 as I write this), and added it into my C# project. I had already setup a new account with Twitter for the application to use when broadcasting it’s status updates, so I had everything ready to go.

As I wrote the FTP application, I included a number of events that could be logged. Each log item, like the start of a download, had a “level” associated with it. The “level” allowed me to make the application really talkative, or fairly mute, depending on the configuration files.

Knowing that I wouldn’t want everything out on the application’s Twitter feed, I setup a special “log to twitter” minimum level for logging. If the log message was below the threshold, then the application would tweet it too. I also included a setting in the configuration file to disable the Twitter logging completely.

Working with Twitterizer couldn’t have been any easier. Their API wrapper has everything you need to easily send a status update.

?View Code CSHARP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
private void statusUpdate(string message, Utilities.LogLevel logLevel)
{
       string tweet = string.Concat(message, " #fr");
       if (tweet.Length > 140)
       {
           tweet = tweet.Substring(0, 140);
       }
 
       if (this.twitterEnabled && logLevel < = this.twitterLogLevel)
       {
           Twitter twitter = new Twitter(this.twitterUserName, this.twitterPassword);
           twitter.Status.Update(tweet);
       }
}

That’s all it took. Two lines of actual code to implement the status update using Twitterizer.

Is an application that tweets all that useful? Probably not. It was, however, fun to make it all work.