NAME
Twitter::Badge - Perl module that displays the current Twitter information of a user
SYNOPSIS
use Twitter::Badge;
# If you know the Twitter ID
my $id = 14512139; # define the Twitter ID
my $twitter = Twitter::Badge->new(id => $id); # create the object for that ID
$twitter->fetch(); # get information for this ID
# Display status
print $twitter->name.' says - '.$twitter->text."\n"; # display status
print $twitter->name.' has '.$twitter->followers_count." followers\n"; # display followers
# .. and so on
DESCRIPTION
Twitter::Badge is a class that retrieves the Twitter information for the user's ID or screen name.
METHODS
new(%args)
The method new(%args)
creates and returns a new Twitter::Badge
object. It takes either zero parameters or a hash containing at least one of the following:
KEY DEFAULT VALUE
=========== =============
id undef
screen_name undef
ua Mozilla/4.0
Summary of parameters
id
[OPTIONAL] This parameter is the Twitter ID, a number that is associated with the Twitter screen name.
screen_name
[OPTIONAL] This parameter is the Twitter screen name.
ua
[OPTIONAL] This parameter is the User-Agent string that is included in the request to Twitter. You can find a list of user-agent strings at http://aruljohn.com/ua/
fetch()
The method fetch()
fetches the following information from the user's corresponding Twitter account:
id
name
text
profile_image_url
followers_count
created_at
screen_name()
The method screen_name()
returns the screen_name value. If a parameter is passed into it, screen_name is set to that value.
This print the current Twitter screen name. print $twitter->screen_name
This will set the current Twitter screen name to 'aruljohn'. $twitter->screen_name('aruljohn');
ua()
The method ua()
returns the User-Agent string value. If a parameter is passed into it, ua is set to that value. You can find a list of User-Agent strings at http://aruljohn.com/ua/
name()
The method name()
returns the name
value retrieved from the account specified by the Twitter ID.
text()
The method text()
returns the text
value retrieved from the account specified by the Twitter ID.
profile_image_url()
The method profile_image_url()
returns the profile_image_url
value retrieved from the account specified by the Twitter ID
followers_count()
The method followers_count()
returns the followers_count
value retrieved from the account specified by the Twitter ID.
created_at()
The method created_at()
returns the created_at
value - the time the user updated his/her Twitter status.
EXAMPLES
Creating badge with no parameters
use Twitter::Badge;
my $twitter = Twitter::Badge->new(); # create an empty Twitter::Badge object
# Setting Twitter ID
$twitter->id(14512139); # setting ID to 14512139
$twitter->fetch(); # fetch Twitter info [with that Twitter ID]
print $twitter->name.' says: '.$twitter->text."\n";
print $twitter->name.' posted on '.$twitter->created_at."\n";
Creating badge with screen name as parameter
use Twitter::Badge;
# Create object with screen name
$twitter = Twitter::Badge->new(screen_name => 'justjul'); # create the object
$twitter->fetch();
print $twitter->name.' says: '.$twitter->text."\n";
print $twitter->name.' posted on '.$twitter->created_at."\n";
Creating badge with User-Agent as parameter
use Twitter::Badge;
# Create object with User-Agent
$twitter = Twitter::Badge->new(ua => 'Mozilla/6.0 (Twitterbot)'); # create the object
$twitter->screen_name('aruljohn');
$twitter->fetch();
print $twitter->name.' says: '.$twitter->text."\n";
print $twitter->name.' posted on '.$twitter->created_at."\n\n";
# Change screen name
$twitter->screen_name('justjul');
$twitter->fetch();
print $twitter->name.' says: '.$twitter->text."\n" if defined $twitter->text;
print $twitter->name.' posted on '.$twitter->created_at."\n" if defined $twitter->created_at;
print $twitter->name.' has '.$twitter->followers_count." followers\n\n" if defined $twitter->followers_count;
You can use the Data::Dumper module to check the contents of $twitter
at any time.
use Data::Dumper;
# other code goes here
print Dumper($twitter);
BUGS
There are no known bugs as of now.
But since the Twitter::Badge module is built on the XML file that Twitter generates - and this is bound to change over a period of time - some methods may stop working. When that happens, I will update this module. I will also update the module if Twitter includes more useful content in its XML file, and on user requests. My email address for contact is <arul@cpan.org>
SEE ALSO
Twitter API Documentation - http://groups.google.com/group/twitter-development-talk/web/api-documentation
AUTHOR
Arul John - http://aruljohn.com
COPYRIGHT AND LICENCE
Copyright (C) 2008 by Arul John
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.6.0 or, at your option, any later version of Perl you may have available.