My Name Is Rich

Icon

Using Bit.ly from Flash

So, I recently wanted to play around with the Bit.ly API and use it in flash. I decided it would be best to write up a nice little helper class. The usage for this is pretty simple and right now it only implements two of the API methods, shorten and expand. I’ll work on the other calls but I figured these were the most widely used.

1
2
3
4
5
6
7
8
9
10
11
12
import com.imperez.apis.bitly.Bitly;
import com.imperez.apis.bitly.events.BitlyEvent;
 
var bitly:Bitly = new Bitly("bitly username", "user api_key");
bitly.addEventListener(BitlyEvent.SHORTEN, this._shorten);
bitly.shorten("http://www.google.com/");
 
function _shorten(event:BitlyEvent):void
{
	var shortURL:String = event.currentTarget.shortURL;
	trace(shortURL); //http://bit.ly/4BSxf
}

As you can see from the code above it’s pretty simple. Pass in your username and api key in the constructor and then listen for the BitlyEvent.SHORTEN event. Make your call along passing your long url and you are set to go. I wanted to keep this is as easy to use as possible. I also wanted to make it so you wouldn’t need to have to parse xml in order to get this information.

And that’s it. Nothing more to see but sweet, sweet code . If you’re interested I have it up on my repository located here. There are still some bug fixes and general clean up to on top of further implementation but I would say it’s a good start.

About Me

My name is Richard Perez and I am an alumni of Rochester Institute of Technology. This is my personal blog where I like to post about anything that insterests me. Which can range from design, programming, family, and tech gadgets. Currently, I work at HZDG in New York City as an Interactive Flash Developer. I love design and combining that with flash makes my day ten times better.

Categories

Calendar

September 2010
M T W T F S S
« Mar    
 12345
6789101112
13141516171819
20212223242526
27282930