Make other timeline API endpoints output Activity Streams JSON

This commit is contained in:
Zach Copley 2011-02-18 15:43:40 -08:00
parent da42d36d7f
commit 68017392ff
10 changed files with 150 additions and 74 deletions

View 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);

View 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.

View 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);

View 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);

View 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);

View 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');
// 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));
$atom = new AtomNoticeFeed($this->auth_user);
$this->showAtomTimeline($strm, $title, $id, $link);
$atom->setId($id);
$atom->setTitle($title);
$atom->setSubtitle($subtitle);
$atom->setUpdated('now');
$atom->addLink($link);
$id = $this->arg('id');
$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.

View 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');
common_debug(var_export($strm, true));
$profile = $this->auth_user->getProfile();
$subtitle = sprintf(
_('%1$s notices that %2$s / %3$s has repeated.'),
$sitename, $this->auth_user->nickname, $profile->getBestName()
);
$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;
}
}

View 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);

View 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);

View 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(