summaryrefslogtreecommitdiff
path: root/actions/twitapidirect_messages.php
diff options
context:
space:
mode:
authorZach Copley <zach@controlyourself.ca>2008-09-25 21:20:15 -0400
committerZach Copley <zach@controlyourself.ca>2008-09-25 21:20:15 -0400
commit10f4ee7abb889aeb21b45efb563ebe5c2f4d9c94 (patch)
tree1143bcce438ded1e6f96abb123b5bf1b7babf375 /actions/twitapidirect_messages.php
parentd687f16525307b89c99c6fc0fb3f78e30095ae7d (diff)
Twitter-compatible API - rss and atom feeds for direct messages
darcs-hash:20080926012015-7b5ce-da94465ff9c027183e0e674b6152902c302d0131.gz
Diffstat (limited to 'actions/twitapidirect_messages.php')
-rw-r--r--actions/twitapidirect_messages.php71
1 files changed, 65 insertions, 6 deletions
diff --git a/actions/twitapidirect_messages.php b/actions/twitapidirect_messages.php
index 39780258a..8eee6a753 100644
--- a/actions/twitapidirect_messages.php
+++ b/actions/twitapidirect_messages.php
@@ -63,18 +63,24 @@ class Twitapidirect_messagesAction extends TwitterapiAction {
$message->find();
+ $title = 'Direct messages to ' . $user->nickname;
+ $subtitle = 'All the direct messages sent to ' . $user->nickname;
+
+ $server = common_root_url();
+ $link = $server . $user->nickname . '/inbox';
+
switch($apidata['content-type']) {
case 'xml':
- $this->show_xml_direct_messages($message);
+ $this->show_xml_dmsgs($message);
break;
case 'rss':
- //$this->show_rss_timeline($notice, $title, $id, $link, $subtitle);
+ $this->show_rss_dmsgs($message, $title, $link, $subtitle);
break;
case 'atom':
- //$this->show_atom_timeline($notice, $title, $id, $link, $subtitle);
+ $this->show_atom_dmsgs($message, $title, $link, $subtitle);
break;
case 'json':
- $this->show_json_direct_messages($message);
+ $this->show_json_dmsgs($message);
break;
default:
common_user_error(_('API method not found!'), $code = 404);
@@ -102,7 +108,7 @@ class Twitapidirect_messagesAction extends TwitterapiAction {
exit();
}
- function show_xml_direct_messages($message) {
+ function show_xml_dmsgs($message) {
$this->init_document('xml');
common_element_start('direct-messages', array('type' => 'array'));
@@ -123,7 +129,7 @@ class Twitapidirect_messagesAction extends TwitterapiAction {
$this->end_document('xml');
}
- function show_json_direct_messages($message) {
+ function show_json_dmsgs($message) {
$this->init_document('json');
@@ -146,6 +152,59 @@ class Twitapidirect_messagesAction extends TwitterapiAction {
$this->end_document('json');
}
+ function show_rss_dmsgs($message, $title, $link, $subtitle) {
+
+ $this->init_document('rss');
+
+ common_element_start('channel');
+ common_element('title', NULL, $title);
+
+ common_element('link', NULL, $link);
+ common_element('description', NULL, $subtitle);
+ common_element('language', NULL, 'en-us');
+ common_element('ttl', NULL, '40');
+
+ if (is_array($message)) {
+ foreach ($message as $m) {
+ $entry = $this->twitter_rss_dmsg_array($m);
+ $this->show_twitter_rss_item($entry);
+ }
+ } else {
+ while ($message->fetch()) {
+ $entry = $this->twitter_rss_dmsg_array($message);
+ $this->show_twitter_rss_item($entry);
+ }
+ }
+
+ common_element_end('channel');
+ $this->end_twitter_rss();
+ }
+
+ function show_atom_dmsgs($message, $title, $link, $subtitle) {
+
+ $this->init_document('atom');
+
+ common_element('title', NULL, $title);
+ $siteserver = common_config('site', 'server');
+ common_element('id', NULL, "tag:$siteserver,2008:DirectMessage");
+ common_element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), NULL);
+ common_element('updated', NULL, common_date_iso8601(strftime('%c')));
+ common_element('subtitle', NULL, $subtitle);
+
+ if (is_array($message)) {
+ foreach ($message as $m) {
+ $entry = $this->twitter_rss_dmsg_array($m);
+ $this->show_twitter_atom_entry($entry);
+ }
+ } else {
+ while ($message->fetch()) {
+ $entry = $this->twitter_rss_dmsg_array($message);
+ $this->show_twitter_atom_entry($entry);
+ }
+ }
+
+ $this->end_document('atom');
+ }
} \ No newline at end of file