Skip to content

Commit

Permalink
Update API documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebrowning committed Jul 22, 2011
1 parent 2994c03 commit 1f9f5e1
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 30 deletions.
20 changes: 19 additions & 1 deletion services.servers.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@
* An associative array with the following keys.
*
* - name: The display name of this server.
* - settings: an assoc array containing settings information per endpoint that this server is enabled.
*/
function hook_server_info() {
return array(
'name' => 'REST',
'path' => 'rest',
'settings' => array(
'file' => array('inc', 'rest_server'),
'form' => '_rest_server_settings',
'submit' => '_rest_server_settings_submit',
),
);
}

Expand All @@ -32,5 +39,16 @@ function hook_server_info() {
* servers.
*/
function hook_server() {

$endpoint_path = services_get_server_info('endpoint_path', 'services/rest');
$canonical_path = trim(drupal_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 '';
}
//Handle server based on $canonical_path
}
172 changes: 143 additions & 29 deletions services.services.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,57 +64,171 @@
* - default value: this is a value that will be passed to the method for this particular argument if no argument value is passed
*/
function hook_services_resources() {
return array(
'user' => array(
'file' => array('type' => 'inc', 'module' => 'user_resource'),
$node_resource = array(
'node' => array(
'retrieve' => array(
'help' => 'Retrieves a user',
'callback' => '_user_resource_retrieve',
'access arguments' => array('access user profiles'), // this is probably not enough, doesn't block things like pass and email
'access arguments append' => TRUE,
'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/node_resource'),
'callback' => '_node_resource_retrieve',
'args' => array(
array(
'name' => 'uid',
'name' => 'nid',
'optional' => FALSE,
'source' => array('path' => 0),
'type' => 'int',
'description' => 'The uid of the user to retrieve.',
'source' => array('path' => '0'),
'description' => 'The nid of the node to get',
),
),
'access callback' => '_node_resource_access',
'access arguments' => array('view'),
'access arguments append' => TRUE,
),
'create' => array(
'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/node_resource'),
'callback' => '_node_resource_create',
'args' => array(
array(
'name' => 'node',
'optional' => FALSE,
'default value' => NULL,
'source' => 'data',
'description' => 'The node data to create',
'type' => 'array',
),
),
'access callback' => '_node_resource_access',
'access arguments' => array('create'),
'access arguments append' => TRUE,
),
),

'actions' => array(
'login' => array(
'help' => 'Login a user for a new session',
'callback' => '_user_resource_login',
'update' => array(
'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/node_resource'),
'callback' => '_node_resource_update',
'args' => array(
array(
'name' => 'username',
'type' => 'string',
'description' => 'A valid username',
'source' => array('data'),
'name' => 'nid',
'optional' => FALSE,
'source' => array('path' => 0),
'type' => 'int',
'description' => 'The nid of the node to get',
),
array(
'name' => 'password',
'type' => 'string',
'description' => 'A valid password',
'source' => array('data'),
'name' => 'node',
'optional' => FALSE,
'source' => 'data',
'description' => 'The node data to update',
'type' => 'array',
),
),
'access callback' => '_node_resource_access',
'access arguments' => array('update'),
'access arguments append' => TRUE,
),

'logout' => array(
'help' => 'Logout a user session',
'callback' => '_user_resource_logout',
'delete' => array(
'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/node_resource'),
'callback' => '_node_resource_delete',
'args' => array(
array(
'name' => 'nid',
'optional' => FALSE,
'source' => array('path' => 0),
'type' => 'int',
),
),
'access callback' => '_node_resource_access',
'access arguments' => array('delete'),
'access arguments append' => TRUE,
),
'index' => array(
'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/node_resource'),
'callback' => '_node_resource_index',
'args' => array(
array(
'name' => 'page',
'optional' => TRUE,
'type' => 'int',
'description' => 'The zero-based index of the page to get, defaults to 0.',
'default value' => 0,
'source' => array('param' => 'page'),
),
array(
'name' => 'fields',
'optional' => TRUE,
'type' => 'string',
'description' => 'The fields to get.',
'default value' => '*',
'source' => array('param' => 'fields'),
),
array(
'name' => 'parameters',
'optional' => TRUE,
'type' => 'array',
'description' => 'Parameters array',
'default value' => array(),
'source' => array('param' => 'parameters'),
),
),
'access arguments' => array('access content'),
),
'relationships' => array(
'files' => array(
'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/node_resource'),
'help' => t('This method returns files associated with a node.'),
'access callback' => '_node_resource_access',
'access arguments' => array('view'),
'access arguments append' => TRUE,
'callback' => '_node_resource_load_node_files',
'args' => array(
array(
'name' => 'nid',
'optional' => FALSE,
'source' => array('path' => 0),
'type' => 'int',
'description' => 'The nid of the node whose files we are getting',
),
array(
'name' => 'file_contents',
'type' => 'int',
'description' => t('To return file contents or not.'),
'source' => array('path' => 2),
'optional' => TRUE,
'default value' => TRUE,
),
),
),
),
),
);
if (module_exists('comment')) {
$comments = array(
'file' => array('type' => 'inc', 'module' => 'services', 'name' => 'resources/node_resource'),
'help' => t('This method returns the number of new comments on a given node.'),
'access callback' => 'user_access',
'access arguments' => array('access comments'),
'access arguments append' => FALSE,
'callback' => '_node_resource_load_node_comments',
'args' => array(
array(
'name' => 'nid',
'type' => 'int',
'description' => t('The node id to load comments for.'),
'source' => array('path' => 0),
'optional' => FALSE,
),
array(
'name' => 'count',
'type' => 'int',
'description' => t('Number of comments to load.'),
'source' => array('param' => 'count'),
'optional' => TRUE,
),
array(
'name' => 'offset',
'type' => 'int',
'description' => t('If count is set to non-zero value, you can pass also non-zero value for start. For example to get comments from 5 to 15, pass count=10 and start=5.'),
'source' => array('param' => 'offset'),
'optional' => TRUE,
),
),
);
$node_resource['node']['relationships']['comments'] = $comments;
}
return $node_resource;
}

0 comments on commit 1f9f5e1

Please sign in to comment.