]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Twitter-compatible API: public_timeline.rss mostly working
authorzach <zach@copley.name>
Wed, 16 Jul 2008 07:21:24 +0000 (03:21 -0400)
committerzach <zach@copley.name>
Wed, 16 Jul 2008 07:21:24 +0000 (03:21 -0400)
darcs-hash:20080716072124-ca946-6714d13d6801eddf84800b884721aac37852993d.gz

actions/twitapistatuses.php
lib/twitterapi.php

index 83fd4b53c0ad38968fed18c3e3c8a9003ce41013..d1f9579425bcd77fa9dea84e0864552409e44a9e 100644 (file)
@@ -47,12 +47,13 @@ class TwitapistatusesAction extends TwitterapiAction {
                $cnt = $notice->find();
 
                if ($apidata['content-type'] == 'xml') {
+                       
                        header('Content-Type: application/xml; charset=utf-8');         
                        
                        common_start_xml();
 
                        // XXX: To really live up to the spec we need to build a list
-                       // of notices by users who have custom avatars
+                       // of notices by users who have custom avatars -- Zach
                        if ($cnt > 0) {
                                common_element_start('statuses', array('type' => 'array'));
                                for ($i = 0; $i < 20; $i++) {
@@ -69,7 +70,35 @@ class TwitapistatusesAction extends TwitterapiAction {
                
                        common_end_xml();
                } elseif ($apidata['content-type'] == 'rss') {
-                       common_server_error("API method under construction.", $code=501);
+
+                       //header('Content-Type: application/xml; charset=utf-8');               
+                       
+                       header("Content-Type: application/rss+xml; charset=utf-8");
+
+                       $this->init_twitter_rss();
+                       
+                       common_element_start('channel');
+                       common_element('title', NULL, 'Identi.ca public timeline');
+                       common_element('link', NULL, 'http://www.identi.ca');
+                       common_element('description', NULL, 'Identi.ca updates from everyone!');
+                       common_element('language', NULL, 'en-us');
+                       common_element('ttl', NULL, '40'); // 40 what?
+                       
+                       if ($cnt > 0) {
+                               for ($i = 0; $i < 20; $i++) {
+                                       if ($notice->fetch()) {
+                                               $twitter_status = $this->twitter_status_array($notice);                                         
+                                               $this->show_twitter_rss_item($twitter_status);
+                                       } else {
+                                               // shouldn't happen!
+                                               break;
+                                       }
+                               }
+                       }
+                       common_element_end('channel');
+                                               
+                       $this->end_twitter_rss();
+
                } elseif ($apidata['content-type'] == 'atom') {
                        common_server_error("API method under construction.", $code=501);       
                } elseif ($apidata['content-type'] == 'json') {
index 708630247cd0e46668acefcef48cc20c2c8e1a21..012057861f96b5ed9a3be54927e5b737ecbd6ddc 100644 (file)
@@ -154,4 +154,44 @@ class TwitterapiAction extends Action {
                return NULL;
        }
        
+       function init_twitter_rss() {
+               
+               common_start_xml();
+               common_element_start('rss', array('version' => '2.0'));
+       }
+       
+       function end_twitter_rss() {
+               
+               common_element_end('rss');
+               common_end_xml();
+
+       }
+
+       function get_twitter_channel() {
+               
+       }
+
+/*
+
+  <item>
+    <title>CapitalD: @baxterd Have you read The Conquest of Cool? It looks interesting to me...</title>
+    <description>CapitalD: @baxterd Have you read The Conquest of Cool? It looks interesting to me...</description>
+    <pubDate>Mon, 14 Jul 2008 23:54:13 +0000</pubDate>
+    <guid>http://twitter.com/CapitalD/statuses/858499551</guid>
+    <link>http://twitter.com/CapitalD/statuses/858499551</link>
+  </item>
+
+*/
+
+       function show_twitter_rss_item($twitter_status) {
+               common_element_start('item');
+               common_element('title', NULL, "{$twitter_status[user][screen_name]}: $twitter_status[text]");
+               common_element('description', NULL, "{$twitter_status[user][screen_name]}: $twitter_status[text]");
+               common_element('pubDate', NULL, "$twitter_status[created_at]");
+               common_element('guid', NULL, "$twitter_status[id]");
+               common_element('link', NULL, "$twitter_status[id]");
+               common_element_end('item');
+       }
+
+       
 }
\ No newline at end of file