diff options
author | zach <zach@controlyourself.ca> | 2008-10-16 22:36:38 -0400 |
---|---|---|
committer | zach <zach@controlyourself.ca> | 2008-10-16 22:36:38 -0400 |
commit | b2f0ad1cccc4bebbf264c4ab61a37173c9a565cc (patch) | |
tree | e0b7298a79dbd44710b385a4fdc5eac2f4785aa8 /lib | |
parent | 9b75a8ea9f7f274e1e410afa3f3cde793bdecdc3 (diff) |
Twitter-compatible API:
- Filled in favorites tags in statuses
- Filled in more tags in user/show, including undocumented features
- Better error handling and more consistent error messages
- Code clean-up and refactoring
- Removed huge obnoxious comments
darcs-hash:20081017023638-462f3-27b5d2709e423c616723d4bcfbc9d7d30a4ad161.gz
Diffstat (limited to 'lib')
-rw-r--r-- | lib/twitterapi.php | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/lib/twitterapi.php b/lib/twitterapi.php index 06b41fd0c..734fc4907 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -21,6 +21,8 @@ if (!defined('LACONICA')) { exit(1); } class TwitterapiAction extends Action { + var $auth_user; + function handle($args) { parent::handle($args); } @@ -53,10 +55,11 @@ class TwitterapiAction extends Action { return $twitter_user; } - function twitter_status_array($notice, $get_user=true) { + function twitter_status_array($notice, $include_user=true) { - $twitter_status = array(); + $profile = $notice->getProfile(); + $twitter_status = array(); $twitter_status['text'] = $notice->content; $twitter_status['truncated'] = 'false'; # Not possible on Laconica $twitter_status['created_at'] = $this->date_twitter($notice->created); @@ -64,12 +67,18 @@ class TwitterapiAction extends Action { $twitter_status['source'] = $this->source_link($notice->source); $twitter_status['id'] = intval($notice->id); $twitter_status['in_reply_to_user_id'] = ($notice->reply_to) ? $this->replier_by_reply(intval($notice->reply_to)) : NULL; - $twitter_status['favorited'] = NULL; # XXX: Not implemented on Laconica yet. + + if (isset($this->auth_user)) { + common_debug("auth user set: " . $this->auth_user->nickname); + $twitter_status['favorited'] = ($this->auth_user->hasFave($notice)) ? 'true' : 'false'; + } else { + common_debug("no auth user set"); + $twitter_status['favorited'] = 'false'; + } - if ($get_user) { - $profile = $notice->getProfile(); + if ($include_user) { # Don't get notice (recursive!) - $twitter_user = $this->twitter_user_array($profile, false); + $twitter_user = $this->twitter_user_array($profile, false, $user); $twitter_status['user'] = $twitter_user; } @@ -364,7 +373,7 @@ class TwitterapiAction extends Action { } } - function init_document($type='xml') { + function init_document($type='xml') { switch ($type) { case 'xml': header('Content-Type: application/xml; charset=utf-8'); @@ -505,11 +514,14 @@ class TwitterapiAction extends Action { return; } - function get_user($id) { - if (is_numeric($id)) { + function get_user($id, $apidata=NULL) { + if (!$id) { + return $apidata['user']; + } else if (is_numeric($id)) { return User::staticGet($id); } else { - return User::staticGet('nickname', $id); + $nickname = common_canonical_nickname($id); + return User::staticGet('nickname', $nickname); } } |