Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Version 0.7

  • Loading branch information...
commit 005238bef155e8ef253c3c43b9826cfc9102c689 1 parent c89f2dc
Mashape authored
View
2  README
@@ -1,4 +1,4 @@
-Mashape PHP library v0.6
+Mashape PHP library v0.7
Copyright (C) 2011 Mashape, Inc.
The Mashape PHP Library is:
View
2  api.xml
@@ -2,7 +2,7 @@
<api>
<method http="GET" name="sayHello" >
- <result type="simple" name="helloWorldMessage" />
+ <result type="simple" name="helloWorldMessage"/>
</method>
</api>
View
7 mashape/configuration/helpers/loadMethods.php
@@ -75,16 +75,17 @@ function loadMethodsFromXML($xmlParser) {
}
// Get the result
- $resultsNode = $xmlMethod->result;
+ $resultsNode = XmlParserUtils::getChildren($xmlMethod, "result"); //$xmlMethod->result;
$resultNode = null;
if (count($resultsNode) > 1) {
throw new MashapeException(sprintf(EXCEPTION_RESULT_MULTIPLE, $name), EXCEPTION_XML_CODE);
} elseif (count($resultsNode)==1) {
$resultNode = $resultsNode[0];
- } else {
- throw new MashapeException(sprintf(EXCEPTION_RESULT_MISSING, $name), EXCEPTION_XML_CODE);
}
+// else {
+// throw new MashapeException(sprintf(EXCEPTION_RESULT_MISSING, $name), EXCEPTION_XML_CODE);
+// }
$object = null;
$array = null;
View
6 mashape/exceptions/exceptionMessages.php
@@ -65,15 +65,15 @@
define("EXCEPTION_NOTSUPPORTED_OPERATION_CODE", 1004);
define("EXCEPTION_NOTSUPPORTED_OPERATION", "Operation not supported");
-define("EXCEPTION_AUTH_INVALID_SERVERKEY_CODE", 1005);
-define("EXCEPTION_AUTH_INVALID_SERVERKEY", "The request can't be authenticated because the server key sent for the request, and the one set in your implementation, don't match");
-
define("EXCEPTION_METHOD_NOTFOUND_CODE", 1006);
define("EXCEPTION_METHOD_NOTFOUND", "The method requested was not found: \"%s\"");
define("EXCEPTION_AUTH_INVALID_CODE", 1007);
define("EXCEPTION_AUTH_INVALID", "The request has not been authorized");
+define("EXCEPTION_AUTH_INVALID_SERVERKEY_CODE", 1005);
+define("EXCEPTION_AUTH_INVALID_SERVERKEY", "The request can't be authenticated because the server key sent for the request, and the one set in your implementation, don't match");
+
define("EXCEPTION_REQUIRED_PARAMETERS_CODE", 1008);
define("EXCEPTION_REQUIRED_PARAMETERS", "Some parameters required by the method are missing");
View
2  mashape/init/init.php
@@ -31,4 +31,4 @@
require_once(dirname(__FILE__) . "/../exceptions/mashapeException.php");
define("LIBRARY_LANGUAGE", "PHP");
-define("LIBRARY_VERSION", "V06");
+define("LIBRARY_VERSION", "V07");
View
2  mashape/json/jsonUtils.php
@@ -27,7 +27,7 @@
class JsonUtils {
public static function serializeError($message, $code) {
- return '{"errors":[{"message":' . self::encodeToJson($message) . ',"code":' . self::encodeToJson($code) . '}], "result":null}';
+ return '[{"message":' . self::encodeToJson($message) . ',"code":' . self::encodeToJson($code) . '}]';
}
public static function encodeToJson($text) {
View
17 mashape/methods/call/helpers/callHelper.php
@@ -30,22 +30,21 @@
function doCall($method, $parameters, $instance, $serverKey) {
$callParameters = validateCallParameters($method, $parameters, $instance);
-
+
$reflectedClass = new ReflectionClass(get_class($instance));
$reflectedMethod = $reflectedClass->getMethod($method->getName());
$result;
-
+
$result = $reflectedMethod->invokeArgs($instance, $callParameters);
- $resultJson = '{';
+ $resultJson = "";
//Print custom errors
$reflectedErrorMethod = $reflectedClass->getMethod("getErrors");
$reflectedErrors = $reflectedErrorMethod->invoke($instance);
- $resultJson .= '"errors":[';
-
if (!empty($reflectedErrors)) {
+ $resultJson .= "[";
foreach ($reflectedErrors as $reflectedError) {
$reflectedErrorClass = new ReflectionClass(get_class($reflectedError));
$code = $reflectedErrorClass->getMethod("getCode")->invoke($reflectedError);
@@ -53,11 +52,9 @@ function doCall($method, $parameters, $instance, $serverKey) {
$resultJson .= '{"code":' . JsonUtils::encodeToJson($code) . ',"message":' . JsonUtils::encodeToJson($message) . '},';
}
$resultJson = JsonUtils::removeLastChar($reflectedErrors, $resultJson);
+ $resultJson .= "]";
+ } else {
+ $resultJson .= serializeMethodResult($method, $result, $instance, $serverKey);
}
-
- $resultJson .= ']';
- $resultJson .= ',"result":';
- $resultJson .= serializeMethodResult($method, $result, $instance, $serverKey);
- $resultJson .= '}';
return $resultJson;
}
View
14 mashape/methods/call/helpers/serializeMethodResult.php
@@ -34,13 +34,17 @@
function serializeMethodResult($method, $result, $instance, $serverKey) {
$json = "";
+ if (isNoResult($method)) {
+ return "{}";
+ }
+
$isSimpleResult = isSimpleResult($method);
if ($result === null) {
if($isSimpleResult) {
$json .= '{"' . $method->getResult() . '":null}';
} else {
- $json .= "null";
+ $json .= "{}";
}
} else {
if ($isSimpleResult) {
@@ -68,6 +72,14 @@ function serializeMethodResult($method, $result, $instance, $serverKey) {
return $json;
}
+function isNoResult($method) {
+ $resultName = $method->getResult();
+ $objectName = $method->getObject();
+ if (empty($resultName) && empty($objectName)) {
+ return true;
+ }
+ return false;
+}
function isSimpleResult($method) {
$resultName = $method->getResult();
$objectName = $method->getObject();
View
49 mashape/methods/discover/discover.php
@@ -44,38 +44,57 @@ public function handle($instance, $serverKey, $parameters, $httpRequestMethod) {
if (strtolower($httpRequestMethod) != "get") {
throw new MashapeException(EXCEPTION_INVALID_HTTPMETHOD, EXCEPTION_INVALID_HTTPMETHOD_CODE);
}
+
// Validate request
if ($this->validateRequest($serverKey) == false) {
throw new MashapeException(EXCEPTION_AUTH_INVALID_SERVERKEY, EXCEPTION_AUTH_INVALID_SERVERKEY_CODE);
}
- $resultJson = "{";
+ $resultXml = "<?xml version=\"1.0\" ?>\n";
+
+ $fileParts = Explode('/', $_SERVER["PHP_SELF"]);
+ $scriptName = $fileParts[count($fileParts) - 1];
+
+ $baseUrl = Explode("/" . $scriptName, $this->curPageURL());
+ $resultXml .= "<api baseUrl=\"" . $baseUrl[0] . "\" " . $this->getSimpleInfo() . ">\n";
$mode = (isset($parameters[MODE])) ? $parameters[MODE] : null;
-
+
$configuration = RESTConfigurationLoader::reloadConfiguration($serverKey);
if ($mode == null || $mode != SIMPLE_MODE) {
$objectsFound = array();
- $methods = discoverMethods($instance, $configuration, $objectsFound);
+ $objectsToCreate = array();
+
+ $methods = discoverMethods($instance, $configuration, $objectsFound, $objectsToCreate, $scriptName);
$objects = discoverObjects($configuration, $objectsFound);
- $resultJson .= $methods . "," . $objects . "," . $this->getSimpleInfo();
-
+ $resultXml .= $methods . $objects . generateObjects($objectsToCreate);
+
// Update the .htaccess file with the new route settings
updateHtaccess($instance);
-
- } else {
- $resultJson .= $this->getSimpleInfo();
+
}
- $resultJson .= "}";
+ $resultXml .= "</api>";
- return $resultJson;
+ return $resultXml;
}
-
+
private function getSimpleInfo() {
- $libraryVersion = '"version":"' . LIBRARY_VERSION . '"';
- $libraryLanguage = '"language":"' . LIBRARY_LANGUAGE . '"';
-
- return $libraryLanguage . "," . $libraryVersion;
+ $libraryLanguage = "language=\"" . LIBRARY_LANGUAGE . "\"";
+ $libraryVersion = " version=\"" . LIBRARY_VERSION . "\"";
+
+ return $libraryLanguage . $libraryVersion;
+ }
+
+ private function curPageURL() {
+ $pageURL = 'http';
+ if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
+ $pageURL .= "://";
+ if (isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"] != "80") {
+ $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
+ } else {
+ $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
+ }
+ return $pageURL;
}
private function validateRequest($serverKey) {
View
94 mashape/methods/discover/helpers/discoverMethods.php
@@ -27,58 +27,93 @@
require_once(dirname(__FILE__) . "/../../../json/jsonUtils.php");
require_once(dirname(__FILE__) . "/../../../utils/routeUtils.php");
-function discoverMethods($instance, $configuration, &$objectsFound) {
+function discoverMethods($instance, $configuration, &$objectsFound, &$objectsToCreate, $scriptName) {
// Serialize methods
- $result = '"methods":[';
+ $result = "";
$methods = $configuration->getMethods();
foreach($methods as $method) {
- $result .= "{";
+ $result .= "\t<method ";
$name = $method->getName();
- $result .= '"name":"' . $name . '",';
- $object = $method->getObject();
+ $result .= 'name="' . $name . '"';
+ $http = $method->getHttp();
+ $result .= " http=\"" . strtoupper($http) . "\">\n";
$route = $method->getRoute();
- if (empty($object)) {
- $result .= '"object":null,';
- } else {
- $result .= '"object":"' . $object . '",';
- array_push($objectsFound, $object);
- }
+
+ $result .= "\t\t<url><![CDATA[";
if (empty($route)) {
- $result .= '"route":null,';
+ $result .= "/" . $scriptName . "?_method=" . $name . serializeParametersQueryString($method, $instance);
} else {
- $result .= '"route":"' . $route . '",';
+ $result .= $route;
}
+ $result .= "]]></url>\n";
+ $result .= serializeParameters($method, $instance);
+
+ $object = $method->getObject();
$resultName = $method->getResult();
- if (empty($resultName)) {
- $result .= '"result":null,';
- } else {
- $result .= '"result":"' . $resultName . '",';
+
+ if (!empty($object)) {
+ $result .= "\t\t<result object=\"" . $object . "\"";
+ array_push($objectsFound, $object);
+ }
+
+ if (!empty($resultName)) {
+ $uniqueName = findUniqueObjectName($objectsToCreate, $resultName, 0);
+ $result .= "\t\t<result object=\"" . $uniqueName . "\"";
+ $objectsToCreate[$uniqueName] = $resultName;
}
+
$array = $method->isArray();
- $result .= '"array":' . ($array ? "true" : "false") . ',';
- $http = $method->getHttp();
- $result .= '"http":"' . $http . '",';
- $result .= serializeParameters($method, $instance);
+ $result .= " array=\"" . ($array ? "true" : "false") . "\" />\n";
- $result .= "},";
+ $result .= "\t\t<error object=\"StandardMashapeError\" array=\"true\" />\n";
+
+ $result .= "\t</method>\n";
}
- // Remove the last comma
- $result = JsonUtils::removeLastChar($methods, $result);
- $result .= "]";
return $result;
}
-function serializeParameters($method, $instance) {
+function findUniqueObjectName($objects, $name, $index) {
+ $numeratedName = $name;
+ if ($index > 0) {
+ $numeratedName .= $index;
+ }
+ $keys = array_keys($objects);
+ foreach ($keys as $key) {
+ if ($key == $numeratedName) {
+ return findUniqueObjectName($objects, $name, $index + 1);
+ }
+ }
+ return $numeratedName;
+}
+
+function serializeParametersQueryString($method, $instance) {
$reflectedClass = new ReflectionClass(get_class($instance));
$reflectedMethod = $reflectedClass->getMethod($method->getName());
$reflectedParameters = $reflectedMethod->getParameters();
- $result = '"parameters":[';
+ $result = "";
for ($i=0;$i<count($reflectedParameters);$i++) {
$param = $reflectedParameters[$i];
- $result .= '{"name":"' . $param->name . '", "optional":' . ($param->isDefaultValueAvailable() ? "true" : "false") . ',"index":' . $i . '},';
+ if ($i == 0) {
+ $result .= "&";
+ }
+ $result .= $param->name . "={" . $param->name . "}&";
}
- // Remove the last comma
+
$result = JsonUtils::removeLastChar($reflectedParameters, $result);
+ return $result;
+}
+
+function serializeParameters($method, $instance) {
+ $reflectedClass = new ReflectionClass(get_class($instance));
+ $reflectedMethod = $reflectedClass->getMethod($method->getName());
+ $reflectedParameters = $reflectedMethod->getParameters();
+ $result = "\t\t<parameters>\n";
+ for ($i=0;$i<count($reflectedParameters);$i++) {
+ $param = $reflectedParameters[$i];
+ $result .= "\t\t\t<parameter optional=\"" . ($param->isDefaultValueAvailable() ? "true" : "false") . "\">" . $param->name . "</parameter>\n";
+ }
+
+ $result .= "\t\t</parameters>\n";
// Check route parameters
$route = $method->getRoute();
@@ -105,6 +140,5 @@ function serializeParameters($method, $instance) {
}
}
- $result .= ']';
return $result;
}
View
51 mashape/methods/discover/helpers/discoverObjects.php
@@ -27,50 +27,59 @@
require_once(dirname(__FILE__) . "/../../../json/jsonUtils.php");
require_once(dirname(__FILE__) . "/../../../exceptions/mashapeException.php");
+function generateObjects($objectsToCreate) {
+ $result = "";
+
+ $keys = array_keys($objectsToCreate);
+
+ foreach ($keys as $key) {
+ $result .= "\t<object ";
+ $result .= "name=\"" . $key . "\">\n";
+ $result .= "\t\t<field>" . $objectsToCreate[$key] . "</field>\n";
+ $result .= "\t</object>\n";
+ }
+
+ return $result;
+}
+
+
function discoverObjects($configuration, $objectsFound) {
- $result = '"objects":[';
+ $result = "";
$objects = $configuration->getObjects();
$objectsDone = array();
foreach ($objects as $object) {
- $result .= "{";
+ $result .= "\t<object ";
$className = $object->getClassName();
- $result .= '"class":"' . $className . '",';
- $result .= '"fields":[';
+ $result .= "name=\"" . $className . "\" >\n";
foreach($object->getFields() as $field) {
- $result .= "{";
+ $result .= "\t\t<field";
- $fieldName = $field->getName();
- $result .= '"name":"' . $fieldName . '",';
$objectName = $field->getObject();
if ($objectName != null) {
if (!in_array($objectName, $objectsFound) && !in_array($objectName, $objectsDone)) {
array_push($objectsFound, $objectName);
}
}
- $result .= '"object":' . (empty($objectName) ? "null" : '"' . $objectName . '"') . ',';
- $methodName = $field->getMethod();
- $result .= '"method":' . (empty($methodName) ? "null" : '"' . $methodName . '"') . ',';
- $result .= '"array":' . ($field->isArray() ? "true" : "false") . ",";
- $result .= '"optional":' . ($field->isOptional() ? "true" : "false");
-
- $result .= "},";
+ if (!empty($objectName)) {
+ $result .= " object=\"" . $objectName . "\"";
+ }
+ $result .= " array=\"" . ($field->isArray() ? "true" : "false") . "\"";
+ $result .= " optional=\"" . ($field->isOptional() ? "true" : "false") . "\"";
+ $fieldName = $field->getName();
+ $result .= ">" . $fieldName . "</field>\n";
}
- // Remove the last comma
- $result = JsonUtils::removeLastChar($object->getFields(), $result);
- $result .= ']';
- $result .= "},";
+ $result .= "\t</object>\n";
array_push($objectsDone, $className);
$objectsFound = array_diff($objectsFound, array($className));
}
- // Remove the last comma
- $result = JsonUtils::removeLastChar($objects, $result);
- $result .= ']';
+
+ $result .= "\t<object name=\"StandardMashapeError\">\n\t\t<field>code</field>\n\t\t<field>message</field>\n\t</object>\n";
// Check that all objects exist
if (!empty($objectsFound)) {
View
8 mashape/methods/handler.php
@@ -85,6 +85,7 @@ public static function handleAPI($instance, $serverKey) {
$result;
switch (strtolower($operation)) {
case "discover":
+ header("Content-type: application/xml");
$discover = new Discover();
$result = $discover->handle($instance, $serverKey, $params, $requestMethod);
break;
@@ -116,6 +117,7 @@ public static function handleAPI($instance, $serverKey) {
} catch (Exception $e) {
//If it's an ApizatorException then print the specific code
if ($e instanceof MashapeException) {
+ header("Content-type: application/json");
$code = $e->getCode();
switch ($code) {
case EXCEPTION_XML_CODE:
@@ -130,15 +132,15 @@ public static function handleAPI($instance, $serverKey) {
case EXCEPTION_NOTSUPPORTED_OPERATION_CODE:
header("HTTP/1.0 501 Not Implemented");
break;
- case EXCEPTION_AUTH_INVALID_SERVERKEY_CODE:
- self::setUnauthorizedResponse();
- break;
case EXCEPTION_METHOD_NOTFOUND_CODE:
header("HTTP/1.0 200 OK");
break;
case EXCEPTION_AUTH_INVALID_CODE:
self::setUnauthorizedResponse();
break;
+ case EXCEPTION_AUTH_INVALID_SERVERKEY_CODE:
+ self::setUnauthorizedResponse();
+ break;
case EXCEPTION_REQUIRED_PARAMETERS_CODE:
header("HTTP/1.0 200 OK");
break;
View
6 mashape/utils/routeUtils.php
@@ -32,8 +32,10 @@ public static function getRoutePlaceholder($val) {
public static function isRoutePlaceholder($val) {
if (!empty($val)) {
- if (substr($val, 0, 1) == "{" && substr($val, strlen($val) - 1, 1) == "}") {
- return true;
+ if (strlen($val) >= 2) {
+ if (substr($val, 0, 1) == "{" && substr($val, strlen($val) - 1, 1) == "}") {
+ return true;
+ }
}
}
return false;
View
2  tests/bootstrap.php
@@ -1,7 +1,7 @@
<?php
/**
- * Initialise testing environment
+ * Initialize testing environment
*
* @author Devis Lucato <devis@lucato.it>
*/
View
8 tests/json/jsonUtilsTest.php
@@ -29,9 +29,9 @@
class JsonUtilsTest extends PHPUnit_Framework_TestCase
{
function testSerializeError() {
- $this->assertEquals('{"errors":[{"message":"this is an error","code":2}], "result":null}', JsonUtils::serializeError("this is an error", 2));
- $this->assertEquals('{"errors":[{"message":"this is an error","code":null}], "result":null}', JsonUtils::serializeError("this is an error", null));
- $this->assertEquals('{"errors":[{"message":null,"code":null}], "result":null}', JsonUtils::serializeError(null, null));
- $this->assertEquals('{"errors":[{"message":"this is a \"great\" error","code":2}], "result":null}', JsonUtils::serializeError('this is a "great" error', 2));
+ $this->assertEquals('[{"message":"this is an error","code":2}]', JsonUtils::serializeError("this is an error", 2));
+ $this->assertEquals('[{"message":"this is an error","code":null}]', JsonUtils::serializeError("this is an error", null));
+ $this->assertEquals('[{"message":null,"code":null}]', JsonUtils::serializeError(null, null));
+ $this->assertEquals('[{"message":"this is a \"great\" error","code":2}]', JsonUtils::serializeError('this is a "great" error', 2));
}
}
View
33 tests/methods/call/helpers/callHelperTest.php
@@ -37,26 +37,26 @@ function testNull() {
$method = new RESTMethod();
$method->setName("touchNull");
$method->setResult("message");
- $this->assertEquals('{"errors":[],"result":{"message":null}}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
+ $this->assertEquals('{"message":null}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
// Test NULL Object
$method = new RESTMethod();
$method->setName("touchNull");
$method->setObject("Ret");
- $this->assertEquals('{"errors":[],"result":null}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
+ $this->assertEquals('{}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
}
function testSimple() {
$method = new RESTMethod();
$method->setName("touchSimple");
$method->setResult("message");
- $this->assertEquals('{"errors":[],"result":{"message":"simpleValue"}}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
+ $this->assertEquals('{"message":"simpleValue"}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
$method = new RESTMethod();
$method->setName("touchSimpleArray");
$method->setResult("message");
$method->setArray(true);
- $this->assertEquals('{"errors":[],"result":{"message":["value1",3,"value3"]}}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
+ $this->assertEquals('{"message":["value1",3,"value3"]}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
}
function testComplex() {
@@ -64,68 +64,68 @@ function testComplex() {
$method = new RESTMethod();
$method->setName("touchComplex");
$method->setObject("ClassOne");
- $this->assertEquals('{"errors":[],"result":{"field1":"value1","field2":"value2"}}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
+ $this->assertEquals('{"field1":"value1","field2":"value2"}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
RESTConfigurationLoader::reloadConfiguration(SERVER_KEY, dirname(__FILE__) . "/test2.xml");
$method = new RESTMethod();
$method->setName("touchComplex2");
$method->setObject("ClassOne");
- $this->assertEquals('{"errors":[],"result":{"field2":"value2"}}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
+ $this->assertEquals('{"field2":"value2"}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
RESTConfigurationLoader::reloadConfiguration(SERVER_KEY, dirname(__FILE__) . "/test3.xml");
$method = new RESTMethod();
$method->setName("touchComplex3");
$method->setObject("ClassOne");
- $this->assertEquals('{"errors":[],"result":{"field1":"value1","field2":{"childField1":"child value 1","childField2":"child value 2"}}}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
+ $this->assertEquals('{"field1":"value1","field2":{"childField1":"child value 1","childField2":"child value 2"}}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
RESTConfigurationLoader::reloadConfiguration(SERVER_KEY, dirname(__FILE__) . "/test3.xml");
$method = new RESTMethod();
$method->setName("touchComplex4");
$method->setObject("ClassOne");
- $this->assertEquals('{"errors":[],"result":{"field1":"value1","field2":null}}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
+ $this->assertEquals('{"field1":"value1","field2":null}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
RESTConfigurationLoader::reloadConfiguration(SERVER_KEY, dirname(__FILE__) . "/test4.xml");
$method = new RESTMethod();
$method->setName("touchComplex5");
$method->setObject("ClassOne");
- $this->assertEquals('{"errors":[],"result":{"field1":["value1",3,"value3"]}}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
+ $this->assertEquals('{"field1":["value1",3,"value3"]}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
RESTConfigurationLoader::reloadConfiguration(SERVER_KEY, dirname(__FILE__) . "/test5.xml");
$method = new RESTMethod();
$method->setName("touchComplex6");
$method->setObject("ClassOne");
- $this->assertEquals('{"errors":[],"result":{"field1":[{"childField1":"child value 1","childField2":"child value 2"},{"childField1":"second child value 1","childField2":"second child value 2"}]}}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
+ $this->assertEquals('{"field1":[{"childField1":"child value 1","childField2":"child value 2"},{"childField1":"second child value 1","childField2":"second child value 2"}]}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
RESTConfigurationLoader::reloadConfiguration(SERVER_KEY, dirname(__FILE__) . "/test6.xml");
$method = new RESTMethod();
$method->setName("touchComplex7");
$method->setObject("ClassThree");
- $this->assertEquals('{"errors":[],"result":{"field1":"this is field1","field2":["this","is","field",2,true],"field4":[{"field1":"child value 1","field2":"child value 2"},{"field1":"second child value 1","field2":"second child value 2"}]}}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
+ $this->assertEquals('{"field1":"this is field1","field2":["this","is","field",2,true],"field4":[{"field1":"child value 1","field2":"child value 2"},{"field1":"second child value 1","field2":"second child value 2"}]}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
RESTConfigurationLoader::reloadConfiguration(SERVER_KEY, dirname(__FILE__) . "/test.xml");
$method = new RESTMethod();
$method->setName("touchComplex8");
$method->setObject("ClassOne");
$method->setArray(true);
- $this->assertEquals('{"errors":[],"result":[{"field1":"value1","field2":"value2"},{"field1":"second value1","field2":"second value2"},{"field1":"third value1","field2":"third value2"}]}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
+ $this->assertEquals('[{"field1":"value1","field2":"value2"},{"field1":"second value1","field2":"second value2"},{"field1":"third value1","field2":"third value2"}]', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
$method = new RESTMethod();
$method->setName("touchComplex9");
$method->setArray(true);
$method->setResult("val");
- $this->assertEquals('{"errors":[],"result":{"val":["ciao","marco",false]}}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
+ $this->assertEquals('{"val":["ciao","marco",false]}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
$method = new RESTMethod();
$method->setName("touchComplex10");
$method->setArray(true);
$method->setResult("val");
- $this->assertEquals('{"errors":[],"result":{"val":{"key1":"value1","key2":"value2","key3":{"nested1":"nv1","nested2":"nv2"}}}}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
+ $this->assertEquals('{"val":{"key1":"value1","key2":"value2","key3":{"nested1":"nv1","nested2":"nv2"}}}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
$method = new RESTMethod();
$method->setName("touchComplex11");
$method->setArray(true);
$method->setResult("val");
- $this->assertEquals('{"errors":[],"result":{"val":{"key1":"value1","key2":"value2","key3":{"nested1":"nv1","nested2":{"yo1":"vyo1","yo2":[1,2,3]}}}}}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
+ $this->assertEquals('{"val":{"key1":"value1","key2":"value2","key3":{"nested1":"nv1","nested2":{"yo1":"vyo1","yo2":[1,2,3]}}}}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
}
function testError() {
@@ -134,10 +134,11 @@ function testError() {
$method->setName("touchError");
$method->setObject("ClassOne");
$method->setArray(true);
- $this->assertEquals('{"errors":[{"code":1,"message":"custom message"}],"result":null}', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
+ $this->assertEquals('[{"code":1,"message":"custom message"}]', doCall($method, null, new NewSampleAPI(), SERVER_KEY));
}
}
+
class ClassOne {
public $field1;
public $field2;
Please sign in to comment.
Something went wrong with that request. Please try again.