Index: json_server.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/json_server/json_server.module,v retrieving revision 1.8.2.1 diff -u -F^f -r1.8.2.1 json_server.module --- json_server.module 13 Jan 2008 16:12:23 -0000 1.8.2.1 +++ json_server.module 26 Feb 2009 22:47:25 -0000 @@ -9,47 +9,33 @@ function json_server_server_info() { } function json_server_server_error($message) { - return array("status" => FALSE, "message" => $message); + return array('error' => TRUE, 'message' => $message); } function json_server_server() { - if (!isset($_POST)) { + if (empty($_POST)) { return "JSON server accepts POST requests only."; } $request = $_POST['method']; - $methods = services_get_all(); - $args = array(); - foreach ($methods as $method) { + foreach (services_get_all() as $method) { if ($method['#method'] == $request) { unset($_POST['q']); unset($_POST['method']); $args = array(); foreach($method['#args'] as $arg) { - if(isset($_POST[$arg['#name']])) { - $args[] = $_POST[$arg['#name']]; - } - elseif($arg['#optional'] == 0) { - return drupal_to_js(array("status" => FALSE, "data" => "Argument ". $arg['#name'] ." not recieved")); - } - else { - $args[] = NULL; - } + $args[] = $_POST[$arg['#name']]; } $result = services_method_call($method['#method'], $args); - if (is_array($result) && isset($result['#error']) && $result['#error'] === TRUE) - return drupal_to_js(array('status' => FALSE, 'data' => $result['#message'])); - + if (is_array($result) && $result['error']) { + return drupal_to_js(array('status' => FALSE, 'data' => $result['message'])); + } + return drupal_to_js(array('status' => TRUE, 'data' => $result)); } } - return drupal_to_js(array('status' => FALSE, 'data' => "Invalid method $request")); + $error = services_error("Invalid method $request"); + return drupal_to_js($error); } -function json_load() { - global $base_url; - $path = drupal_get_path("module", "json_server"); - drupal_add_js($path ."/json_server.js"); - drupal_add_js(array('basePath' => base_path()), 'setting'); -} \ No newline at end of file