Bit.ly Package

The Morfik bit.ly package contains an interface to the bit.ly API to create shortened URLs, primarily used for saving characters in Tweets, blogs and emails.


package-view.png
package-down.png


A quick walkthrough

To use the Morfik bit.ly package simply add the package to the project by utilizing the “Used Packages” command on the project ribbon (see Figure 1 Used Packages Command), or simply drag the package file onto the application main client area.


security-fig1.png
Figure 1: Used Packages Command


To use the API, you will need an account (free) from bit.ly. Signing up will provide you with a Login and a Key, both of which are required.

Once the package has been added to your application, it is simple to use. When you want to create a shortened URL, just add mfk_BitLy to the Uses clause and write code similar to that below:


FX Code

Procedure Form1.GetShortUrl(Event: TDOMEvent);
Var ShortenUrl: TShortenUrl;
Begin
    ShortenUrl := TShortenUrl.Create;
    ShortenUrl.LongUrl := TextEdit1.Text;
    ShortenUrl.bitLogin := 'My_bitly_Login';
    ShortenUrl.bitKey := 'My_bitly_key';
    ShortenUrl.Callback := GetMethodPointer(Self, @MakeShortUrlCallback);
    ShortenUrl.MakeShort;
    ShortenUrl.Free;
End;	
Procedure Form1.MakeShortUrlCallback(s1, s2 : string; Data : TDataShort);
Begin
    If s1 = '200' Then
        TextEdit3.Text := Data.url
    Else
        TextEdit3.Text := 'Unknown url format';
End;


The newly created short Url will be added to your collection of Urls registered at bit.ly and can be monitored through that site.

You can also find the long Url for any short Url by using the ShortUrl property of the TShortUrl class:

FX Code

ShortenUrl.ShortUrl := TextEdit3.Text;


and calling the MakeLong method after creating a MakeLongUrlCallback procedure.


FX Code

Procedure Form1.MakeLongUrlCallback (s1, s2: string; Data: TDataLong);
Begin
    If s1 = '200' Then
        ShowMessage(Data.long_url)
    Else
        ShowMessage('Unknown url format');
End;


See Also

Back to top