Posted by Yaeko on January 16, 2013 at 9:32am
Hello,
I'm fiddling around with the Services module using SOAP as server combined with OAuth.
So I've created a custom resource via the hook_services_resource, code:
<?php
function noteresource_services_resources() {
return array(
'note' => array(
'retrieve' => array(
'help' => 'Retrieves a note',
'file' => array('file' => 'inc', 'module' => 'noteresource', 'name' => 'noteresource'),
'callback' => '_noteresource_retrieve',
'access callback' => '_noteresource_access',
'access arguments' => array('view'),
'access arguments append' => TRUE,
'args' => array(
array(
'name' => 'id',
'type' => 'int',
'description' => 'The id of the note to get',
'source' => array('path' => '0'),
'optional' => FALSE,
),
),
),
'create' => array(
'help' => 'Creates a note',
'file' => array('file' => 'inc', 'module' => 'noteresource'),
'callback' => '_noteresource_create',
'access arguments' => array('note resource create'),
'access arguments append' => FALSE,
'args' => array(
array(
'name' => 'data',
'type' => 'struct',
'description' => 'The note object',
'source' => 'data',
'optional' => FALSE,
),
),
),
'update' => array(
'help' => 'Updates a note',
'file' => array('file' => 'inc', 'module' => 'noteresource'),
'callback' => '_noteresource_update',
'access callback' => '_noteresource_access',
'access arguments' => array('update'),
'access arguments append' => TRUE,
'args' => array(
array(
'name' => 'id',
'type' => 'int',
'description' => 'The id of the node to update',
'source' => array('path' => '0'),
'optional' => FALSE,
),
array(
'name' => 'data',
'type' => 'struct',
'description' => 'The note data object',
'source' => 'data',
'optional' => FALSE,
),
),
),
'delete' => array(
'help' => 'Deletes a note',
'file' => array('file' => 'inc', 'module' => 'noteresource'),
'callback' => '_noteresource_delete',
'access callback' => '_noteresource_access',
'access arguments' => array('delete'),
'access arguments append' => TRUE,
'args' => array(
array(
'name' => 'nid',
'type' => 'int',
'description' => 'The id of the note to delete',
'source' => array('path' => '0'),
'optional' => FALSE,
),
),
),
'index' => array(
'help' => 'Retrieves a listing of notes',
'file' => array('file' => 'inc', 'module' => 'noteresource'),
'callback' => '_noteresource_index',
'access callback' => 'user_access',
'access arguments' => array('access content'),
'access arguments append' => FALSE,
'args' => array(array(
'name' => 'page',
'type' => 'int',
'description' => '',
'source' => array(
'param' => 'page',
),
'optional' => TRUE,
'default value' => 0,
),
array(
'name' => 'parameters',
'type' => 'array',
'description' => '',
'source' => 'param',
'optional' => TRUE,
'default value' => array(),
),
),
),
),
);
}
?>I'm trying to get some data back from the server with my client:
<?php
require "OAuth.php";
require "common.inc.php";
$consumer_key = 'key';
$consumer_secret = 'sec key';
$access_key = 'acckey';
$access_key_secret = 'accsec';
$signature_method = new OAuthSignatureMethod_HMAC_SHA1();
$server_uri = 'http://drupal_services.local/js-api';
$consumer = new OAuthConsumer($consumer_key, $consumer_secret, NULL);
$token = new OAuthConsumer($access_key, $access_key_secret);
$params = array();
$request = OAuthRequest::from_consumer_and_token($consumer, $token, "POST", $server_uri);
$request->sign_request($signature_method, $consumer, $token);
$header = $request->to_header($server_uri);
$header = urldecode($header);
$opts = array('http' => array(
'header' => $header,
));
$ctx = stream_context_create($opts);
$wsdl = "http://drupal_services.local/js-api?wsdl";
try {
$client = new SoapClient($wsdl, array(
'stream_context' => $ctx,
'trace' => 1,
));
echo "<pre>";
print_r($client->__getFunctions());
echo "</pre>";
echo "<hr />";
$call = $client->note_soap_retrieve(1);
echo "<pre>";
print_r($call);
echo "</pre>";
echo "<hr />";
}
catch (Exception $e) {
$error = 1;
$error_message = $e->getMessage();
print_r($error_message);
}
return 'ok';
?>I echo out what functions my SoapClient has and it turns out that it has only the following:
Seems that my custom resources isn't in the response object. The resource is very well checked in the settings, so that's not the issue.
The issue seems to be elsewhere, but I don't know where to look.
If anyone can lend me a hand? ;)
Thanks!
