LJ-Simple
view release on metacpan or search on metacpan
=item login
Logs into the LiveJournal system.
## Simplest logon method
my $lj = new LJ::Simple ( {
user => "username",
pass => "password",
} );
## Login with options
my $lj = new LJ::Simple ( {
user => "username",
pass => "password",
site => "hostname[:port]",
proxy => "hostname[:port]",
moods => 0 | 1,
pics => 0 | 1,
fast => 0 | 1,
} );
## Login by using login()
my $lj = LJ::Simple->login ( {
user => "username",
pass => "password",
site => "hostname[:port]",
proxy => "hostname[:port]",
moods => 0 | 1,
pics => 0 | 1,
fast => 0 | 1,
} );
Where:
user is the username to use
pass is the password associated with the username
site is the remote site to use
proxy is the HTTP proxy site to use; see below.
moods is set to 0 if we do not want to download the mood
list. Defaults to 1
pics is set to 0 if we do not want to download the user
picture information. Defaults to 1
fast is set to 1 if we want to perform a fast login.
Default is 0. See below for details of this.
Sites defined in C<site> or C<proxy> are a hostname with an
optional port number, separated by a C<:>, i.e.:
www.livejournal.com
www.livejournal.com:80
If C<site> is given C<undef> then the code assumes that you wish to
connect to C<www.livejournal.com:80>. If no port is given then port
C<80> is the default.
If C<proxy> is given C<undef> then the code will go directly to the
C<$site> unless a suitable environment variable is set.
If no port is given then port C<3128> is the default.
C<LJ::Simple> also supports the use the environment variables C<http_proxy>
and C<HTTP_PROXY> to store the HTTP proxy server details. The format of these
environment variables is assumed to be:
http://server[:port]/
Where C<server> is the name of the proxy server and the optional C<port> the
proxy server is on - port C<3128> is used if no port is explicitly given.
It should be noted that the proxy environment variables are B<only> checked
if the C<proxy> value is B<NOT> given to the C<LJ::Simple> object creation.
Thus to disable looking at the proxy environment variables use
C<proxy=E<gt>undef> in C<new()> or C<login()>.
If C<moods> is set to C<0> then the mood list will not be pulled from
the LiveJournal server and the following functions will be affected:
o moods() will always return undef (error)
o Setprop_current_mood_id() will not validate the mood_id
given to it.
o SetMood() will not attempt to convert the string it is
given into a given mood_id
If C<pics> is set to C<0> then the data on the user pictures will
not be pulled from the LiveJournal server and the following
functions will be affected:
o pictures() will always return undef (error)
o Setprop_picture_keyword() will blindly set the picture keyword
you give it - no validation will be performed.
o DefaultPicURL() will always return undef (error)
If C<fast> is set to C<1> then we will perform a I<fast login>. Essentially
all this does is to set up the various entries in the object hash which
the routines called after C<login> expect to see; at no time does it talk to
the LiveJournal servers. What this means is that it is very fast. However it
also means that when you use parts of the API which B<do> talk to the LiveJournal
servers its quite possible that you will get back errors associated with
authentication errors, network outages, I<etc>. In other words, in C<fast> mode
the login will always succeed, no matter what the state the LiveJournal
server we're talking is in. It should be noted that the following functions
will be affected if you enable the I<fast login>:
o moods() will always return undef (error)
o Setprop_current_mood_id() will not validate the mood_id
given to it
o SetMood() will not attempt to convert the string it is
given into a given mood_id
o pictures() will always return undef (error)
o Setprop_picture_keyword() will blindly set the picture keyword
you give it - no validation will be performed
o communities() will always return an empty list
o MemberOf() will always return 0 (error)
o UseJournal() will not validate the shared journal name you
give it
o groups() will always return undef (error)
o MapGroupToId() will always undef (error)
o MapIdToGroup() will always undef (error)
o SetProtectGroups() will always 0 (error)
o message() will always return undef (error)
o The key of "groups" in the list of hashes returned by
GetFriends() will always point to an empty list
$LJ::Simple::UTF=1;
Debug("UTF-8 support found");
} else {
$LJ::Simple::UTF=0;
Debug("No UTF-8 support found");
}
} elsif ($LJ::Simple::UTF) {
eval { require utf8 };
if (!$@) {
Debug("Using UTF-8 as requested");
} else {
$LJ::Simple::error="CODE: no UTF-8 support in your version of perl";
return undef;
}
}
eval { require Digest::MD5 };
if (!$@) {
Debug("Using Digest::MD5");
my $md5=Digest::MD5->new;
$md5->add($hr->{pass});
$self->{auth}->{hash}=$md5->hexdigest;
delete $self->{auth}->{pass};
(!defined $LJ::Simple::challenge) && ($LJ::Simple::challenge=1);
} else {
if ((defined $LJ::Simple::challenge)&&($LJ::Simple::challenge)) {
$LJ::Simple::error="Challenge-response auth requested, no Digest::MD5 found";
return undef;
}
$LJ::Simple::challenge=0;
}
if ((exists $hr->{site})&&(defined $hr->{site})&&($hr->{site} ne "")) {
my $site_port=$StdPort{http};
if ($hr->{site}=~/\s*(.*?):([0-9]+)\s*$/) {
$hr->{site} = $1;
$site_port = $2;
}
$self->{lj}={
host => $hr->{site},
port => $site_port,
}
} else {
$self->{lj}={
host => "www.livejournal.com",
port => $StdPort{http},
}
}
if ((exists $hr->{proxy})&&(defined $hr->{proxy})&&($hr->{proxy} ne "")) {
my $proxy_port=$StdPort{http_proxy};
if ($hr->{proxy}=~/\s*(.*?):([0-9]+)\s*$/) {
$hr->{proxy} = $1;
$proxy_port = $2;
}
$self->{proxy}={
host => $hr->{proxy},
port => $proxy_port,
};
} elsif (!exists $hr->{proxy}) {
# Getting proxy details from the environment; assumes that the proxy is
# given as http://site[:port]/
# The first matching env is used.
foreach my $env (qw( http_proxy HTTP_PROXY )) {
(exists $ENV{$env}) || next;
($ENV{$env}=~/^(?:http:\/\/)([^:\/]+)(?::([0-9]+)){0,1}/o) || next;
$self->{proxy}={
host => $1,
port => $2,
};
(defined $self->{proxy}->{port}) || ($self->{proxy}->{port}=$StdPort{http_proxy});
}
} else {
$self->{proxy}=undef;
}
# Set fastserver to 0 until we know better
$self->{fastserver}=0;
if ((exists $hr->{fast}) && ($hr->{fast}==1)) {
## Doing fast login, so return object
Debug(dump_hash($self,""));
return $self;
}
my $GetMoods=1;
if ((exists $hr->{moods}) && ($hr->{moods}==0)) {
$GetMoods=0;
}
my $GetPics=1;
if ((exists $hr->{pics}) && ($hr->{pics}==0)) {
$GetPics=0;
}
# Perform the actual login
$self->SendRequest("login", {
"moods" => $GetMoods,
"getpickws" => $GetPics,
"getpickurls" => $GetPics,
},undef) || return undef;
# Now see if we can set fastserver
if ( (exists $self->{request}->{lj}->{fastserver}) &&
($self->{request}->{lj}->{fastserver} == 1) ) {
$self->{fastserver}=1;
}
# Moods
$self->{moods}=undef;
$self->{mood_map}=undef;
# Shared access journals
$self->{access}=undef;
# User groups
$self->{groups}=undef;
# Images defined
$self->{pictures}=undef;
# Default URL
$self->{defaultpicurl}=undef;
# Message from LJ
$self->{message}=undef;
# Handle moods, etc.
my ($k,$v)=(undef,undef);
while(($k,$v) = each %{$self->{request}->{lj}}) {
( run in 1.728 second using v1.01-cache-2.11-cpan-71847e10f99 )