wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[ljcom] r11543: LJSV-2037: Logging twitter digest activi...

Committer: wisest-owl
LJSV-2037: Logging twitter digest activity

U   trunk/cgi-bin/LJ/Client/Twitter.pm
U   trunk/cgi-bin/LJ/TwitterDigest.pm
Modified: trunk/cgi-bin/LJ/Client/Twitter.pm
===================================================================
--- trunk/cgi-bin/LJ/Client/Twitter.pm	2012-02-29 12:13:22 UTC (rev 11542)
+++ trunk/cgi-bin/LJ/Client/Twitter.pm	2012-02-29 12:46:23 UTC (rev 11543)
@@ -292,7 +292,8 @@
     } else {
         if ($res->code eq '401' && $u) {
             warn "twitter error: 401 Unauthorized\n";
-            $u->log_event ("twitter_failed", { text => '401 Unauthorized' } );
+            $u->log_event ("twitter_failed", { text => '401 Unauthorized' } )
+                if $opts{'call_from_digest'};
 
             $u->clear_prop($_)
                 foreach qw(
@@ -316,12 +317,14 @@
             # 50x codes (which indicate a server error) only get
             # printed if we have an environment flag on
             if ( $ENV{'LJ_DEBUG_TWITTER_CONNECTIVITY'} ) {
-                $u->log_event ("twitter_failed", { text => $res->status_line } );
+                $u->log_event ("twitter_failed", { text => $res->status_line } )
+                    if $opts{'call_from_digest'};
                 die "twitter connectivity error: " . $res->status_line;
             }
             return;
         } else {
-            $u->log_event ("twitter_failed", { text => $res->status_line } );
+            $u->log_event ("twitter_failed", { text => $res->status_line } )
+                if $opts{'call_from_digest'};
             die "twitter connectivity error: " . $res->status_line;
         }
         return undef;
@@ -449,8 +452,10 @@
 }
 
 sub user_last_tweets {
-    my ($class, $u) = @_;
+    my ($class, $u, $opts) = @_;
 
+    $opts ||= {};
+
     unless ( LJ::Client::Twitter->get_user_access_token($u) ) {
         # if they don't have a token, return an empty result
         return [];
@@ -462,6 +467,7 @@
         'http_method' => 'GET',
         'params' => { 'count'       => $LJ::TWITTER_RECENT_FEED_DEPTH,
                       'include_rts' => 1, }, # with retweets
+        %$opts,
     );
 
     return [ map { LJ::Client::Twitter::Tweet->from_hash($_) } 
@@ -472,8 +478,8 @@
 sub get_userinfo {
     my ($class, %opts) = @_;
 
-    my $token = $opts{'access_token'};
-    my $u     = $opts{'user'};
+    my $token = delete $opts{'access_token'};
+    my $u     = delete $opts{'user'};
 
     if ($u) {
         unless ( LJ::Client::Twitter->get_user_access_token($u) ) {
@@ -486,6 +492,7 @@
         'api_method'    => 'account/verify_credentials',
         'access_token'  => $token,
         'user'          => $u,
+        %opts,
     );
 
     my $twu = LJ::Client::Twitter::User->from_hash($userdata);

Modified: trunk/cgi-bin/LJ/TwitterDigest.pm
===================================================================
--- trunk/cgi-bin/LJ/TwitterDigest.pm	2012-02-29 12:13:22 UTC (rev 11542)
+++ trunk/cgi-bin/LJ/TwitterDigest.pm	2012-02-29 12:46:23 UTC (rev 11543)
@@ -212,7 +212,7 @@
 sub post_digest {
     my ($class, $u) = @_;
 
-    my $twu = LJ::Client::Twitter->get_userinfo( 'user' => $u );
+    my $twu = LJ::Client::Twitter->get_userinfo( 'user' => $u, 'call_from_digest' => 1 );
 
     return if ! $twu || $twu->protected;
 
@@ -235,7 +235,7 @@
     # this way, ML knows which language to use
     LJ::set_remote($u);
 
-    my $tweets = LJ::Client::Twitter->user_last_tweets($u);
+    my $tweets = LJ::Client::Twitter->user_last_tweets($u, { 'call_from_digest' => 1 });
     unless (@$tweets) {
         $u->log_event ("twitter_skipped", { text => "No tweets to import" });
         return;

Tags: ljcom, pm, wisest-owl
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 

  • 0 comments