madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[ljcom] r11763: LJSUP-11858: Vkontakte integration

Committer: sbelyaev
LJSUP-11858: Vkontakte integration
U   trunk/cgi-bin/LJ/Client/Vkontakte.pm
U   trunk/cgi-bin/LJ/Identity/Vkontakte.pm
U   trunk/cgi-bin/LJ/Worker/Repost/EntryToVkontakte.pm
U   trunk/htdocs/manage/settings/vkontakte.bml
Modified: trunk/cgi-bin/LJ/Client/Vkontakte.pm
===================================================================
--- trunk/cgi-bin/LJ/Client/Vkontakte.pm	2012-04-23 14:15:28 UTC (rev 11762)
+++ trunk/cgi-bin/LJ/Client/Vkontakte.pm	2012-04-23 14:19:17 UTC (rev 11763)
@@ -123,17 +123,7 @@
         die 'vkontakte connectivity error';
     }
 
-    my $params_returned = LJ::JSON->from_json( $res->content );
-
-    if ( $params_returned->{'error'} ) {
-        warn 'vkontakte connectivity error: '
-           . $params_returned->{'error'}->{'error_code'} . ' / '
-           . $params_returned->{'error'}->{'error_msg'};
-
-        die 'vkontakte connectivity error';
-    }
-
-    return $params_returned->{'response'};
+    return LJ::JSON->from_json( $res->content );
 }
 
 sub get_useragent {

Modified: trunk/cgi-bin/LJ/Identity/Vkontakte.pm
===================================================================
--- trunk/cgi-bin/LJ/Identity/Vkontakte.pm	2012-04-23 14:15:28 UTC (rev 11762)
+++ trunk/cgi-bin/LJ/Identity/Vkontakte.pm	2012-04-23 14:19:17 UTC (rev 11763)
@@ -54,7 +54,7 @@
             'access_token' => $token,
         } );
 
-        $userdata = $res->[0];
+        $userdata = (ref $res eq 'ARRAY') ? $res->[0] : $res;
     }
 
     ## INITIALIZE USER PROFILE

Modified: trunk/cgi-bin/LJ/Worker/Repost/EntryToVkontakte.pm
===================================================================
--- trunk/cgi-bin/LJ/Worker/Repost/EntryToVkontakte.pm	2012-04-23 14:15:28 UTC (rev 11762)
+++ trunk/cgi-bin/LJ/Worker/Repost/EntryToVkontakte.pm	2012-04-23 14:19:17 UTC (rev 11763)
@@ -34,12 +34,36 @@
 
     my $status = "$title $short_url";
 
-    LJ::Client::Vkontakte->call( 'wall.post', {
+    my $result = LJ::Client::Vkontakte->call( 'wall.post', {
         'message' =>  $status,
         'access_token' => $poster->prop('vkontakte_access_token'),
     } );
 
+    $class->process_result($poster, $result);
     return $job->completed;
 }
 
+sub process_result {
+    my ($class, $poster, $result) = @_;
+
+    my $error = $result->{error};
+
+    if (!$error) {
+        return;
+    }
+
+    my $error_string = "Repost entry to VK error: " .$error->{'error_code'} .
+                        " / " . $error->{'error_msg'};
+
+    __log_statushistory($class, $poster, $error_string);
+}
+
+sub __log_statushistory {
+    my ( $class, $poster, $notes ) = @_;
+
+    my $sys_uid   = LJ::get_userid("system");
+    LJ::statushistory_add($poster->userid, $sys_uid, 'vk_repost_entry', $notes);
+}
+
 1;
+

Modified: trunk/htdocs/manage/settings/vkontakte.bml
===================================================================
--- trunk/htdocs/manage/settings/vkontakte.bml	2012-04-23 14:15:28 UTC (rev 11762)
+++ trunk/htdocs/manage/settings/vkontakte.bml	2012-04-23 14:19:17 UTC (rev 11763)
@@ -39,7 +39,10 @@
     if ($act eq 'connect') {
         my $vk_code = LJ::Request->get_param('code');
 
-        unless ($vk_code) {
+        unless ($vk_code) {  
+            my $sys_uid   = LJ::get_userid("system");
+            LJ::statushistory_add($u->userid, $sys_uid, 'vk_connect', 'Connection to vkontakte is broken');
+
             return LJ::Request->redirect($settings_page)
                 if LJ::Request->get_param('error_reason') eq 'user_denied';
 
@@ -62,7 +65,7 @@
                 'access_token' => $vk_token,
             } );
 
-        $vk_userdata = $vk_userdata->[0] || $vk_userdata;
+        $vk_userdata = (ref $vk_userdata eq 'ARRAY' ) ? $vk_userdata->[0] : $vk_userdata;
         my $name = $vk_userdata->{'first_name'} . ' '
                  . $vk_userdata->{'last_name'} ;
 
@@ -73,6 +76,9 @@
         $u->set_prop( 'vkontakte_name'         => $name );
         $u->set_prop( 'vkontakte_link'         => $link );
 
+        my $sys_uid   = LJ::get_userid("system");
+        LJ::statushistory_add($u->userid, $sys_uid, 'vk_connect', 'User is connected to vk successful');
+
         return LJ::Request->redirect($settings_page);
     } else {
         # $act eq 'disconnect'
@@ -87,6 +93,9 @@
             foreach qw( vkontakte_userid vkontakte_access_token
                         vkontakte_name vkontakte_link );
 
+        my $sys_uid   = LJ::get_userid("system");
+        LJ::statushistory_add($u->userid, $sys_uid, 'vk_connect', 'User is disconnected from vkontakte');
+
         return LJ::Request->redirect($settings_page);
     }
 }

Tags: bml, ljcom, madeon, pm, sbelyaev
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