]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Make other timeline API endpoints output Activity Streams JSON
authorZach Copley <zach@status.net>
Fri, 18 Feb 2011 23:43:40 +0000 (15:43 -0800)
committerZach Copley <zach@status.net>
Fri, 18 Feb 2011 23:43:40 +0000 (15:43 -0800)
actions/apitimelinefavorites.php
actions/apitimelinegroup.php
actions/apitimelinehome.php
actions/apitimelinementions.php
actions/apitimelinepublic.php
actions/apitimelineretweetedtome.php
actions/apitimelineretweetsofme.php
actions/apitimelinetag.php
actions/apitimelineuser.php
lib/router.php

index c952c4623870e91d882fc68d8f3721b14aeb4cc5..36fc3089f52d968ac6cd5edc9710fd4849133428 100644 (file)
@@ -169,6 +169,14 @@ class ApiTimelineFavoritesAction extends ApiBareAuthAction
         case 'json':
             $this->showJsonTimeline($this->notices);
             break;
+        case 'as':
+            header('Content-Type: application/json; charset=utf-8');
+            $doc = new ActivityStreamJSONDocument($this->auth_user);
+            $doc->setTitle($title);
+            $doc->addLink($link,'alternate', 'text/html');
+            $doc->addItemsFromNotices($this->notices);
+            $this->raw($doc->asString());
+            break;
         default:
             // TRANS: Client error displayed when trying to handle an unknown API method.
             $this->clientError(_('API method not found.'), $code = 404);
index e1bc102e450edc54b2df4fe35b25887a89dac310..3fc930fa08664630a01972676875ba7888d5a466 100644 (file)
@@ -106,6 +106,11 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction
 
         $self = $this->getSelfUri();
 
