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
The 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 command line interface
For the hacker you, Bitlyfier can also be used as a command line tool. These are the options:
- bitlyfier [OPTION…] – Bitlyfier, URL shortener/expander
- Help Options:
- -h, –help Show help options
- Application Options:
- -e, –expand Expands the given URL
- -s, –shorten Shortens the given URL
- -n, –no-gui Sets the application in command line mode
- -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
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:
- // main.vala
- // Compile: valac –pkg gee-1.0 –pkg json-glib-1.0 –pkg libsoup-2.4 -o main
int main(string argv)
- Bitly.Api api = new Bitly.Api(“username”, “R_the_api_key”);
- Bitly.Response response = api.shorten(“http://domain.com/the/long/url”);
- stdout.printf(“Short URL: %s\n”, response.get_string(“shortUrl”));
- response = api.stats(“A2ma2z”);
- stdout.printf(“Clicks: %d\n”, response.get_integer(“clicks”));
- return 0;
More about the Bit.ly API and what the API methods do can be read about at http://bit.ly/6HIqjS.
The development sources of this application is available at Bitlyfier at Github. The current stable release can be found at the Download page.