]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Twitter-compatible API: public_timeline.atom works
authorzach <zach@copley.name>
Wed, 16 Jul 2008 20:52:18 +0000 (16:52 -0400)
committerzach <zach@copley.name>
Wed, 16 Jul 2008 20:52:18 +0000 (16:52 -0400)
darcs-hash:20080716205218-ca946-98e53e29ed364ea4254ed90303c04b93511877f9.gz

actions/twitapistatuses.php
lib/twitterapi.php

index 3a495a1296d8d1e808438b92f7fcb9a41e659f4f..f9b804bd16d423ff25d7dbcffe165351f9e1f566 100644 (file)
@@ -101,7 +101,33 @@ class TwitapistatusesAction extends TwitterapiAction {
                        $this->end_twitter_rss();
 
                } elseif ($apidata['content-type'] == 'atom') {
-                       common_server_error("API method under construction.", $code=501);       
+
+                       header('Content-Type: application/atom+xml; charset=utf-8');
+
+                       $this->init_twitter_atom();
+                       
+                       $sitename = common_config('site', 'name');
+                       $siteserver = common_config('site', 'server');
+
+                       common_element('title', NULL, "$sitename public timeline");
+                       common_element('id', NULL, "tag:$siteserver:Statuses");
+                       common_element('link', array('href' => "http://$siteserver", 'rel' => 'alternate', 'type' => 'text/html'), NULL);
+                       common_element('subtitle', NULL, "$sitename updates from everyone!");
+                       
+                       if ($cnt > 0) {
+                               for ($i = 0; $i < 20; $i++) {
+                                       if ($notice->fetch()) {
+                                               $entry = $this->twitter_rss_entry_array($notice);                                               
+                                               $this->show_twitter_atom_entry($entry);
+                                       } else {
+                                               // shouldn't happen!
+                                               break;
+                                       }
+                               }
+                       }
+
+                       $this->end_twitter_atom();
+
                } elseif ($apidata['content-type'] == 'json') {
 
                        header('Content-Type: application/json; charset=utf-8');
index b11c04876bce9f6972e649202b660f245b9f9311..2c4ddbbd5c72fd331748d0d26abe586e686d8b32 100644 (file)
@@ -77,7 +77,7 @@ class TwitterapiAction extends Action {
                $entry['title'] = $entry['content'];
                $entry['link'] = common_local_url('shownotice', array('notice' => $notice->id));;
                $entry['published'] = $this->date_iso8601($notice->created);
-               $entry['id'] = "tag:http://$server,$entry[published]:$entry[link]";
+               $entry['id'] = "tag:$server,$entry[published]:$entry[link]";
                $entry['updated'] = $entry['published'];
 
                # RSS Item specific
@@ -127,6 +127,17 @@ class TwitterapiAction extends Action {
                common_element('link', NULL, $entry['link']);
                common_element_end('item');
        }
+               
+       function show_twitter_atom_entry($entry) {
+           common_element_start('entry');
+               common_element('title', NULL, $entry['title']);
+               common_element('content', array('type' => 'html'), $entry['title']);
+               common_element('id', NULL, $entry['id']);
+               common_element('published', NULL, $entry['published']);
+               common_element('updated', NULL, $entry['updated']);
+               common_element('link', array('href' => $entry['link'], 'rel' => 'alternate', 'type' => 'text/html'), NULL);
+               common_element_end('entry');
+       }
        
        function render_twitter_json_statuses($twitter_statuses) {
                print(json_encode($twitter_statuses));
@@ -197,20 +208,27 @@ class TwitterapiAction extends Action {
        }
        
        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() {
                
        }
+               
+       function init_twitter_atom() {
+               common_start_xml();
+               common_element_start('feed', array('xmlns' => 'http://www.w3.org/2005/Atom', 'xml:lang' => 'en-US'));
+       }
+       
+       function end_twitter_atom() {
+               common_end_xml();
+               common_element_end('feed');
+       }
 
 }
\ No newline at end of file