3 * Laconica - a distributed open-source microblogging tool
4 * Copyright (C) 2008, Controlez-Vous, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('LACONICA')) { exit(1); }
22 require_once(INSTALLDIR.'/lib/twitterapi.php');
24 class TwitapiaccountAction extends TwitterapiAction
26 function verify_credentials($args, $apidata)
28 parent::handle($args);
30 switch ($apidata['content-type']) {
33 $action_obj = new TwitapiusersAction();
34 $action_obj->prepare($args);
35 call_user_func(array($action_obj, 'show'), $args, $apidata);
38 header('Content-Type: text/html; charset=utf-8');
43 function end_session($args, $apidata)
45 parent::handle($args);
46 $this->serverError(_('API method under construction.'), $code=501);
49 function update_location($args, $apidata)
51 parent::handle($args);
53 if ($_SERVER['REQUEST_METHOD'] != 'POST') {
54 $this->clientError(_('This method requires a POST.'), 400, $apidata['content-type']);
58 $location = trim($this->arg('location'));
60 if (!is_null($location) && mb_strlen($location) > 255) {
62 // XXX: But Twitter just truncates and runs with it. -- Zach
63 $this->clientError(_('That\'s too long. Max notice size is 255 chars.'), 406, $apidate['content-type']);
67 $user = $apidata['user'];
68 $profile = $user->getProfile();
71 $this->serverError(_('User has no profile.'));
75 $orig_profile = clone($profile);
76 $profile->location = $location;
78 $result = $profile->update($orig_profile);
81 common_log_db_error($profile, 'UPDATE', __FILE__);
82 $this->serverError(_('Couldn\'t save profile.'));
86 common_broadcast_profile($profile);
87 $type = $apidata['content-type'];
89 $this->init_document($type);
90 $this->show_profile($profile, $type);
91 $this->end_document($type);
95 function update_delivery_device($args, $apidata)
97 parent::handle($args);
98 $this->serverError(_('API method under construction.'), $code=501);
101 // We don't have a rate limit, but some clients check this method.
102 // It always returns the same thing: 100 hit left.
103 function rate_limit_status($args, $apidata)
105 parent::handle($args);
107 $type = $apidata['content-type'];
108 $this->init_document($type);
110 if ($apidata['content-type'] == 'xml') {
111 $this->elementStart('hash');
112 $this->element('remaining-hits', array('type' => 'integer'), 100);
113 $this->element('hourly-limit', array('type' => 'integer'), 100);
114 $this->element('reset-time', array('type' => 'datetime'), null);
115 $this->element('reset_time_in_seconds', array('type' => 'integer'), 0);
116 $this->elementEnd('hash');
117 } elseif ($apidata['content-type'] == 'json') {
119 $out = array('reset_time_in_seconds' => 0,
120 'remaining_hits' => 100,
121 'hourly_limit' => 100,
123 print json_encode($out);
126 $this->end_document($type);