v2.4.1beta - Remove use of the Net::Identica object, using 'identica => 1' instead...
[twirssi-net-twitter-lite.git] / twirssi.pl
index 001b18240dadc2e37bb9844814f2920b55395a4d..0c433cd687527540918a1eaa86f1bfc8dbc61ebd 100644 (file)
@@ -8,11 +8,12 @@ use LWP::Simple;
 use Data::Dumper;
 use Encode;
 use POSIX qw/:sys_wait_h/;
+use Net::Twitter qw/3.05/;
 $Data::Dumper::Indent = 1;
 
 use vars qw($VERSION %IRSSI);
 
-$VERSION = "2.4.0beta";
+$VERSION = "2.4.1beta";
 %IRSSI   = (
     authors     => 'Dan Boger',
     contact     => 'zigdon@gmail.com',
@@ -21,7 +22,7 @@ $VERSION = "2.4.0beta";
       . 'Can optionally set your bitlbee /away message to same',
     license => 'GNU GPL v2',
     url     => 'http://twirssi.com',
-    changed => '$Date: 2009-08-07 01:24:53 -0700 (Fri, 07 Aug 2009) $',
+    changed => 'Fri Jan 22 14:40:48 PST 2010',
 );
 
 my $window;
@@ -430,7 +431,9 @@ sub cmd_logout {
     return unless $data = &valid_username($data);
 
     &notice("Logging out $data...");
-    $twits{$data}->end_session();
+    eval {
+        $twits{$data}->end_session();
+    };
     delete $twits{$data};
     undef $twit;
     if ( keys %twits ) {
@@ -507,18 +510,12 @@ sub cmd_login {
     }
     $defservice = $service = ucfirst lc $service;
 
-    print "Loading Net::$service" if &debug;
-    eval "use Net::$service 3.05";
-    if ($@) {
-        &notice(
-            "Failed to load Net::$service when trying to log in as $user: $@");
-        return;
-    }
-
-    if ( Irssi::settings_get_bool("twirssi_use_oauth") ) {
+    if ( $service eq 'Twitter' and
+         Irssi::settings_get_bool("twirssi_use_oauth") ) {
         print "Attempting OAuth for $user\@$service" if &debug;
         eval {
-            $twit = "Net::$service"->new(
+            $twit = Net::Twitter->new(
+                $service eq 'Identica' ? ( identica => 1 ) : (),
                 traits       => [ 'API::REST', 'OAuth' ],
                 consumer_key => 'BZVAvBma4GxdiRwXIvbnw',
                 consumer_secret => '0T5kahwLyb34vciGZsgkA9lsjtGCQ05vxVE2APXM',
@@ -541,17 +538,28 @@ sub cmd_login {
             }
 
             unless ( $twit->authorized ) {
+                my $url;
+                eval {
+                    $url = $twit->get_authorization_url;
+                };
+
+                if ($@) {
+                    &notice("ERROR: Failed to get OAuth authorization_url.  Try again later.");
+                    return;
+                }
+
                 &notice("Twirssi not autorized to access $service for $user.");
                 &notice("Please authorize at the following url, then enter the pin ");
-                &notice("supplied with /twirssi_oath $user\@$service <pin>");
-                &notice($twit->get_authorization_url);
+                &notice("supplied with /twirssi_oauth $user\@$service <pin>");
+                &notice($url);
 
                 $oauth{pending}{"$user\@$service"} = $twit;
                 return;
             }
         }
     } else { 
-        $twit = "Net::$service"->new(
+        $twit = Net::Twitter->new(
+            $service eq 'Identica' ? ( identica => 1 ) : (),
             username => $user,
             password => $pass,
             source   => "twirssi",
@@ -560,7 +568,7 @@ sub cmd_login {
     }
 
     unless ($twit) {
-        &notice("Failed to create Net::$service object!  Aborting.");
+        &notice("Failed to create object!  Aborting.");
         return;
     }
 
@@ -1043,11 +1051,13 @@ sub get_updates {
 sub do_updates {
     my ( $fh, $username, $obj, $cache ) = @_;
 
-    my $rate_limit = $obj->rate_limit_status();
-    if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
-        &notice("Rate limit exceeded for $username");
-        return undef;
-    }
+    eval {
+        my $rate_limit = $obj->rate_limit_status();
+        if ( $rate_limit and $rate_limit->{remaining_hits} < 1 ) {
+            &notice("Rate limit exceeded for $username");
+            return undef;
+        }
+    };
 
     print scalar localtime, " - Polling for updates for $username" if &debug;
     my $tweets;