mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
web service MDL-12886 trivial refactoring
This commit is contained in:
parent
965a0eb68a
commit
f4358aa946
@ -27,22 +27,6 @@ $server = new Zend_Amf_Server();
|
||||
$server->setClass($classpath."_external");
|
||||
$response = $server->handle();
|
||||
echo $response;
|
||||
/*
|
||||
*
|
||||
|
||||
varlog("-- The Moodle AMF server is running --");
|
||||
//basic test server
|
||||
$server = new Zend_Amf_Server();
|
||||
$server->addFunction('hello');
|
||||
$response = $server->handle();
|
||||
echo $response;
|
||||
|
||||
|
||||
function hello($name, $greeting = 'The Moodle server say Hi to')
|
||||
{
|
||||
varlog($greeting . ', ' . $name);
|
||||
return $greeting . ', ' . $name;
|
||||
}
|
||||
*/
|
||||
|
||||
?>
|
@ -20,30 +20,30 @@ Zend_Loader::registerAutoload();
|
||||
$client = new Zend_Rest_Client($CFG->wwwroot."/webservice/rest/zend_rest_server.php");
|
||||
|
||||
|
||||
$token = $client->tmp_get_token(array('username' => "wsuser", 'password' => "wspassword"))->get();
|
||||
echo $token->response();
|
||||
$token = $token->response();
|
||||
printLastRequestResponse($client);
|
||||
$token = $client->tmp_get_token(array('username' => "wsuser", 'password' => "wspassword"))->get();
|
||||
echo $token->response();
|
||||
$token = $token->response();
|
||||
printLastRequestResponse($client);
|
||||
|
||||
|
||||
//2. test functions
|
||||
$client = new Zend_Rest_Client($CFG->wwwroot."/webservice/rest/zend_rest_server.php/?classpath=user&token=".$token);
|
||||
|
||||
var_dump($client->tmp_get_users(array('search' => "admin"))->get());
|
||||
printLastRequestResponse($client);
|
||||
var_dump($client->tmp_create_user(array('username' => "mockuser66",'firstname' => "firstname6",'lastname' => "lastname6",'email' => "mockuser6@mockuser6.com",'password' => "password6"))->get());
|
||||
printLastRequestResponse($client);
|
||||
var_dump($client->tmp_update_user(array('username' => "mockuser66",'mnethostid' => 1,'newusername' => "mockuser6b",'firstname' => "firstname6b"))->get());
|
||||
printLastRequestResponse($client);
|
||||
var_dump($client->tmp_delete_user(array('username' => "mockuser6b",'mnethostid' => 1))->get());
|
||||
printLastRequestResponse($client);
|
||||
|
||||
var_dump($client->tmp_get_users(array('search' => "admin"))->get());
|
||||
printLastRequestResponse($client);
|
||||
var_dump($client->tmp_create_user(array('username' => "mockuser66",'firstname' => "firstname6",'lastname' => "lastname6",'email' => "mockuser6@mockuser6.com",'password' => "password6"))->get());
|
||||
printLastRequestResponse($client);
|
||||
var_dump($client->tmp_update_user(array('username' => "mockuser66",'mnethostid' => 1,'newusername' => "mockuser6b",'firstname' => "firstname6b"))->get());
|
||||
printLastRequestResponse($client);
|
||||
var_dump($client->tmp_delete_user(array('username' => "mockuser6b",'mnethostid' => 1))->get());
|
||||
printLastRequestResponse($client);
|
||||
|
||||
|
||||
|
||||
function printLastRequestResponse($client) {
|
||||
print "<pre>\n";
|
||||
// print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
|
||||
// print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
|
||||
// print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
|
||||
// print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
|
||||
print "</pre>";
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/**
|
||||
* Main script - SOAP server
|
||||
* Main script - REST server
|
||||
*
|
||||
* @author Jerome Mouneyrac <jerome@moodle.com>
|
||||
* @version 1.0
|
||||
@ -38,7 +38,7 @@ if (empty($token)) {
|
||||
//retrieve the api name
|
||||
$classpath = optional_param(classpath,null,PARAM_ALPHA);
|
||||
require_once(dirname(__FILE__) . '/../../'.$classpath.'/external.php');
|
||||
|
||||
|
||||
/// run the server
|
||||
$server = new Zend_Rest_Server(); //TODO: need to call the wsdl generation on the fly
|
||||
$server->setClass($classpath."_external"); //TODO: pass $user as parameter
|
||||
@ -64,12 +64,17 @@ function mock_check_token($token) {
|
||||
}
|
||||
|
||||
class soap_authentication {
|
||||
/**
|
||||
*
|
||||
* @param array $params
|
||||
* @return integer
|
||||
*/
|
||||
function tmp_get_token($params) {
|
||||
if ($params['username'] == 'wsuser' && $params['password'] == 'wspassword') {
|
||||
return '465465465468468464';
|
||||
} else {
|
||||
throw new moodle_exception('wrongusernamepassword');
|
||||
}
|
||||
return '465465465468468464';
|
||||
} else {
|
||||
throw new moodle_exception('wrongusernamepassword');
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
@ -21,7 +21,7 @@ $client = new SoapClient($CFG->wwwroot."/webservice/soap/generatewsdl.php",array
|
||||
try {
|
||||
$token = $client->tmp_get_token(array('username' => "wsuser", 'password' => "wspassword"));
|
||||
printLastRequestResponse($client);
|
||||
|
||||
|
||||
} catch (SoapFault $exception) {
|
||||
echo $exception;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user