+        $link = common_local_url(
+            'ApiTimelineGroup',
+            array('nickname' => $this->group->nickname)
+        );
+
         switch($this->format) {
         case 'xml':
             $this->showXmlTimeline($this->notices);
@@ -123,24 +128,20 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction
             break;
         case 'atom':
             header('Content-Type: application/atom+xml; charset=utf-8');
-
-            try {
                 $atom->addEntryFromNotices($this->notices);
                 $this->raw($atom->getString());
-            } catch (Atom10FeedException $e) {
-                $this->serverError(
-                    // TRANS: Server error displayed when generating an Atom feed fails.
-                    // TRANS: %s is the error.
-                    sprintf(_('Could not generate feed for group - %s'),$e->getMessage()),
-                   400,
-                   $this->format
-                );
-                return;
-            }
             break;
         case 'json':
             $this->showJsonTimeline($this->notices);
             break;
+        case 'as':
+            header('Content-Type: application/json; charset=utf-8');
+            $doc = new ActivityStreamJSONDocument($this->auth_user);
+            $doc->setTitle($atom->title);
+            $doc->addLink($link, 'alternate', 'text/html');
+            $doc->addItemsFromNotices($this->notices);
+            $this->raw($doc->asString());
+            break;
         default:
             $this->clientError(
                 // TRANS: Client error displayed when trying to handle an unknown API method.
index 75a9f725808d0549d285f17d6f9d8819210ebc14..023c9698a1d9fbf45910793e4edf1cb18b8a1896 100644 (file)
@@ -168,6 +168,14 @@ class ApiTimelineHomeAction extends ApiBareAuthAction
         case 'json':
             $this->showJsonTimeline($this->notices);
             break;
+        case 'as':
+            header('Content-Type: application/json; charset=utf-8');
+            $doc = new ActivityStreamJSONDocument($this->auth_user);
+            $doc->setTitle($title);
+            $doc->addLink($link, 'alternate', 'text/html');
+            $doc->addItemsFromNotices($this->notices);
+            $this->raw($doc->asString());
+            break;
         default:
             // TRANS: Client error displayed when trying to handle an unknown API method.
             $this->clientError(_('API method not found.'), $code = 404);
index a9b6d0b3df14c4f8c0d24ed8f11719ea9771ed08..2857bd41ea3dc3e4933ed8170d4a3a6e3e7b28f0 100644 (file)
@@ -169,6 +169,14 @@ class ApiTimelineMentionsAction extends ApiBareAuthAction
         case 'json':
             $this->showJsonTimeline($this->notices);
             break;
+        case 'as':
+            header('Content-Type: application/json; charset=utf-8');
+            $doc = new ActivityStreamJSONDocument($this->auth_user);
+            $doc->setTitle($title);
+            $doc->addLink($link, 'alternate', 'text/html');
+            $doc->addItemsFromNotices($this->notices);
+            $this->raw($doc->asString());
+            break;
         default:
             // TRANS: Client error displayed when trying to handle an unknown API method.
             $this->clientError(_('API method not found.'), $code = 404);
index 2745e5d3fe969cf70269901d706809ab73af0378..353973b6533a9d76fe25008a773db90dbb716272 100644 (file)
@@ -234,6 +234,14 @@ class ApiTimelinePublicAction extends ApiPrivateAuthAction
         case 'json':
             $this->showJsonTimeline($this->notices);
             break;
+        case 'as':
+            header('Content-Type: application/json; charset=utf-8');
+            $doc = new ActivityStreamJSONDocument($this->auth_user);
+            $doc->setTitle($title);
+            $doc->addLink($link, 'alternate', 'text/html');
+            $doc->addItemsFromNotices($this->notices);
+            $this->raw($doc->asString());
+            break;
         default:
             // TRANS: Client error displayed when trying to handle an unknown API method.
             $this->clientError(_('API method not found.'), $code = 404);
index 6213a08eac05f84e457ae34508864e59f23b3a17..b9f9be1dda0151a89b8190155064435a39db5d6d 100644 (file)
@@ -92,6 +92,20 @@ class ApiTimelineRetweetedToMeAction extends ApiAuthAction
         $offset = ($this->page-1) * $this->cnt;
         $limit  = $this->cnt;
 
+        // TRANS: Title for Atom feed "repeated to me". %s is the user nickname.
+        $title      = sprintf(_("Repeated to %s"), $this->auth_user->nickname);
+        $subtitle   = sprintf(
+            _('%1$s notices that were to repeated to %2$s / %3$s.'),
+            $sitename, $this->user->nickname, $profile->getBestName()
+        );
+        $taguribase = TagURI::base();
+        $id         = "tag:$taguribase:RepeatedToMe:" . $this->auth_user->id;
+
+        $link = common_local_url(
+            'all',
+             array('nickname' => $this->auth_user->nickname)
+        );
+
         $strm = $this->auth_user->repeatedToMe($offset, $limit, $this->since_id, $this->max_id);
 
         switch ($this->format) {
@@ -102,16 +116,31 @@ class ApiTimelineRetweetedToMeAction extends ApiAuthAction
             $this->showJsonTimeline($strm);
             break;
         case 'atom':
-            $profile    = $this->auth_user->getProfile();
+            header('Content-Type: application/atom+xml; charset=utf-8');
+
+            $atom = new AtomNoticeFeed($this->auth_user);
+
+            $atom->setId($id);
+            $atom->setTitle($title);
+            $atom->setSubtitle($subtitle);
+            $atom->setUpdated('now');
+            $atom->addLink($link);
 
-            // TRANS: Title for Atom feed "repeated to me". %s is the user nickname.
-            $title      = sprintf(_("Repeated to %s"), $this->auth_user->nickname);
-            $taguribase = TagURI::base();
-            $id         = "tag:$taguribase:RepeatedToMe:" . $this->auth_user->id;
-            $link       = common_local_url('all',
-                                           array('nickname' => $this->auth_user->nickname));
+            $id = $this->arg('id');
 
-            $this->showAtomTimeline($strm, $title, $id, $link);
+            $atom->setSelfLink($self);
+            $atom->addEntryFromNotices($strm);
+
+            $this->raw($atom->getString());
+
+            break;
+        case 'as':
+            header('Content-Type: application/json; charset=utf-8');
+            $doc = new ActivityStreamJSONDocument($this->auth_user);
+            $doc->setTitle($title);
+            $doc->addLink($link, 'alternate', 'text/html');
+            $doc->addItemsFromNotices($strm);
+            $this->raw($doc->asString());
             break;
         default:
             // TRANS: Client error displayed when trying to handle an unknown API method.
index 9cb277279f25f1cfa9c4498d696ca7a16a265679..aec6877f1585102d954750c3ca350d5ac9aff020 100644 (file)
@@ -93,9 +93,27 @@ class ApiTimelineRetweetsOfMeAction extends ApiAuthAction
         $offset = ($this->page-1) * $this->cnt;
         $limit  = $this->cnt;
 
-        $strm = $this->auth_user->repeatsOfMe($offset, $limit, $this->since_id, $this->max_id);
+        // TRANS: Title of list of repeated notices of the logged in user.
+        // TRANS: %s is the nickname of the logged in user.
+        $title      = sprintf(_("Repeats of %s"), $this->auth_user->nickname);
+        $sitename   = common_config('site', 'name');
+
+        $profile = $this->auth_user->getProfile();
+
+        $subtitle   = sprintf(
+            _('%1$s notices that %2$s / %3$s has repeated.'),
+            $sitename, $this->auth_user->nickname, $profile->getBestName()
+        );
 
-        common_debug(var_export($strm, true));
+        $taguribase = TagURI::base();
+        $id         = "tag:$taguribase:RepeatsOfMe:" . $this->auth_user->id;
+
+        $link = common_local_url(
+            'all',
+             array('nickname' => $this->auth_user->nickname)
+        );
+
+        $strm = $this->auth_user->repeatsOfMe($offset, $limit, $this->since_id, $this->max_id);
 
         switch ($this->format) {
         case 'xml':
@@ -105,49 +123,28 @@ class ApiTimelineRetweetsOfMeAction extends ApiAuthAction
             $this->showJsonTimeline($strm);
             break;
         case 'atom':
-            $profile    = $this->auth_user->getProfile();
-
-            // TRANS: Title of list of repeated notices of the logged in user.
-            // TRANS: %s is the nickname of the logged in user.
-            $title      = sprintf(_("Repeats of %s"), $this->auth_user->nickname);
-            $taguribase = TagURI::base();
-            $id         = "tag:$taguribase:RepeatsOfMe:" . $this->auth_user->id;
-
             header('Content-Type: application/atom+xml; charset=utf-8');
-
             $atom = new AtomNoticeFeed($this->auth_user);
-
             $atom->setId($id);
             $atom->setTitle($title);
             $atom->setSubtitle($subtitle);
             $atom->setUpdated('now');
-
-            $atom->addLink(
-                common_local_url(
-                    'showstream',
-                    array('nickname' => $this->auth_user->nickname)
-                )
-            );
-
-            $id = $this->arg('id');
-            $aargs = array('format' => 'atom');
-            if (!empty($id)) {
-                $aargs['id'] = $id;
-            }
-
-            $atom->addLink(
-                $this->getSelfUri('ApiTimelineRetweetsOfMe', $aargs),
-                array('rel' => 'self', 'type' => 'application/atom+xml')
-            );
-
+            $atom->addLink($link);
+            $atom->setSelfLink($this->getSelfUri());
             $atom->addEntryFromNotices($strm);
-
             $this->raw($atom->getString());
-
+            break;
+        case 'as':
+            header('Content-Type: application/json; charset=utf-8');
+            $doc = new ActivityStreamJSONDocument($this->auth_user);
+            $doc->setTitle($title);
+            $doc->addLink($link, 'alternate', 'text/html');
+            $doc->addItemsFromNotices($strm);
+            $this->raw($doc->asString());
             break;
         default:
             // TRANS: Client error displayed when trying to handle an unknown API method.
-            $this->clientError(_('API method not found.'), $code = 404);
+            $this->clientError(_('API method not found.'), 404);
             break;
         }
     }
index 4dbe1fc0dbcb9d865884eb4ff3a3e494ea71facb..5fa76d0cd08659e8b5cfc5b1975dc7111e4b57f8 100644 (file)
@@ -107,7 +107,7 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction
             $sitename
         );
         $taguribase = TagURI::base();
-        $id         = "tag:$taguribase:TagTimeline:".$tag;
+        $id         = "tag:$taguribase:TagTimeline:".$this->tag;
 
         $link = common_local_url(
             'tag',
@@ -116,8 +116,6 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction
 
         $self = $this->getSelfUri();
 
-        common_debug("self link is: $self");
-
         switch($this->format) {
         case 'xml':
             $this->showXmlTimeline($this->notices);
@@ -154,6 +152,14 @@ class ApiTimelineTagAction extends ApiPrivateAuthAction
         case 'json':
             $this->showJsonTimeline($this->notices);
             break;
+        case 'as':
+            header('Content-Type: application/json; charset=utf-8');
+            $doc = new ActivityStreamJSONDocument($this->auth_user);
+            $doc->setTitle($title);
+            $doc->addLink($link, 'alternate', 'text/html');
+            $doc->addItemsFromNotices($this->notices);
+            $this->raw($doc->asString());
+            break;
         default:
             // TRANS: Client error displayed when trying to handle an unknown API method.
             $this->clientError(_('API method not found.'), $code = 404);
index b0ca7e923fb741787fd2a6c3fecc5408cef600b5..66984b5abda1ca47ad8dafd338ca98c215d5237e 100644 (file)
@@ -201,6 +201,17 @@ class ApiTimelineUserAction extends ApiBareAuthAction
         case 'json':
             $this->showJsonTimeline($this->notices);
             break;
+        case 'as':
+            header('Content-Type: application/json; charset=utf-8');
+            $doc = new ActivityStreamJSONDocument($this->auth_user);
+            $doc->setTitle($atom->title);
+            $doc->addLink($link, 'alternate', 'text/html');
+            $doc->addItemsFromNotices($this->notices);
+
+            // XXX: Add paging extension?
+
+            $this->raw($doc->asString());
+            break;
         default:
             // TRANS: Client error displayed when trying to handle an unknown API method.
             $this->clientError(_('API method not found.'), $code = 404);
index 9f2b1df8683fb8500a2116a06da26ce653e437a1..a4547b325807d5d1b8d7c3f08e5b54d7aa4c0e97 100644 (file)
@@ -407,7 +407,7 @@ class Router
 
             $m->connect('api/statuses/public_timeline.:format',
                         array('action' => 'ApiTimelinePublic',
-                              'format' => '(xml|json|rss|atom)'));
+                              'format' => '(xml|json|rss|atom|as)'));
 
             $m->connect('api/statuses/friends_timeline.:format',
                         array('action' => 'ApiTimelineFriends',
@@ -416,55 +416,55 @@ class Router
             $m->connect('api/statuses/friends_timeline/:id.:format',
                         array('action' => 'ApiTimelineFriends',
                               'id' => Nickname::INPUT_FMT,
-                              'format' => '(xml|json|rss|atom)'));
+                              'format' => '(xml|json|rss|atom|as)'));
 
             $m->connect('api/statuses/home_timeline.:format',
                         array('action' => 'ApiTimelineHome',
-                              'format' => '(xml|json|rss|atom)'));
+                              'format' => '(xml|json|rss|atom|as)'));
 
             $m->connect('api/statuses/home_timeline/:id.:format',
                         array('action' => 'ApiTimelineHome',
                               'id' => Nickname::INPUT_FMT,
-                              'format' => '(xml|json|rss|atom)'));
+                              'format' => '(xml|json|rss|atom|as)'));
 
             $m->connect('api/statuses/user_timeline.:format',
                         array('action' => 'ApiTimelineUser',
-                              'format' => '(xml|json|rss|atom)'));
+                              'format' => '(xml|json|rss|atom|as)'));
 
             $m->connect('api/statuses/user_timeline/:id.:format',
                         array('action' => 'ApiTimelineUser',
                               'id' => Nickname::INPUT_FMT,
-                              'format' => '(xml|json|rss|atom)'));
+                              'format' => '(xml|json|rss|atom|as)'));
 
             $m->connect('api/statuses/mentions.:format',
                         array('action' => 'ApiTimelineMentions',
-                              'format' => '(xml|json|rss|atom)'));
+                              'format' => '(xml|json|rss|atom|as)'));
 
             $m->connect('api/statuses/mentions/:id.:format',
                         array('action' => 'ApiTimelineMentions',
                               'id' => Nickname::INPUT_FMT,
-                              'format' => '(xml|json|rss|atom)'));
+                              'format' => '(xml|json|rss|atom|as)'));
 
             $m->connect('api/statuses/replies.:format',
                         array('action' => 'ApiTimelineMentions',
-                              'format' => '(xml|json|rss|atom)'));
+                              'format' => '(xml|json|rss|atom|as)'));
 
             $m->connect('api/statuses/replies/:id.:format',
                         array('action' => 'ApiTimelineMentions',
                               'id' => Nickname::INPUT_FMT,
-                              'format' => '(xml|json|rss|atom)'));
+                              'format' => '(xml|json|rss|atom|as)'));
 
             $m->connect('api/statuses/retweeted_by_me.:format',
                         array('action' => 'ApiTimelineRetweetedByMe',
-                              'format' => '(xml|json|atom)'));
+                              'format' => '(xml|json|atom|as)'));
 
             $m->connect('api/statuses/retweeted_to_me.:format',
                         array('action' => 'ApiTimelineRetweetedToMe',
-                              'format' => '(xml|json|atom)'));
+                              'format' => '(xml|json|atom|as)'));
 
             $m->connect('api/statuses/retweets_of_me.:format',
                         array('action' => 'ApiTimelineRetweetsOfMe',
-                              'format' => '(xml|json|atom)'));
+                              'format' => '(xml|json|atom|as)'));
 
             $m->connect('api/statuses/friends.:format',
                         array('action' => 'ApiUserFriends',
@@ -625,12 +625,12 @@ class Router
 
             $m->connect('api/favorites.:format',
                         array('action' => 'ApiTimelineFavorites',
-                              'format' => '(xml|json|rss|atom)'));
+                              'format' => '(xml|json|rss|atom|as)'));
 
             $m->connect('api/favorites/:id.:format',
                         array('action' => 'ApiTimelineFavorites',
                               'id' => Nickname::INPUT_FMT,
-                              'format' => '(xml|json|rss|atom)'));
+                              'format' => '(xml|json|rss|atom|as)'));
 
             $m->connect('api/favorites/create/:id.:format',
                         array('action' => 'ApiFavoriteCreate',
@@ -695,7 +695,7 @@ class Router
             $m->connect('api/statusnet/groups/timeline/:id.:format',
                         array('action' => 'ApiTimelineGroup',
                               'id' => Nickname::INPUT_FMT,
-                              'format' => '(xml|json|rss|atom)'));
+                              'format' => '(xml|json|rss|atom|as)'));
 
             $m->connect('api/statusnet/groups/show.:format',
                         array('action' => 'ApiGroupShow',
@@ -756,7 +756,7 @@ class Router
             // Tags
             $m->connect('api/statusnet/tags/timeline/:tag.:format',
                         array('action' => 'ApiTimelineTag',
-                              'format' => '(xml|json|rss|atom)'));
+                              'format' => '(xml|json|rss|atom|as)'));
 
             // media related
             $m->connect(