Bitlyfier – A Bit.ly client for GNOME

Published 7 January, 2010 in Applications , Linux , Programming - 0 Comments

Bitlyfier For those of us tweeting – or sharing web addresses in general – these long addresses with extensive query strings you wan’t to share isn’t too user friendly. So we have Bit.ly, among others, that lets you shorten a URL – or give it an alias if you like – and also gives you statistics on how many clicks it has and if it’s shared on Twitter and what not.

Since I’m on the quest of learning the programming language Vala I though why not making a Bit.ly desktop client for GNOME. So I did!

The desktop client

There’s really nothing extraordinary about it, in fact it’s quite simple. Put a long URL in the input field and hit “OK”. You’ll get the shortened URL back in the same input field.

NOTE! The screenshots is showing the Swedish translation but the interface is orginally in English.

Shortening a long URL
Shortening an URL with Bitlyfier

The shortened URL
The Bit.ly shortened URL

To use the application you will of course need a Bit.ly account. The first time Bitlyfier is launched it will ask for your Bit.ly account settings. Just fill in your username and API key (it’s found on your account page at http://bit.ly/account).

Bitlyfier account settings
The bitlyfier settings dialog

The command line interface

For the hacker you, Bitlyfier can also be used as a command line tool. These are the options:

11 lines of Plain text
  1. Usage:
  2. bitlyfier [OPTION…] – Bitlyfier, URL shortener/expander
  3. Help Options:
  4. -h, –help Show help options
  5. Application Options:
  6. -e, –expand Expands the given URL
  7. -s, –shorten Shortens the given URL
  8. -n, –no-gui Sets the application in command line mode
  9. -g, –gconf Invokes setting username and apikey

NOTE! You should quote the value of the ‘-s’ flag. If the URL to be shortened
contains a querystring with ampersands the URL will be truncated if it’s not
quoted.

So to shorten a long URL do like:

  user@machine:~$ bitlyfier -n -s "http://domain.com/long/url/to/shorten"

The Vala Bitly API classes

The Bitly API class I’ve written can of course be used standalone (it’s located in src/bitly.vala in the sources package downloadable below). Here’s an example of usage:

14 lines of Vala
  1. // main.vala
  2. // Compile: valac –pkg gee-1.0 –pkg json-glib-1.0 –pkg libsoup-2.4 -o main
  3. int main(string[] argv)
  4. {
  5. Bitly.Api api = new Bitly.Api(“username”, “R_the_api_key”);
  6. Bitly.Response response = api.shorten(“http://domain.com/the/long/url”);
  7. stdout.printf(“Short URL: %s\n”, response.get_string(“shortUrl”));
  8. response = api.stats(“A2ma2z”);
  9. stdout.printf(“Clicks: %d\n”, response.get_integer(“clicks”));
  10. return 0;
  11. }

More about the Bit.ly API and what the API methods do can be read about at http://bit.ly/6HIqjS.

The sources

The development sources of this application is available at Bitlyfier at Github. The current stable release can be found at the Download page.