From f4358aa9469742b66546216bb76b279a44c512e9 Mon Sep 17 00:00:00 2001 From: jerome Date: Fri, 30 Jan 2009 04:57:49 +0000 Subject: [PATCH] web service MDL-12886 trivial refactoring --- webservice/amf/server.php | 16 ---------- .../{index.php => php_curl_rest_client.php} | 0 .../rest/testclient/zend_rest_client.php | 30 +++++++++---------- webservice/rest/zend_rest_server.php | 17 +++++++---- .../{index.php => php_soap_client.php} | 2 +- 5 files changed, 27 insertions(+), 38 deletions(-) rename webservice/rest/testclient/{index.php => php_curl_rest_client.php} (100%) rename webservice/soap/testclient/{index.php => php_soap_client.php} (99%) diff --git a/webservice/amf/server.php b/webservice/amf/server.php index 628dd6ba0f5..620e60c5fba 100644 --- a/webservice/amf/server.php +++ b/webservice/amf/server.php @@ -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; -} -*/ ?> \ No newline at end of file diff --git a/webservice/rest/testclient/index.php b/webservice/rest/testclient/php_curl_rest_client.php similarity index 100% rename from webservice/rest/testclient/index.php rename to webservice/rest/testclient/php_curl_rest_client.php diff --git a/webservice/rest/testclient/zend_rest_client.php b/webservice/rest/testclient/zend_rest_client.php index 19314ed8648..a21c195c667 100644 --- a/webservice/rest/testclient/zend_rest_client.php +++ b/webservice/rest/testclient/zend_rest_client.php @@ -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 "
\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 "
"; } diff --git a/webservice/rest/zend_rest_server.php b/webservice/rest/zend_rest_server.php index 65e6d4bf6ab..8db5e0d4905 100644 --- a/webservice/rest/zend_rest_server.php +++ b/webservice/rest/zend_rest_server.php @@ -1,6 +1,6 @@ * @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'); + } } } ?> \ No newline at end of file diff --git a/webservice/soap/testclient/index.php b/webservice/soap/testclient/php_soap_client.php similarity index 99% rename from webservice/soap/testclient/index.php rename to webservice/soap/testclient/php_soap_client.php index 4b0e00ca7b3..77366a9022f 100644 --- a/webservice/soap/testclient/index.php +++ b/webservice/soap/testclient/php_soap_client.php @@ -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; }