Made /api/account/verify_credentials.format return an extended user object. Updates to status and user API objects.
This commit is contained in:
parent
78a715bc37
commit
36bb33fb1d
@ -23,16 +23,18 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
|
|||||||
|
|
||||||
class TwitapiaccountAction extends TwitterapiAction
|
class TwitapiaccountAction extends TwitterapiAction
|
||||||
{
|
{
|
||||||
|
|
||||||
function verify_credentials($args, $apidata)
|
function verify_credentials($args, $apidata)
|
||||||
{
|
{
|
||||||
if ($apidata['content-type'] == 'xml') {
|
parent::handle($args);
|
||||||
header('Content-Type: application/xml; charset=utf-8');
|
|
||||||
print '<authorized>true</authorized>';
|
switch ($apidata['content-type']) {
|
||||||
} elseif ($apidata['content-type'] == 'json') {
|
case 'xml':
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
case 'json':
|
||||||
print '{"authorized":true}';
|
$action_obj = new TwitapiusersAction();
|
||||||
} else {
|
$action_obj->prepare($args);
|
||||||
|
call_user_func(array($action_obj, 'show'), $args, $apidata);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
header('Content-Type: text/html; charset=utf-8');
|
header('Content-Type: text/html; charset=utf-8');
|
||||||
print 'Authorized';
|
print 'Authorized';
|
||||||
}
|
}
|
||||||
|
@ -33,14 +33,18 @@ class TwitapiusersAction extends TwitterapiAction
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->auth_user = $apidata['user'];
|
|
||||||
$user = null;
|
$user = null;
|
||||||
$email = $this->arg('email');
|
$email = $this->arg('email');
|
||||||
|
$user_id = $this->arg('user_id');
|
||||||
|
|
||||||
if ($email) {
|
if ($email) {
|
||||||
$user = User::staticGet('email', $email);
|
$user = User::staticGet('email', $email);
|
||||||
|
} elseif ($user_id) {
|
||||||
|
$user = $this->get_user($user_id);
|
||||||
} elseif (isset($apidata['api_arg'])) {
|
} elseif (isset($apidata['api_arg'])) {
|
||||||
$user = $this->get_user($apidata['api_arg']);
|
$user = $this->get_user($apidata['api_arg']);
|
||||||
|
} elseif (isset($apidata['user'])) {
|
||||||
|
$user = $apidata['user'];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
@ -74,9 +78,12 @@ class TwitapiusersAction extends TwitterapiAction
|
|||||||
|
|
||||||
// Other fields Twitter sends...
|
// Other fields Twitter sends...
|
||||||
$twitter_user['profile_background_color'] = '';
|
$twitter_user['profile_background_color'] = '';
|
||||||
|
$twitter_user['profile_background_image_url'] = '';
|
||||||
$twitter_user['profile_text_color'] = '';
|
$twitter_user['profile_text_color'] = '';
|
||||||
$twitter_user['profile_link_color'] = '';
|
$twitter_user['profile_link_color'] = '';
|
||||||
$twitter_user['profile_sidebar_fill_color'] = '';
|
$twitter_user['profile_sidebar_fill_color'] = '';
|
||||||
|
$twitter_user['profile_sidebar_border_color'] = '';
|
||||||
|
$twitter_user['profile_background_tile'] = 'false';
|
||||||
|
|
||||||
$faves = DB_DataObject::factory('fave');
|
$faves = DB_DataObject::factory('fave');
|
||||||
$faves->user_id = $user->id;
|
$faves->user_id = $user->id;
|
||||||
@ -94,16 +101,25 @@ class TwitapiusersAction extends TwitterapiAction
|
|||||||
$twitter_user['utc_offset'] = $t->format('Z');
|
$twitter_user['utc_offset'] = $t->format('Z');
|
||||||
$twitter_user['time_zone'] = $timezone;
|
$twitter_user['time_zone'] = $timezone;
|
||||||
|
|
||||||
if (isset($this->auth_user)) {
|
if (isset($apidata['user'])) {
|
||||||
|
|
||||||
if ($this->auth_user->isSubscribed($profile)) {
|
if ($apidata['user']->isSubscribed($profile)) {
|
||||||
$twitter_user['following'] = 'true';
|
$twitter_user['following'] = 'true';
|
||||||
} else {
|
} else {
|
||||||
$twitter_user['following'] = 'false';
|
$twitter_user['following'] = 'false';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not implemented yet
|
// Notifications on?
|
||||||
|
$sub = Subscription::pkeyGet(array('subscriber' =>
|
||||||
|
$apidata['user']->id, 'subscribed' => $profile->id));
|
||||||
|
|
||||||
|
if ($sub) {
|
||||||
|
if ($sub->jabber || $sub->sms) {
|
||||||
|
$twitter_user['notifications'] = 'true';
|
||||||
|
} else {
|
||||||
$twitter_user['notifications'] = 'false';
|
$twitter_user['notifications'] = 'false';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($apidata['content-type'] == 'xml') {
|
if ($apidata['content-type'] == 'xml') {
|
||||||
@ -114,6 +130,12 @@ class TwitapiusersAction extends TwitterapiAction
|
|||||||
$this->init_document('json');
|
$this->init_document('json');
|
||||||
$this->show_json_objects($twitter_user);
|
$this->show_json_objects($twitter_user);
|
||||||
$this->end_document('json');
|
$this->end_document('json');
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// This is in case 'show' was called via /account/verify_credentials
|
||||||
|
// without a format (xml or json).
|
||||||
|
header('Content-Type: text/html; charset=utf-8');
|
||||||
|
print 'Authorized';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -228,14 +228,15 @@ class Router
|
|||||||
|
|
||||||
// users
|
// users
|
||||||
|
|
||||||
$m->connect('api/users/show/:argument',
|
$m->connect('api/users/:method/:argument',
|
||||||
array('action' => 'api',
|
array('action' => 'api',
|
||||||
'apiaction' => 'users'));
|
'apiaction' => 'users'),
|
||||||
|
array('method' => 'show(\.(xml|json))?'));
|
||||||
|
|
||||||
$m->connect('api/users/:method',
|
$m->connect('api/users/:method',
|
||||||
array('action' => 'api',
|
array('action' => 'api',
|
||||||
'apiaction' => 'users'),
|
'apiaction' => 'users'),
|
||||||
array('method' => 'show(\.(xml|json|atom|rss))?'));
|
array('method' => 'show(\.(xml|json))?'));
|
||||||
|
|
||||||
// direct messages
|
// direct messages
|
||||||
|
|
||||||
|
@ -60,20 +60,34 @@ class TwitterapiAction extends Action
|
|||||||
|
|
||||||
function twitter_status_array($notice, $include_user=true)
|
function twitter_status_array($notice, $include_user=true)
|
||||||
{
|
{
|
||||||
|
|
||||||
$profile = $notice->getProfile();
|
$profile = $notice->getProfile();
|
||||||
|
|
||||||
$twitter_status = array();
|
$twitter_status = array();
|
||||||
$twitter_status['text'] = $notice->content;
|
$twitter_status['text'] = $notice->content;
|
||||||
$twitter_status['truncated'] = 'false'; # Not possible on Laconica
|
$twitter_status['truncated'] = 'false'; # Not possible on Laconica
|
||||||
$twitter_status['created_at'] = $this->date_twitter($notice->created);
|
$twitter_status['created_at'] = $this->date_twitter($notice->created);
|
||||||
$twitter_status['in_reply_to_status_id'] = ($notice->reply_to) ? intval($notice->reply_to) : null;
|
$twitter_status['in_reply_to_status_id'] = ($notice->reply_to) ?
|
||||||
|
intval($notice->reply_to) : null;
|
||||||
$twitter_status['source'] = $this->source_link($notice->source);
|
$twitter_status['source'] = $this->source_link($notice->source);
|
||||||
$twitter_status['id'] = intval($notice->id);
|
$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;
|
|
||||||
|
$replier_profile = null;
|
||||||
|
|
||||||
|
if ($notice->reply_to) {
|
||||||
|
$reply = Notice::staticGet(intval($notice->reply_to));
|
||||||
|
if ($reply) {
|
||||||
|
$replier_profile = $reply->getProfile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$twitter_status['in_reply_to_user_id'] =
|
||||||
|
($replier_profile) ? intval($replier_profile->id) : null;
|
||||||
|
$twitter_status['in_reply_to_screen_name'] =
|
||||||
|
($replier_profile) ? $replier_profile->nickname : null;
|
||||||
|
|
||||||
if (isset($this->auth_user)) {
|
if (isset($this->auth_user)) {
|
||||||
$twitter_status['favorited'] = ($this->auth_user->hasFave($notice)) ? 'true' : 'false';
|
$twitter_status['favorited'] =
|
||||||
|
($this->auth_user->hasFave($notice)) ? 'true' : 'false';
|
||||||
} else {
|
} else {
|
||||||
$twitter_status['favorited'] = 'false';
|
$twitter_status['favorited'] = 'false';
|
||||||
}
|
}
|
||||||
@ -137,7 +151,6 @@ class TwitterapiAction extends Action
|
|||||||
|
|
||||||
function twitter_dmsg_array($message)
|
function twitter_dmsg_array($message)
|
||||||
{
|
{
|
||||||
|
|
||||||
$twitter_dm = array();
|
$twitter_dm = array();
|
||||||
|
|
||||||
$from_profile = $message->getFrom();
|
$from_profile = $message->getFrom();
|
||||||
@ -387,22 +400,6 @@ class TwitterapiAction extends Action
|
|||||||
return date("D M d G:i:s O Y", $t);
|
return date("D M d G:i:s O Y", $t);
|
||||||
}
|
}
|
||||||
|
|
||||||
function replier_by_reply($reply_id)
|
|
||||||
{
|
|
||||||
$notice = Notice::staticGet($reply_id);
|
|
||||||
if ($notice) {
|
|
||||||
$profile = $notice->getProfile();
|
|
||||||
if ($profile) {
|
|
||||||
return intval($profile->id);
|
|
||||||
} else {
|
|
||||||
common_debug('Can\'t find a profile for notice: ' . $notice->id, __FILE__);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
common_debug("Can't get notice: $reply_id", __FILE__);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX: Candidate for a general utility method somewhere?
|
// XXX: Candidate for a general utility method somewhere?
|
||||||
function count_subscriptions($profile)
|
function count_subscriptions($profile)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user