WWW::Shorten::Bitly - Interface to shortening URLs using "/bit.ly" in http::
$Revision: 78 $
WWW::Shorten::Bitly provides an easy interface for shortening URLs using http://bit.ly. In addition to shortening URLs, you can pull statistics that bit.ly gathers regarding each shortened WWW::Shorten::Bitly uses XML::Simple to convert the xml response for the meta info and click stats to create a hashref of the results.
WWW::Shorten::Bitly provides two interfaces. The first is the common makeashorterlink and makealongerlink that WWW::Shorten provides. However, due to the way the bit.ly API works, additional arguments are required. The second provides a better way of retrieving additional information and statistics about a bit.ly URL.
makeashorterlink
makealongerlink
use WWW::Shorten::Bitly; my $url = "http://www.example.com"; my $tmp = makeashorterlink($url, 'MY_BITLY_USERNAME', 'MY_BITLY_API_KEY'); my $tmp1 = makealongerlink($tmp, 'MY_BITLY_USERNAME', 'MY_BITLY_API_KEY');
or
use WWW::Shorten::Bitly; my $url = "http://www.example.com"; my $bitly = WWW::Shorten::Bitly->new(URL => $url, USER => "my_user_id", APIKEY => "my_api_key"); $bitly->shorten(URL => $url); print "shortened URL is $bitly->{bitlyurl}\n"; $bitly->expand(URL => $bitly->{bitlyurl}); print "expanded/original URL is $bitly->{longurl}\n"; my $info = $bitly->info(); say "City referred to is " . $info->{calais}->{city}->{item}; say "Companies referred to are " . $info->{calais}->{company}->{item}[0] . "and " . $info->{calais}->{company}->{item}[1]; say "Title of the page is " . $info->{htmlTitle}; my $clicks = $bitly->clicks(); say "Total number of clicks received: " . $clicks->{clicks}; say "Total number of direct clicks received are: " . ${$clicks->{referrers}->{nodeKeyVal}[0]}->{direct}
Create a new bit.ly object using your bit.ly user id and bit.ly api key.
my $bitly = WWW::Shorten::Bitly->new(URL => "http://www.example.com/this_is_one_example.html", USER => "bitly_user_id", APIKEY => "bitly_api_key");
The function makeashorterlink will call the bit.ly API site passing it your long URL and will return the shorter bit.ly version.
bit.ly requires the use of a user id and API key to shorten links.
The function makealongerlink does the reverse. makealongerlink will accept as an argument either the full bit.ly URL or just the bit.ly identifier. bit.ly requires the use of a user name and API Key when using the API.
If anything goes wrong, then the function will return undef.
undef
Shorten a URL using http://bit.ly. Calling the shorten method will return the shortened URL but will also store it in bit.ly object until the next call is made.
my $url = "http://www.example.com"; my $shortstuff = $bitly->shorten(URL => $url); print "biturl is " . $bitly->{bitlyurl} . "\n"; or print "biturl is $shortstuff\n";
Expands a shortened bit.ly URL to the original long URL.
Get info about a shortened bit.ly URL. By default, the method will use the value that's stored in $bitly->{bitlyurl}. To be sure you're getting info on the correct URL, it's a good idea to set this value before getting any info on it.
$bitly->{bitlyurl} = "http://bit.ly/jmv6"; my $info = $bitly->info(); say "City referred to is " . $info->{calais}->{city}->{item}; say "Companies referred to are " . $info->{calais}->{company}->{item}[0] . "and " . $info->{calais}->{company}->{item}[1]; say "Title of the page is " . $info->{htmlTitle};
Get click thru information for a shortened bit.ly URL. By default, the method will use the value that's stored in $bitly->{bitlyurl}. To be sure you're getting info on the correct URL, it's a good idea to set this value before getting any info on it.
$bitly->{bitlyurl} = "http://bit.ly/jmv6"; my $clicks = $bitly->clicks(); say "Total number of clicks received: " . $clicks->{clicks}; say "Total number of direct clicks received are: " . ${$clicks->{referrers}->{nodeKeyVal}[0]}->{direct}
Gets the module version number
Pankaj Jain, <perl at teknatus.com>
<perl at teknatus.com>
Please report any bugs or feature requests to bug-www-shorten-bitly at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Shorten-Bitly. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-www-shorten-bitly at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc WWW::Shorten::Bitly
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Shorten-Bitly
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/WWW-Shorten-Bitly
CPAN Ratings
http://cpanratings.perl.org/d/WWW-Shorten-Bitly
Search CPAN
http://search.cpan.org/dist/WWW-Shorten-Bitly/
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
perl, WWW::Shorten.
To install WWW::Shorten::Bitly, copy and paste the appropriate command in to your terminal.
cpanm
cpanm WWW::Shorten::Bitly
CPAN shell
perl -MCPAN -e shell install WWW::Shorten::Bitly
For more information on module installation, please visit the detailed CPAN module installation guide.