Twitter-compatible API - checks for is_readonly() now work!

darcs-hash:20081024213745-462f3-7c26611e7f75265affafd471c3d66e02ec7e686e.gz
This commit is contained in:
zach 2008-10-24 17:37:45 -04:00
parent 18d4226ead
commit f8a73c157e
8 changed files with 34 additions and 100 deletions

View File

@ -166,19 +166,26 @@ class ApiAction extends Action {
$method = $_REQUEST['method'];
list($cmdtext, $fmt) = explode('.', $method);
# FIXME: probably need a table here, instead of this switch
static $write_methods = array(
'account' => array('update_location', 'update_delivery_device', 'end_session'),
'blocks' => array('create', 'destroy'),
'direct_messages' => array('create', 'destroy'),
'favorites' => array('create', 'destroy'),
'friendships' => array('create', 'destroy'),
'help' => array(),
'notifications' => array('follow', 'leave'),
'statuses' => array('update', 'destroy'),
'users' => array()
);
switch ($apiaction) {
case 'statuses':
switch ($cmdtext) {
case 'update':
case 'destroy':
return false;
default:
if (array_key_exists($apiaction, $write_methods)) {
common_debug("checking method");
if (!in_array($cmdtext, $write_methods[$apiaction])) {
return true;
}
default:
}
return false;
}
}
}

View File

@ -23,20 +23,6 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class TwitapiaccountAction extends TwitterapiAction {
function is_readonly() {
static $write_methods = array( 'update_location',
'update_delivery_device');
$cmdtext = explode('.', $this->arg('method'));
if (in_array($cmdtext[0], $write_methods)) {
return false;
}
return true;
}
function verify_credentials($args, $apidata) {
if ($apidata['content-type'] == 'xml') {

View File

@ -23,20 +23,6 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class Twitapidirect_messagesAction extends TwitterapiAction {
function is_readonly() {
static $write_methods = array( 'direct_messages',
'sent');
$cmdtext = explode('.', $this->arg('method'));
if (in_array($cmdtext[0], $write_methods)) {
return false;
}
return true;
}
function direct_messages($args, $apidata) {
parent::handle($args);
return $this->show_messages($args, $apidata, 'received');

View File

@ -23,19 +23,6 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class TwitapifavoritesAction extends TwitterapiAction {
function is_readonly() {
static $write_methods = array('favorites');
$cmdtext = explode('.', $this->arg('method'));
if (in_array($cmdtext[0], $write_methods)) {
return false;
}
return true;
}
function favorites($args, $apidata) {
parent::handle($args);

View File

@ -23,20 +23,6 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class TwitapifriendshipsAction extends TwitterapiAction {
function is_readonly() {
static $write_methods = array( 'create',
'destroy');
$cmdtext = explode('.', $this->arg('method'));
if (in_array($cmdtext[0], $write_methods)) {
return false;
}
return true;
}
function create($args, $apidata) {
parent::handle($args);

View File

@ -23,10 +23,6 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class TwitapihelpAction extends TwitterapiAction {
function is_readonly() {
return true;
}
/* Returns the string "ok" in the requested format with a 200 OK HTTP status code.
* URL:http://identi.ca/api/help/test.format
* Formats: xml, json

View File

@ -23,20 +23,6 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class TwitapistatusesAction extends TwitterapiAction {
function is_readonly() {
static $write_methods = array( 'update',
'destroy');
$cmdtext = explode('.', $this->arg('method'));
if (in_array($cmdtext[0], $write_methods)) {
return false;
}
return true;
}
function public_timeline($args, $apidata) {
parent::handle($args);
@ -242,6 +228,10 @@ class TwitapistatusesAction extends TwitterapiAction {
return;
}
foreach ($_POST as $p => $v) {
common_debug("_POST: $p = $v");
}
$this->auth_user = $apidata['user'];
$user = $this->auth_user;
$status = $this->trimmed('status');

View File

@ -23,10 +23,6 @@ require_once(INSTALLDIR.'/lib/twitterapi.php');
class TwitapiusersAction extends TwitterapiAction {
function is_readonly() {
return true;
}
function show($args, $apidata) {
parent::handle($args);