]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Made /api/account/verify_credentials.format return an extended user object. Updates...
authorZach Copley <zach@controlyourself.ca>
Thu, 5 Mar 2009 00:17:40 +0000 (16:17 -0800)
committerZach Copley <zach@controlyourself.ca>
Thu, 5 Mar 2009 00:17:40 +0000 (16:17 -0800)
actions/twitapiaccount.php
actions/twitapiusers.php
lib/router.php
lib/twitterapi.php

index c19cd370d927f2b2bb6e8f5bf044f328f5e12926..68a18cb57b43c87d7a9e4e6090f5b5b1df019a9a 100644 (file)
@@ -23,22 +23,24 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
 
 class TwitapiaccountAction extends TwitterapiAction
 {
-
     function verify_credentials($args, $apidata)
     {
-        if ($apidata['content-type'] == 'xml') {
-            header('Content-Type: application/xml; charset=utf-8');
-            print '<authorized>true</authorized>';
-        } elseif ($apidata['content-type'] == 'json') {
-            header('Content-Type: application/json; charset=utf-8');
-            print '{"authorized":true}';
-        } else {
+        parent::handle($args);
+
+        switch ($apidata['content-type']) {
+        case 'xml':
+        case 'json':
+            $action_obj = new TwitapiusersAction();
+            $action_obj->prepare($args);
+            call_user_func(array($action_obj, 'show'), $args, $apidata);
+            break;
+        default:
             header('Content-Type: text/html; charset=utf-8');
             print 'Authorized';
         }
     }
 
-    function end_session($args, $apidata)
+   function end_session($args, $apidata)
     {
         parent::handle($args);
         $this->serverError(_('API method under construction.'), $code=501);
index 8f16e56131e87f3ec2f2173fa4bd275d8dda0980..2894b7486dd31372fe63ca76ca41ed99821922b4 100644 (file)
@@ -25,25 +25,29 @@ class TwitapiusersAction extends TwitterapiAction
 {
 
     function show($args, $apidata)
-    {
+    {        
         parent::handle($args);
 
-        if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+        if (!in_array($apidata['content-type'], array('xml', 'json'))) {            
             $this->clientError(_('API method not found!'), $code = 404);
             return;
         }
-
- $this->auth_user = $apidata['user'];
+                
                $user = null;
                $email = $this->arg('email');
+               $user_id = $this->arg('user_id');
 
                if ($email) {
                        $user = User::staticGet('email', $email);
+               } elseif ($user_id) {
+                       $user = $this->get_user($user_id);  
                } elseif (isset($apidata['api_arg'])) {
                        $user = $this->get_user($apidata['api_arg']);
-               }
-
-               if (!$user) {
+           } elseif (isset($apidata['user'])) {
+               $user = $apidata['user'];
+           }
+       
+               if (!$user) {               
                        // XXX: Twitter returns a random(?) user instead of throwing and err! -- Zach
                        $this->client_error(_('Not found.'), 404, $apidata['content-type']);
                        return;
@@ -74,9 +78,12 @@ class TwitapiusersAction extends TwitterapiAction
 
                // Other fields Twitter sends...
                $twitter_user['profile_background_color'] = '';
+               $twitter_user['profile_background_image_url'] = '';
                $twitter_user['profile_text_color'] = '';
                $twitter_user['profile_link_color'] = '';
                $twitter_user['profile_sidebar_fill_color'] = '';
+        $twitter_user['profile_sidebar_border_color'] = '';
+        $twitter_user['profile_background_tile'] = 'false';
 
                $faves = DB_DataObject::factory('fave');
                $faves->user_id = $user->id;
@@ -94,18 +101,27 @@ class TwitapiusersAction extends TwitterapiAction
                $twitter_user['utc_offset'] = $t->format('Z');
                $twitter_user['time_zone'] = $timezone;
 
-               if (isset($this->auth_user)) {
+               if (isset($apidata['user'])) {
 
-                       if ($this->auth_user->isSubscribed($profile)) {
+                       if ($apidata['user']->isSubscribed($profile)) {
                                $twitter_user['following'] = 'true';
                        } else {
                                $twitter_user['following'] = 'false';
                        }
-
-                       // Not implemented yet
-                       $twitter_user['notifications'] = 'false';
-               }
-
+            
+            // Notifications on?
+                   $sub = Subscription::pkeyGet(array('subscriber' =>
+                       $apidata['user']->id, 'subscribed' => $profile->id));
+            
+            if ($sub) {
+                if ($sub->jabber || $sub->sms) {
+                    $twitter_user['notifications'] = 'true';
+                } else {
+                    $twitter_user['notifications'] = 'false';
+                }
+            }
+        }
+        
                if ($apidata['content-type'] == 'xml') {
                        $this->init_document('xml');
                        $this->show_twitter_xml_user($twitter_user);
@@ -114,7 +130,13 @@ class TwitapiusersAction extends TwitterapiAction
                        $this->init_document('json');
                        $this->show_json_objects($twitter_user);
                        $this->end_document('json');
-               }
+               } else {
+                   
+                   // This is in case 'show' was called via /account/verify_credentials
+                   // without a format (xml or json).
+            header('Content-Type: text/html; charset=utf-8');
+            print 'Authorized';
+        }
 
        }
 }
index 4b70c01505ec3163454db89f01ab8a498a270a64..a36cd2691ee6886b46a04ad722ddbd8f6a2b1caa 100644 (file)
@@ -228,14 +228,15 @@ class Router
 
         // users
 
-        $m->connect('api/users/show/:argument',
+        $m->connect('api/users/:method/:argument',
                     array('action' => 'api',
-                          'apiaction' => 'users'));
+                          'apiaction' => 'users'), 
+                    array('method' => 'show(\.(xml|json))?'));
 
         $m->connect('api/users/:method',
                     array('action' => 'api',
                           'apiaction' => 'users'),
-                    array('method' => 'show(\.(xml|json|atom|rss))?'));
+                    array('method' => 'show(\.(xml|json))?'));
 
         // direct messages
 
@@ -304,11 +305,11 @@ class Router
         }
 
         // account
-
+        
         $m->connect('api/account/:method',
                     array('action' => 'api',
                           'apiaction' => 'account'));
-
+                          
         // favorites
 
         $m->connect('api/favorites/:method/:argument',
index a4d183fcd05e3c3739185755fc7e4be40a5d49ea..74f265cbb9fcde99f9153baaaa473e269213011a 100644 (file)
@@ -60,20 +60,34 @@ class TwitterapiAction extends Action
 
     function twitter_status_array($notice, $include_user=true)
     {
-
         $profile = $notice->getProfile();
 
         $twitter_status = array();
         $twitter_status['text'] = $notice->content;
         $twitter_status['truncated'] = 'false'; # Not possible on Laconica
         $twitter_status['created_at'] = $this->date_twitter($notice->created);
-        $twitter_status['in_reply_to_status_id'] = ($notice->reply_to) ? intval($notice->reply_to) : null;
+        $twitter_status['in_reply_to_status_id'] = ($notice->reply_to) ?
+            intval($notice->reply_to) : null;
         $twitter_status['source'] = $this->source_link($notice->source);
         $twitter_status['id'] = intval($notice->id);
-        $twitter_status['in_reply_to_user_id'] = ($notice->reply_to) ? $this->replier_by_reply(intval($notice->reply_to)) : null;
+
+        $replier_profile = null;
+
+        if ($notice->reply_to) {
+            $reply = Notice::staticGet(intval($notice->reply_to));
+            if ($reply) {
+                $replier_profile = $reply->getProfile();
+            }
+        }
+
+        $twitter_status['in_reply_to_user_id'] =
+            ($replier_profile) ? intval($replier_profile->id) : null;
+        $twitter_status['in_reply_to_screen_name'] =
+            ($replier_profile) ? $replier_profile->nickname : null;
 
         if (isset($this->auth_user)) {
-            $twitter_status['favorited'] = ($this->auth_user->hasFave($notice)) ? 'true' : 'false';
+            $twitter_status['favorited'] = 
+                ($this->auth_user->hasFave($notice)) ? 'true' : 'false';
         } else {
             $twitter_status['favorited'] = 'false';
         }
@@ -137,7 +151,6 @@ class TwitterapiAction extends Action
 
     function twitter_dmsg_array($message)
     {
-
         $twitter_dm = array();
 
         $from_profile = $message->getFrom();
@@ -386,23 +399,7 @@ class TwitterapiAction extends Action
         $t = strtotime($dt);
         return date("D M d G:i:s O Y", $t);
     }
-
-    function replier_by_reply($reply_id)
-    {
-        $notice = Notice::staticGet($reply_id);
-        if ($notice) {
-            $profile = $notice->getProfile();
-            if ($profile) {
-                return intval($profile->id);
-            } else {
-                common_debug('Can\'t find a profile for notice: ' . $notice->id, __FILE__);
-            }
-        } else {
-            common_debug("Can't get notice: $reply_id", __FILE__);
-        }
-        return null;
-    }
-
+    
     // XXX: Candidate for a general utility method somewhere?
     function count_subscriptions($profile)
     {