From c622d144400026dac65c39303994d11f114c0f5b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Sat, 12 Dec 2009 14:46:24 -0500 Subject: add statuses/retweets to API --- actions/apistatusesretweets.php | 116 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 actions/apistatusesretweets.php (limited to 'actions/apistatusesretweets.php') diff --git a/actions/apistatusesretweets.php b/actions/apistatusesretweets.php new file mode 100644 index 000000000..c54a374e2 --- /dev/null +++ b/actions/apistatusesretweets.php @@ -0,0 +1,116 @@ +. + * + * @category API + * @package StatusNet + * @author Evan Prodromou + * @copyright 2009 StatusNet, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +if (!defined('STATUSNET')) { + exit(1); +} + +require_once INSTALLDIR . '/lib/apiauth.php'; +require_once INSTALLDIR . '/lib/mediafile.php'; + +/** + * Show up to 100 repeats of a notice + * + * @category API + * @package StatusNet + * @author Evan Prodromou + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://status.net/ + */ + +class ApiStatusesRetweetsAction extends ApiAuthAction +{ + const MAXCOUNT = 100; + + var $original = null; + var $cnt = self::MAXCOUNT; + + /** + * Take arguments for running + * + * @param array $args $_REQUEST args + * + * @return boolean success flag + * + */ + + function prepare($args) + { + parent::prepare($args); + + $id = $this->trimmed('id'); + + $this->original = Notice::staticGet('id', $id); + + if (empty($this->original)) { + $this->clientError(_('No such notice'), + 400, $this->format); + return false; + } + + $cnt = $this->trimmed('count'); + + if (empty($cnt) || !is_integer($cnt)) { + $cnt = 100; + } else { + $this->cnt = min((int)$cnt, self::MAXCOUNT); + } + + return true; + } + + /** + * Handle the request + * + * Make a new notice for the update, save it, and show it + * + * @param array $args $_REQUEST data (unused) + * + * @return void + */ + + function handle($args) + { + parent::handle($args); + + $strm = $this->original->repeatStream($this->cnt); + + switch ($this->format) { + case 'xml': + $this->showXmlTimeline($strm); + break; + case 'json': + $this->showJsonTimeline($strm); + break; + default: + $this->clientError(_('API method not found!'), $code = 404); + break; + } + } +} -- cgit v1.2.3-54-g00ecf From 745e35ac1fcee01298db09a8649f79f410138652 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Sun, 13 Dec 2009 18:55:17 +0100 Subject: (Puctuation) consistency in clientError() calls. --- actions/apistatusesretweet.php | 6 +++--- actions/apistatusesretweets.php | 2 +- actions/file.php | 8 ++++---- actions/grouprss.php | 4 ++-- actions/tagother.php | 4 ++-- actions/userbyid.php | 9 ++++----- lib/profileformaction.php | 4 ++-- plugins/OpenID/openidserver.php | 2 +- plugins/TemplatePlugin.php | 2 +- 9 files changed, 20 insertions(+), 21 deletions(-) (limited to 'actions/apistatusesretweets.php') diff --git a/actions/apistatusesretweet.php b/actions/apistatusesretweet.php index fc71d2274..85de79d5c 100644 --- a/actions/apistatusesretweet.php +++ b/actions/apistatusesretweet.php @@ -72,7 +72,7 @@ class ApiStatusesRetweetAction extends ApiAuthAction $this->original = Notice::staticGet('id', $id); if (empty($this->original)) { - $this->clientError(_('No such notice'), + $this->clientError(_('No such notice.'), 400, $this->format); return false; } @@ -80,7 +80,7 @@ class ApiStatusesRetweetAction extends ApiAuthAction $this->user = $this->auth_user; if ($this->user->id == $notice->profile_id) { - $this->clientError(_('Cannot repeat your own notice')); + $this->clientError(_('Cannot repeat your own notice.')); 400, $this->format); return false; } @@ -88,7 +88,7 @@ class ApiStatusesRetweetAction extends ApiAuthAction $profile = $this->user->getProfile(); if ($profile->hasRepeated($id)) { - $this->clientError(_('Already repeated that notice'), + $this->clientError(_('Already repeated that notice.'), 400, $this->format); return false; } diff --git a/actions/apistatusesretweets.php b/actions/apistatusesretweets.php index c54a374e2..2efd59b37 100644 --- a/actions/apistatusesretweets.php +++ b/actions/apistatusesretweets.php @@ -69,7 +69,7 @@ class ApiStatusesRetweetsAction extends ApiAuthAction $this->original = Notice::staticGet('id', $id); if (empty($this->original)) { - $this->clientError(_('No such notice'), + $this->clientError(_('No such notice.'), 400, $this->format); return false; } diff --git a/actions/file.php b/actions/file.php index 10c59a961..c6f7b998a 100644 --- a/actions/file.php +++ b/actions/file.php @@ -31,15 +31,15 @@ class FileAction extends Action parent::prepare($args); $this->id = $this->trimmed('notice'); if (empty($this->id)) { - $this->clientError(_('No notice id')); + $this->clientError(_('No notice ID.')); } $notice = Notice::staticGet('id', $this->id); if (empty($notice)) { - $this->clientError(_('No notice')); + $this->clientError(_('No notice.')); } $atts = $notice->attachments(); if (empty($atts)) { - $this->clientError(_('No attachments')); + $this->clientError(_('No attachments.')); } foreach ($atts as $att) { if (!empty($att->filename)) { @@ -48,7 +48,7 @@ class FileAction extends Action } } if (empty($this->filerec)) { - $this->clientError(_('No uploaded attachments')); + $this->clientError(_('No uploaded attachments.')); } return true; } diff --git a/actions/grouprss.php b/actions/grouprss.php index 50e48a67e..866fc66eb 100644 --- a/actions/grouprss.php +++ b/actions/grouprss.php @@ -88,14 +88,14 @@ class groupRssAction extends Rss10Action } if (!$nickname) { - $this->clientError(_('No nickname'), 404); + $this->clientError(_('No nickname.'), 404); return false; } $this->group = User_group::staticGet('nickname', $nickname); if (!$this->group) { - $this->clientError(_('No such group'), 404); + $this->clientError(_('No such group.'), 404); return false; } diff --git a/actions/tagother.php b/actions/tagother.php index c3f43be8b..e9e13b939 100644 --- a/actions/tagother.php +++ b/actions/tagother.php @@ -30,13 +30,13 @@ class TagotherAction extends Action { parent::prepare($args); if (!common_logged_in()) { - $this->clientError(_('Not logged in'), 403); + $this->clientError(_('Not logged in.'), 403); return false; } $id = $this->trimmed('id'); if (!$id) { - $this->clientError(_('No id argument.')); + $this->clientError(_('No ID argument.')); return false; } diff --git a/actions/userbyid.php b/actions/userbyid.php index ebff7e4a7..f3e1556f3 100644 --- a/actions/userbyid.php +++ b/actions/userbyid.php @@ -47,17 +47,17 @@ class UserbyidAction extends Action { /** * Is read only? - * + * * @return boolean true */ function isReadOnly($args) - { + { return true; } /** * Class handler. - * + * * @param array $args array of arguments * * @return nothing @@ -67,7 +67,7 @@ class UserbyidAction extends Action parent::handle($args); $id = $this->trimmed('id'); if (!$id) { - $this->clientError(_('No id.')); + $this->clientError(_('No ID.')); } $user = User::staticGet($id); if (!$user) { @@ -88,4 +88,3 @@ class UserbyidAction extends Action common_redirect($url, 303); } } - diff --git a/lib/profileformaction.php b/lib/profileformaction.php index 8cb5f6a93..8a934666e 100644 --- a/lib/profileformaction.php +++ b/lib/profileformaction.php @@ -120,7 +120,7 @@ class ProfileFormAction extends Action if ($action) { common_redirect(common_local_url($action, $args), 303); } else { - $this->clientError(_("No return-to arguments")); + $this->clientError(_("No return-to arguments.")); } } @@ -134,6 +134,6 @@ class ProfileFormAction extends Action function handlePost() { - $this->serverError(_("unimplemented method")); + $this->serverError(_("Unimplemented method.")); } } diff --git a/plugins/OpenID/openidserver.php b/plugins/OpenID/openidserver.php index 181cbdf45..afbca553f 100644 --- a/plugins/OpenID/openidserver.php +++ b/plugins/OpenID/openidserver.php @@ -103,7 +103,7 @@ class OpenidserverAction extends Action $response = $this->generateDenyResponse($request); } else { //invalid - $this->clientError(sprintf(_m('You are not authorized to use the identity %s'),$request->identity),$code=403); + $this->clientError(sprintf(_m('You are not authorized to use the identity %s.'),$request->identity),$code=403); } } else { $response = $this->oserver->handleRequest($request); diff --git a/plugins/TemplatePlugin.php b/plugins/TemplatePlugin.php index 5f3ad81f5..18aa8034c 100644 --- a/plugins/TemplatePlugin.php +++ b/plugins/TemplatePlugin.php @@ -300,7 +300,7 @@ class TemplateAction extends Action // verify that user is admin if (!($user->id == 1)) - $this->clientError(_('only User #1 can update the template'), $code = 401); + $this->clientError(_('Only User #1 can update the template.'), $code = 401); // open the old template $tpl_file = $this->templateFolder() . '/index.html'; -- cgit v1.2.3-54-g00ecf