I can't make "out of the box" version to work. (Views 3, Services 3).

These simple, but hardcode overrides solved the problem:

// services_views.module

function services_views_services_resources() {
$resources['views'] = array();

$resources['views']['retrieve'] = array(
'help' => 'Retrieves a view.',
'file' => array(
'type' => 'inc',
'module' => 'services_views',
'name' => 'services_views.resource',
),
'callback' => 'services_views_retrieve',
'access callback' => 'services_views_access',
'access arguments' => array('view'),
'access arguments append' => TRUE,
'args' => array(
// OVERRIDDEN
// 'view_name' => array(
'0' => array(
'name' => 'view_name',
'type' => 'string',
'description' => 'The name of the view to get.',
'source' => array('path' => '0'),
'optional' => FALSE,
),
// OVERRIDDEN
// 'display_id' => array(
'1' => array(
'name' => 'display_id',
'type' => 'string',
'description' => 'The display ID of the view to get.',
// OVERRIDDEN
// 'source' => array('param' => 'display_id'),
'source' => array('path' => '1'),
'optional' => TRUE,
'default value' => 'default',
),
// OVERRIDDEN
// 'args' => array(
'2' => array(
'name' => 'args',
'type' => 'array',
'description' => 'A list of arguments to pass to the view.',
// OVERRIDDEN
// 'source' => array('param' => 'args'),
'source' => array('path' => '2'),
'optional' => TRUE,
'default value' => array(),
),
// OVERRIDDEN
// 'offset' => array(
'3' => array(
'name' => 'offset',
'type' => 'int',
'description' => 'The number of the entry for the page begin with.',
// OVERRIDDEN
// 'source' => array('param' => 'offset'),
'source' => array('path' => '3'),
'optional' => TRUE,
'default value' => 0,
),
// OVERRIDDEN
// 'limit' => array(
'4' => array(
'name' => 'limit',
'type' => 'int',
'description' => 'The total number of entries to list.',
// OVERRIDDEN
// 'source' => array('param' => 'limit'),
'source' => array('path' => '4'),
'optional' => TRUE,
'default value' => 10,
),
// OVERRIDDEN
// 'theme_output' => array(
'5' => array(
'name' => 'theme_output',
'type' => 'bool',
'description' => 'Whether to return the raw data results or style the results.',
// OVERRIDDEN
// 'source' => array('param' => 'theme_output'),
'source' => array('path' => '5'),
'optional' => TRUE,
'default value' => FALSE,
),
),
);

...and one more "hook":

function services_views_access($op = 'view', $args = array()) {

// OVERRIDDEN
+ $args['view_name'] = $args[0];
+ $args['display_id'] = $args[1];

switch ($op) {
case 'view':

- - -

that's it.
the call looks like this (from other custom module):

$result = ..._call_xmlrplc('views.retrieve', $esid,
$view->name, // view name
$view->current_display, // display name
$view->args, // arguments
$view->get_offset(), // offset
$view->get_items_per_page() // items per page
);

Comments

stonevo’s picture

I did this way and built the xmlrpc client to get view information from drupal. But It couldn't be done. Finally I found out that I must clear cache for each changes in services_views module. Hope this will help someone be stucked on the same problem.

jhnphm’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

The above fixes it on 7.x-1.x-dev too.

ygerasimov’s picture

I understand the changes here, but can you please advise what is the problem here? How to reproduce?

jhnphm’s picture

I believe one can reproduce it by trying to use services_views w/ XML-RPC. I'm using Services 7.x-3.x-dev and talking to it via python xmlrpc. It seems the original code breaks positional arguments.

lucascaro’s picture

I can confirm that the xmlrpc server won't work with a keyed array for args. in particular, line 71 of xmlrpc_server.module checks for:

if ($arg['optional'] && isset($arg['default value']) && !isset($args[$index])) {

but $index is 'view_name' (for views.retrieve for example) and args is array(0 => 'parameter').

if you check the other resources defined by services they define the arguments like:

'args' => array(
            array(
              'name' => 'username',
              'type' => 'string',
              'description' => 'A valid username',
              'source' => array('data' => 'username'),
              'optional' => FALSE,
            ),
            array(
              'name' => 'password',
              'type' => 'string',
              'description' => 'A valid password',
              'source' => array('data' => 'password'),
              'optional' => FALSE,
            ),
          ),

so I'm guessing that adding a named key here is not common practice.

I'm working with the 6.x version. I'll try the proposed changes and report back if it works :)

lucascaro’s picture

Ok, this worked for an xmlrpc server on 6.x-1.x-dev. here's a patch formatted for that branch:

lucascaro’s picture

Status: Active » Needs review
jhnphm’s picture

Any progress on applying the various patches?

lucascaro’s picture

on my end this works and allows us to use services_views both for xmlrpc and rest servers for 6.x