summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2009-10-09 13:35:54 -0700
committerZach Copley <zach@status.net>2009-10-09 13:35:54 -0700
commit09f4d1ef236c160afe6b9874793e43b501e1120a (patch)
tree08059f04610c1754addb611a6ce3e113c7c2d42d
parentada84698f2e82c1c659d872dea0c4545ef93509a (diff)
New actions for blocks via API
-rw-r--r--actions/apiblockcreate.php121
-rw-r--r--actions/apiblockdestroy.php120
-rw-r--r--actions/twitapiblocks.php74
-rw-r--r--actions/twitapihelp.php57
-rw-r--r--lib/router.php11
5 files changed, 249 insertions, 134 deletions
diff --git a/actions/apiblockcreate.php b/actions/apiblockcreate.php
new file mode 100644
index 000000000..ff303863e
--- /dev/null
+++ b/actions/apiblockcreate.php
@@ -0,0 +1,121 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Block a user via the API
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category API
+ * @package StatusNet
+ * @author Zach Copley <zach@status.net>
+ * @copyright 2009 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+ exit(1);
+}
+
+require_once INSTALLDIR . '/lib/apiauth.php';
+
+/**
+ * Blocks the user specified in the ID parameter as the authenticating user.
+ * Destroys a friendship to the blocked user if it exists. Returns the
+ * blocked user in the requested format when successful.
+ *
+ * @category API
+ * @package StatusNet
+ * @author Zach Copley <zach@status.net>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ */
+
+class ApiBlockCreateAction extends ApiAuthAction
+{
+ var $format = null;
+ var $user = null;
+ var $other = null;
+
+ /**
+ * Take arguments for running
+ *
+ * @param array $args $_REQUEST args
+ *
+ * @return boolean success flag
+ *
+ */
+
+ function prepare($args)
+ {
+ parent::prepare($args);
+
+ if ($this->requiresAuth()) {
+ if ($this->checkBasicAuthUser() == false) {
+ return;
+ }
+ }
+
+ $this->user = $this->auth_user;
+ $this->other = $this->getTargetUser($this->arg('id'));
+ $this->format = $this->arg('format');
+
+ return true;
+ }
+
+ /**
+ * Handle the request
+ *
+ * Save the new message
+ *
+ * @param array $args $_REQUEST data (unused)
+ *
+ * @return void
+ */
+
+ function handle($args)
+ {
+ parent::handle($args);
+
+ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ $this->clientError(
+ _('This method requires a POST.'),
+ 400,
+ $this->format
+ );
+ return;
+ }
+
+ if (empty($this->user) || empty($this->other)) {
+ $this->clientError(_('No such user!'), 404, $this->format);
+ return;
+ }
+
+ if ($this->user->hasBlocked($this->other)
+ || $this->user->block($this->other)
+ ) {
+ $this->init_document($this->format);
+ $this->show_profile($this->other, $this->format);
+ $this->end_document($this->format);
+ } else {
+ $this->serverError(_('Block user failed.'), 500, $this->format);
+ }
+
+ }
+
+}
+
diff --git a/actions/apiblockdestroy.php b/actions/apiblockdestroy.php
new file mode 100644
index 000000000..0f24be3aa
--- /dev/null
+++ b/actions/apiblockdestroy.php
@@ -0,0 +1,120 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ *
+ * Un-block a user via the API
+ *
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @category API
+ * @package StatusNet
+ * @author Zach Copley <zach@status.net>
+ * @copyright 2009 StatusNet, Inc.
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ */
+
+if (!defined('STATUSNET')) {
+ exit(1);
+}
+
+require_once INSTALLDIR . '/lib/apiauth.php';
+
+/**
+ * Un-blocks the user specified in the ID parameter for the authenticating user.
+ * Returns the un-blocked user in the requested format when successful.
+ *
+ * @category API
+ * @package StatusNet
+ * @author Zach Copley <zach@status.net>
+ * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link http://status.net/
+ */
+
+class ApiBlockDestroyAction extends ApiAuthAction
+{
+ var $format = null;
+ var $user = null;
+ var $other = null;
+
+ /**
+ * Take arguments for running
+ *
+ * @param array $args $_REQUEST args
+ *
+ * @return boolean success flag
+ *
+ */
+
+ function prepare($args)
+ {
+ parent::prepare($args);
+
+ if ($this->requiresAuth()) {
+ if ($this->checkBasicAuthUser() == false) {
+ return;
+ }
+ }
+
+ $this->user = $this->auth_user;
+ $this->other = $this->getTargetUser($this->arg('id'));
+ $this->format = $this->arg('format');
+
+ return true;
+ }
+
+ /**
+ * Handle the request
+ *
+ * Save the new message
+ *
+ * @param array $args $_REQUEST data (unused)
+ *
+ * @return void
+ */
+
+ function handle($args)
+ {
+ parent::handle($args);
+
+ if ($_SERVER['REQUEST_METHOD'] != 'POST') {
+ $this->clientError(
+ _('This method requires a POST.'),
+ 400,
+ $this->format
+ );
+ return;
+ }
+
+ if (empty($this->user) || empty($this->other)) {
+ $this->clientError(_('No such user!'), 404, $this->format);
+ return;
+ }
+
+ if (!$this->user->hasBlocked($this->other)
+ || $this->user->unblock($this->other)
+ ) {
+ $this->init_document($this->format);
+ $this->show_profile($this->other, $this->format);
+ $this->end_document($this->format);
+ } else {
+ $this->serverError(_('Unblock user failed.'));
+ }
+
+ }
+
+}
+
diff --git a/actions/twitapiblocks.php b/actions/twitapiblocks.php
deleted file mode 100644
index ed17946ae..000000000
--- a/actions/twitapiblocks.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-/*
- * StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2008, 2009, StatusNet, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
-}
-
-require_once(INSTALLDIR.'/lib/twitterapi.php');
-
-class TwitapiblocksAction extends TwitterapiAction
-{
-
- function create($args, $apidata)
- {
-
- parent::handle($args);
-
- $blockee = $this->get_user($apidata['api_arg'], $apidata);
-
- if (empty($blockee)) {
- $this->clientError('Not Found', 404, $apidata['content-type']);
- return;
- }
-
- $user = $apidata['user']; // Always the auth user
-
- if ($user->hasBlocked($blockee) || $user->block($blockee)) {
- $type = $apidata['content-type'];
- $this->init_document($type);
- $this->show_profile($blockee, $type);
- $this->end_document($type);
- } else {
- $this->serverError(_('Block user failed.'));
- }
- }
-
- function destroy($args, $apidata)
- {
- parent::handle($args);
- $blockee = $this->get_user($apidata['api_arg'], $apidata);
-
- if (empty($blockee)) {
- $this->clientError('Not Found', 404, $apidata['content-type']);
- return;
- }
-
- $user = $apidata['user'];
-
- if (!$user->hasBlocked($blockee) || $user->unblock($blockee)) {
- $type = $apidata['content-type'];
- $this->init_document($type);
- $this->show_profile($blockee, $type);
- $this->end_document($type);
- } else {
- $this->serverError(_('Unblock user failed.'));
- }
- }
-} \ No newline at end of file
diff --git a/actions/twitapihelp.php b/actions/twitapihelp.php
deleted file mode 100644
index 81381620e..000000000
--- a/actions/twitapihelp.php
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php
-/*
- * StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2008, 2009, StatusNet, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-if (!defined('STATUSNET') && !defined('LACONICA')) {
- exit(1);
-}
-
-require_once(INSTALLDIR.'/lib/twitterapi.php');
-
-class TwitapihelpAction extends TwitterapiAction
-{
-
- /* 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
- */
- function test($args, $apidata)
- {
- parent::handle($args);
-
- if ($apidata['content-type'] == 'xml') {
- $this->init_document('xml');
- $this->element('ok', null, 'true');
- $this->end_document('xml');
- } elseif ($apidata['content-type'] == 'json') {
- $this->init_document('json');
- print '"ok"';
- $this->end_document('json');
- } else {
- $this->clientError(_('API method not found!'), $code=404);
- }
-
- }
-
- function downtime_schedule($args, $apidata)
- {
- parent::handle($args);
- $this->serverError(_('API method under construction.'), $code=501);
- }
-
-} \ No newline at end of file
diff --git a/lib/router.php b/lib/router.php
index cf5c06b26..11f913f6e 100644
--- a/lib/router.php
+++ b/lib/router.php
@@ -474,10 +474,15 @@ class Router
// blocks
- $m->connect('api/blocks/:method/:argument',
- array('action' => 'api',
- 'apiaction' => 'blocks'));
+ $m->connect('api/blocks/create/:id.:format',
+ array('action' => 'ApiBlockCreate',
+ 'id' => '[a-zA-Z0-9]+',
+ 'format' => '(xml|json)'));
+ $m->connect('api/blocks/destroy/:id.:format',
+ array('action' => 'ApiBlockDestroy',
+ 'id' => '[a-zA-Z0-9]+',
+ 'format' => '(xml|json)'));
// help
$m->connect('api/help/test.:format',