| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Provides the Services module via this REST API.
|
| 7 |
*/
|
| 8 |
|
| 9 |
#/**
|
| 10 |
# * Implements hook_server_info().
|
| 11 |
# */
|
| 12 |
#function restapi_services_server_info() {
|
| 13 |
# return array(
|
| 14 |
# '#name' => 'REST API',
|
| 15 |
# '#path' => 'restapi',
|
| 16 |
# );
|
| 17 |
#}
|
| 18 |
#
|
| 19 |
#/**
|
| 20 |
# * Implementation of hook_server().
|
| 21 |
# */
|
| 22 |
#function restapi_services_server() {
|
| 23 |
#}
|
| 24 |
|
| 25 |
/**
|
| 26 |
* Implements hook_restapi_menu(). Adds the services callbacks.
|
| 27 |
*/
|
| 28 |
function restapi_services_restapi_menu($may_cache) {
|
| 29 |
if ($may_cache) {
|
| 30 |
$items[] = array(
|
| 31 |
'method' => 'GET',
|
| 32 |
'path' => '=/service',
|
| 33 |
'callback' => 'restapi_services_do_list',
|
| 34 |
);
|
| 35 |
}
|
| 36 |
|
| 37 |
elseif (arg(0) == '=' && arg(1) == 'service' && arg(2)) {
|
| 38 |
$items[] = array(
|
| 39 |
'method' => 'GET',
|
| 40 |
'path' => '=/service/'.arg(2),
|
| 41 |
'callback' => 'restapi_services_do_describe',
|
| 42 |
);
|
| 43 |
|
| 44 |
$items[] = array(
|
| 45 |
'method' => 'POST',
|
| 46 |
'path' => '=/service/'.arg(2),
|
| 47 |
'callback' => 'restapi_services_do_call',
|
| 48 |
);
|
| 49 |
}
|
| 50 |
|
| 51 |
return $items;
|
| 52 |
}
|
| 53 |
|
| 54 |
function restapi_services_do_list() {
|
| 55 |
$services = services_get_all();
|
| 56 |
$listed_services = array();
|
| 57 |
foreach ($services as $service) {
|
| 58 |
$listed_services[] = $service['#method'];
|
| 59 |
}
|
| 60 |
return restapi_serialize($listed_services);
|
| 61 |
}
|
| 62 |
|
| 63 |
function restapi_services_do_describe($data, $method) {
|
| 64 |
$service = services_method_get($method);
|
| 65 |
if ($service) {
|
| 66 |
return restapi_serialize($service);
|
| 67 |
}
|
| 68 |
else {
|
| 69 |
return drupal_not_found();
|
| 70 |
}
|
| 71 |
}
|
| 72 |
|
| 73 |
function restapi_services_do_call($data, $method) {
|
| 74 |
return restapi_serialize(services_method_call($method_name, $data));
|
| 75 |
}
|