class TwitapifavoritesAction extends TwitterapiAction {
- function is_readonly() {
-
- static $write_methods = array('favorites');
-
- $cmdtext = explode('.', $this->arg('method'));
-
- if (in_array($cmdtext[0], $write_methods)) {
- return false;
- }
-
- return true;
- }
-
function favorites($args, $apidata) {
parent::handle($args);
- $user = null;
-
- // function was called with an argument /favorites/api_arg.format
- if (isset($apidata['api_arg'])) {
-
- if (is_numeric($apidata['api_arg'])) {
- $user = User::staticGet($apidata['api_arg']);
- } else {
- $nickname = common_canonical_nickname($apidata['api_arg']);
- $user = User::staticGet('nickname', $nickname);
- }
- } else {
-
- // if no user was specified, then we'll use the authenticated user
- $user = $apidata['user'];
- }
+ $this->auth_user = $apidata['user'];
+ $user = $this->get_user($apidata['api_arg'], $apidata);
if (!$user) {
- // Set the user to be the auth user if asked-for can't be found
- // honestly! This is what Twitter does, I swear --Zach
- $user = $apidata['user'];
+ $this->client_error('Not Found', 404, $apidata['content-type']);
+ return;
}
$profile = $user->getProfile();
if (!$profile) {
common_server_error(_('User has no profile.'));
- exit();
+ return;
}
$page = $this->arg('page');
if (!$notice) {
common_server_error(_('Could not retrieve favorite notices.'));
- exit();
+ return;
}
$sitename = common_config('site', 'name');
$this->show_xml_timeline($notice);
break;
case 'rss':
- $this->show_rss_timeline($notice, $title, $id, $link, $subtitle);
+ $this->show_rss_timeline($notice, $title, $link, $subtitle);
break;
case 'atom':
$this->show_atom_timeline($notice, $title, $id, $link, $subtitle);
common_user_error(_('API method not found!'), $code = 404);
}
- exit();
}
function create($args, $apidata) {
parent::handle($args);
- if (!in_array($apidata['content-type'], array('xml', 'json'))) {
- common_user_error(_('API method not found!'), $code = 404);
- exit;
- }
-
// Check for RESTfulness
if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
// XXX: Twitter just prints the err msg, no XML / JSON.
$this->client_error(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']);
- exit();
+ return;
}
- $user = $apidata['user'];
+ if (!in_array($apidata['content-type'], array('xml', 'json'))) {
+ common_user_error(_('API method not found!'), $code = 404);
+ return;
+ }
+
+ $this->auth_user = $apidata['user'];
+ $user = $this->auth_user;
$notice_id = $apidata['api_arg'];
$notice = Notice::staticGet($notice_id);
if (!$notice) {
$this->client_error(_('No status found with that ID.'), 404, $apidata['content-type']);
- exit();
+ return;
}
// XXX: Twitter lets you fave things repeatedly via api.
if ($user->hasFave($notice)) {
$this->client_error(_('This notice is already a favorite!'), 403, $apidata['content-type']);
- exit();
+ return;
}
- common_debug("notice: " . $apidata['api_arg']);
-
$fave = Fave::addNew($user, $notice);
if (!$fave) {
common_server_error(_('Could not create favorite.'));
- exit();
+ return;
}
$this->notify($fave, $notice, $user);
$this->show_single_json_status($notice);
}
- exit();
}
function destroy($args, $apidata) {
parent::handle($args);
common_server_error(_('API method under construction.'), $code=501);
- exit();
}
// XXX: these two funcs swiped from faves. Maybe put in util.php, or some common base class?