Первый фоллен на хелле (wildkin) wrote in changelog,
Первый фоллен на хелле
wildkin
changelog

[ljcom] r9912: LJSUP-7679 Twitter optimization

Committer: dnikolaev
LJSUP-7679 Twitter optimization

U   trunk/cgi-bin/LJ/Client/Twitter.pm
Modified: trunk/cgi-bin/LJ/Client/Twitter.pm
===================================================================
--- trunk/cgi-bin/LJ/Client/Twitter.pm	2011-01-14 04:35:28 UTC (rev 9911)
+++ trunk/cgi-bin/LJ/Client/Twitter.pm	2011-01-14 09:14:29 UTC (rev 9912)
@@ -209,14 +209,19 @@
 
     if ($u) {
         $opts{'access_token'} = {
-            'public' => $u->prop('twitter_access_token'),
-            'secret' => $u->prop('twitter_access_token_secret'),
+            'public' => $u->prop('twitter_access_token') || undef,
+            'secret' => $u->prop('twitter_access_token_secret') || undef,
         };
     }
 
     my $access_token = $opts{'access_token'};
     die 'access token not provided' unless $access_token;
 
+    unless ($access_token->{'public'}) {
+        warn "User " . $u->username . " has no twitter access token\n";
+        return undef;
+    }
+
     my $http_method = $opts{'http_method'} || 'GET';
     die 'invalid HTTP method' unless $http_method =~ /^(?:GET|POST)$/;
 
@@ -281,7 +286,9 @@
         $res = $ua->post( $request_url, $post_params );
     }
 
-    unless ($res->is_success) {
+    if ($res->is_success) {
+        return LJ::JSON->from_json($res->content);
+    } else {
         if ($res->code eq '401' && $u) {
             warn "twitter error: 401 Unauthorized\n";
 
@@ -307,9 +314,8 @@
             warn 'twitter connectivity error: ' . Data::Dumper::Dumper($res);
             die "twitter connectivity error";
         }
+        return undef;
     }
-
-    return LJ::JSON->from_json($res->content);
 }
 
 sub store_request_token {

Tags: ljcom, pm, wildkin
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 1 comment