Skip to content
Snippets Groups Projects
Select Git revision
  • f33af71eb017fda5ea7e95270b92f1bca8835bbc
  • master default protected
2 results

hook.php

Blame
  • api.php 5.73 KiB
    <?php
    /**
    * ownCloud
    *
    * @author Tom Needham
    * @author Michael Gapczynski
    * @author Bart Visscher
    * @copyright 2012 Tom Needham tom@owncloud.com
    * @copyright 2012 Michael Gapczynski mtgap@owncloud.com
    * @copyright 2012 Bart Visscher bartv@thisnet.nl
    *
    * This library is free software; you can redistribute it and/or
    * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
    * License as published by the Free Software Foundation; either
    * version 3 of the License, or any later version.
    *
    * This library 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 library.  If not, see <http://www.gnu.org/licenses/>.
    *
    */
    
    class OC_API {
    
    	/**
    	 * API authentication levels
    	 */
    	const GUEST_AUTH = 0;
    	const USER_AUTH = 1;
    	const SUBADMIN_AUTH = 2;
    	const ADMIN_AUTH = 3;
    
    	private static $server;
    
    	/**
    	 * initialises the OAuth store and server
    	 */
    	private static function init() {
    		self::$server = new OC_OAuth_Server(new OC_OAuth_Store());
    	}
    
    	/**
    	 * api actions
    	 */
    	protected static $actions = array();
    
    	/**
    	 * registers an api call
    	 * @param string $method the http method
    	 * @param string $url the url to match
    	 * @param callable $action the function to run
    	 * @param string $app the id of the app registering the call
    	 * @param int $authLevel the level of authentication required for the call
    	 * @param array $defaults
    	 * @param array $requirements
    	 */
    	public static function register($method, $url, $action, $app,
    				$authLevel = OC_API::USER_AUTH,
    				$defaults = array(),
    				$requirements = array()) {
    		$name = strtolower($method).$url;
    		$name = str_replace(array('/', '{', '}'), '_', $name);
    		if(!isset(self::$actions[$name])) {
    			OC::getRouter()->useCollection('ocs');
    			OC::getRouter()->create($name, $url)
    				->method($method)