浏览代码

#758 REST service: key given in clear in the returned objects (incremented the API verion to 1.1)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2902 a333f486-631f-4898-b8df-5754b55c2be0
romainq 11 年之前
父节点
当前提交
f48a2e9719
共有 2 个文件被更改,包括 18 次插入5 次删除
  1. 9 4
      core/restservices.class.inc.php
  2. 9 1
      webservices/itoprest.examples.php

+ 9 - 4
core/restservices.class.inc.php

@@ -36,15 +36,19 @@ class ObjectResult
 {
 	public $code;
 	public $message;
+	public $class;
+	public $key;
 	public $fields;
 	
 	/**
 	 * Default constructor
 	 */
-	public function __construct()
+	public function __construct($sClass = null, $iId = null)
 	{
 		$this->code = RestResult::OK;
 		$this->message = '';
+		$this->class = $sClass;
+		$this->key = $iId;
 		$this->fields = array();
 	}
 
@@ -144,11 +148,10 @@ class RestResultWithObjects extends RestResult
 	 */
 	public function AddObject($iCode, $sMessage, $oObject, $aFields)
 	{
-		$oObjRes = new ObjectResult();
+		$oObjRes = new ObjectResult(get_class($oObject), $oObject->GetKey());
 		$oObjRes->code = $iCode;
 		$oObjRes->message = $sMessage;
 
-		$oObjRes->class = get_class($oObject);
 		foreach ($aFields as $sAttCode)
 		{
 			$oObjRes->AddField($oObject, $sAttCode);
@@ -233,8 +236,10 @@ class CoreServices implements iRestServiceProvider
 	 */
 	public function ListOperations($sVersion)
 	{
+		// 1.1 - In the reply, objects have a 'key' entry so that it is no more necessary to split class::key programmaticaly
+		//
 		$aOps = array();
-		if ($sVersion == '1.0')
+		if (in_array($sVersion, array('1.0', '1.1'))) 
 		{
 			$aOps[] = array(
 				'verb' => 'core/create',

+ 9 - 1
webservices/itoprest.examples.php

@@ -159,7 +159,15 @@ $aOperations = array(
 	),
 );
 
-$sUrl = "http://localhost/rest-services/webservices/rest.php?version=1.0";
+if (true)
+{
+	echo "Please edit the sample script and configure the server URL";
+	exit;
+}
+else
+{
+	$sUrl = "http://localhost/trunk/webservices/rest.php?version=1.1";
+}
 
 $aData = array();
 $aData['auth_user'] = 'admin';