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 /* XXX: Please don't freak out about all the ugly comments in this file.
25 * They are mostly in here for reference while I work on the
26 * API. I'll fix things up to make them look better later. -- Zach
28 class TwitapistatusesAction extends TwitterapiAction {
31 * Returns the 20 most recent statuses from non-protected users who have set a custom
32 * user icon. Does not require authentication.
34 * URL: http://identi.ca/api/statuses/public_timeline.format
36 * Formats: xml, json, rss, atom
38 function public_timeline($args, $apidata) {
39 parent::handle($args);
41 if ($apidata['content-type'] == 'xml') {
42 header('Content-Type: application/xml; charset=utf-8');
43 $notice = DB_DataObject::factory('notice');
45 # FIXME: bad performance
46 $notice->whereAdd('EXISTS (SELECT user.id from user where user.id = notice.profile_id)');
47 $notice->orderBy('created DESC, notice.id DESC');
49 $cnt = $notice->find();
53 // XXX: To really live up to the spec we need to build a list
54 // of notices by users who have custom avatars
56 common_element_start('statuses', array('type' => 'array'));
57 for ($i = 0; $i < 20; $i++) {
58 if ($notice->fetch()) {
59 $this->render_xml_status($notice);
65 common_element_end('statuses');
69 } elseif ($apidata['content-type'] == 'rss') {
70 common_server_error("API method under construction.", $code=501);
71 } elseif ($apidata['content-type'] == 'atom') {
72 common_server_error("API method under construction.", $code=501);
73 } elseif ($apidata['content-type'] == 'json') {
74 common_server_error("API method under construction.", $code=501);
83 Returns the 20 most recent statuses posted by the authenticating user and that user's friends.
84 This is the equivalent of /home on the Web.
86 URL: http://identi.ca/api/statuses/friends_timeline.format
90 * since. Optional. Narrows the returned results to just those statuses created after the specified
91 HTTP-formatted date. The same behavior is available by setting an If-Modified-Since header in
93 Ex: http://identi.ca/api/statuses/friends_timeline.rss?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
94 * since_id. Optional. Returns only statuses with an ID greater than (that is, more recent than)
95 the specified ID. Ex: http://identi.ca/api/statuses/friends_timeline.xml?since_id=12345
96 * count. Optional. Specifies the number of statuses to retrieve. May not be greater than 200.
97 Ex: http://identi.ca/api/statuses/friends_timeline.xml?count=5
98 * page. Optional. Ex: http://identi.ca/api/statuses/friends_timeline.rss?page=3
100 Formats: xml, json, rss, atom
102 function friends_timeline($args, $apidata) {
103 parent::handle($args);
105 $since = $this->arg('since');
106 $since_id = $this->arg('since_id');
107 $count = $this->arg('count');
108 $page = $this->arg('page');
110 print "Friends Timeline! requested content-type: " . $apidata['content-type'] . "\n";
111 print "since: $since, since_id: $since_id, count: $count, page: $page\n";
118 Returns the 20 most recent statuses posted from the authenticating user. It's also possible to
119 request another user's timeline via the id parameter below. This is the equivalent of the Web
120 /archive page for your own user, or the profile page for a third party.
122 URL: http://identi.ca/api/statuses/user_timeline.format
124 Formats: xml, json, rss, atom
128 * id. Optional. Specifies the ID or screen name of the user for whom to return the
129 friends_timeline. Ex: http://identi.ca/api/statuses/user_timeline/12345.xml or
130 http://identi.ca/api/statuses/user_timeline/bob.json.
131 * count. Optional. Specifies the number of
132 statuses to retrieve. May not be greater than 200. Ex:
133 http://identi.ca/api/statuses/user_timeline.xml?count=5
134 * since. Optional. Narrows the returned
135 results to just those statuses created after the specified HTTP-formatted date. The same
136 behavior is available by setting an If-Modified-Since header in your HTTP request. Ex:
137 http://identi.ca/api/statuses/user_timeline.rss?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
138 * since_id. Optional. Returns only statuses with an ID greater than (that is, more recent than)
139 the specified ID. Ex: http://identi.ca/api/statuses/user_timeline.xml?since_id=12345 * page.
140 Optional. Ex: http://identi.ca/api/statuses/friends_timeline.rss?page=3
142 function user_timeline($args, $apidata) {
143 parent::handle($args);
145 $id = $this->arg('id');
146 $count = $this->arg('count');
147 $since = $this->arg('since');
148 $since_id = $this->arg('since_id');
150 print "User Timeline! requested content-type: " . $apidata['content-type'] . "\n";
151 print "id: $id since: $since, since_id: $since_id, count: $count\n";
157 Returns a single status, specified by the id parameter below. The status's author will be returned inline.
159 URL: http://identi.ca/api/statuses/show/id.format
165 * id. Required. The numerical ID of the status you're trying to retrieve.
166 Ex: http://identi.ca/api/statuses/show/123.xml
168 function show($args, $apidata) {
169 parent::handle($args);
171 $id = $this->arg('id');
173 print "show requested content-type: " . $apidata['content-type'] . "\n";
181 Updates the authenticating user's status. Requires the status parameter specified below. Request must be a POST.
183 URL: http://identi.ca/api/statuses/update.format
185 Formats: xml, json. Returns the posted status in requested format when successful.
189 * status. Required. The text of your status update. Be sure to URL encode as necessary. Must not be more than 160
190 characters and should not be more than 140 characters to ensure optimal display.
193 function update($args, $apidata) {
194 parent::handle($args);
195 common_server_error("API method under construction.", $code=501);
199 Returns the 20 most recent @replies (status updates prefixed with @username) for the authenticating user.
200 URL: http://identi.ca/api/statuses/replies.format
202 Formats: xml, json, rss, atom
206 * page. Optional. Retrieves the 20 next most recent replies. Ex: http://identi.ca/api/statuses/replies.xml?page=3
207 * since. Optional. Narrows the returned results to just those replies created after the specified HTTP-formatted date. The
208 same behavior is available by setting an If-Modified-Since header in your HTTP request. Ex:
209 http://identi.ca/api/statuses/replies.xml?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
210 * since_id. Optional. Returns only statuses with an ID greater than (that is, more recent than) the specified
211 ID. Ex: http://identi.ca/api/statuses/replies.xml?since_id=12345
213 function replies($args, $apidata) {
214 parent::handle($args);
215 common_server_error("API method under construction.", $code=501);
220 Destroys the status specified by the required ID parameter. The authenticating user must be
221 the author of the specified status.
223 URL: http://identi.ca/api/statuses/destroy/id.format
229 * id. Required. The ID of the status to destroy. Ex:
230 http://identi.ca/api/statuses/destroy/12345.json or
231 http://identi.ca/api/statuses/destroy/23456.xml
234 function destroy($args, $apidata) {
235 parent::handle($args);
236 common_server_error("API method under construction.", $code=501);
242 Returns up to 100 of the authenticating user's friends who have most recently updated, each with current status inline.
243 It's also possible to request another user's recent friends list via the id parameter below.
245 URL: http://identi.ca/api/statuses/friends.format
251 * id. Optional. The ID or screen name of the user for whom to request a list of friends. Ex:
252 http://identi.ca/api/statuses/friends/12345.json
254 http://identi.ca/api/statuses/friends/bob.xml
255 * page. Optional. Retrieves the next 100 friends. Ex: http://identi.ca/api/statuses/friends.xml?page=2
256 * lite. Optional. Prevents the inline inclusion of current status. Must be set to a value of true. Ex:
257 http://identi.ca/api/statuses/friends.xml?lite=true
258 * since. Optional. Narrows the returned results to just those friendships created after the specified
259 HTTP-formatted date. The same behavior is available by setting an If-Modified-Since header in your HTTP
260 request. Ex: http://identi.ca/api/statuses/friends.xml?since=Tue%2C+27+Mar+2007+22%3A55%3A48+GMT
262 function friends($args, $apidata) {
263 parent::handle($args);
264 common_server_error("API method under construction.", $code=501);
268 Returns the authenticating user's followers, each with current status inline. They are ordered by the
269 order in which they joined Twitter (this is going to be changed).
271 URL: http://identi.ca/api/statuses/followers.format
276 * id. Optional. The ID or screen name of the user for whom to request a list of followers. Ex:
277 http://identi.ca/api/statuses/followers/12345.json
279 http://identi.ca/api/statuses/followers/bob.xml
280 * page. Optional. Retrieves the next 100 followers. Ex: http://identi.ca/api/statuses/followers.xml?page=2
281 * lite. Optional. Prevents the inline inclusion of current status. Must be set to a value of true.
282 Ex: http://identi.ca/api/statuses/followers.xml?lite=true
284 function followers($args, $apidata) {
285 parent::handle($args);
286 common_server_error("API method under construction.", $code=501);
290 Returns a list of the users currently featured on the site with their current statuses inline.
291 URL: http://identi.ca/api/statuses/featured.format
295 function featured($args, $apidata) {
296 parent::handle($args);
297 common_server_error("API method under construction.", $code=501);