'REST', 'path' => 'rest', ); } function rest_server_server() { $endpoint_path = services_get_server_info('endpoint_path', 'services/rest'); $canonical_path = trim(substr($_GET['q'], drupal_strlen($endpoint_path)), '/'); $canonical_path = explode('/', $_GET['q']); $endpoint_path_count = count(explode('/', $endpoint_path)); for($x=0; $x<$endpoint_path_count;$x++) { array_shift($canonical_path); } $canonical_path = implode('/', $canonical_path); if (empty($canonical_path)) { return ''; } try { $server = new RESTServer(); return $server->handle($canonical_path, $endpoint_path); } catch (Exception $e) { $code = $e->getCode(); switch($code) { case 401: drupal_add_http_header('HTTP/1.0 401 Unauthorized', $e->getMessage()); break; case 404: drupal_add_http_header('HTTP/1.0 404 Not found', $e->getMessage()); break; case 406: drupal_add_http_header('HTTP/1.0 406 Not Acceptable', $e->getMessage()); break; default: if ($code >= 400 && $code < 600) { drupal_add_http_header('HTTP/1.0 ' . $code, $e->getMessage()); } else { drupal_add_http_header('HTTP/1.0 500 An error occurred: (' . $code . ')', $e->getMessage()); } break; } } } /** * Implementation of hook_services_resources_alter(). */ function rest_server_services_resources_alter($resources, $endpoint) { // Set the default models for the retrieve and index controllers in the node // resource if they are not already set. if (isset($resources['node'])) { if (isset($resources['node']['retrieve'])) { if (!isset($resources['node']['retrieve']['models'])) { $resources['node']['retrieve']['models'] = array(); } $resources['node']['retrieve']['models'] += array( 'ResourceFeedModel' => array( 'class' => 'NodeResourceFeedModel', 'arguments' => array('source' => 'single'), ), ); } if (isset($resources['node']['index'])) { if (!isset($resources['node']['index']['models'])) { $resources['node']['index']['models'] = array(); } $resources['node']['index']['models'] += array( 'ResourceFeedModel' => array( 'class' => 'NodeResourceFeedModel', ), 'ResourceTimeFeedModel' => array( 'class' => 'NodeResourceFeedModel', ), ); } } }