You are here

function clients_connection_call in Web Service Clients 7.3

Same name and namespace in other branches
  1. 6.2 clients.module \clients_connection_call()
  2. 7.2 clients.module \clients_connection_call()

Call a remote method on a client.

This the main API for Client connections that support remote methods, such as XMLRPC.

Used thus: clients_connection_call('connection_machine_name', 'method_name', $params...); For example: clients_connection_call('my_connection', 'node.load', 1); will return node 1 loaded from the remote site.

Parameters

$connection_name: The connection machine name.

$method: The name of the remote method to call.

...: All other parameters are passed to the remote method.

Return value

Whatever is returned from the remote site.

Throws

Exception if the connection is not found or there is an error returned from the remote site.

File

./clients.module, line 147
Clients module provides a UI, storage, and an API for handling connections to remote webservices, including those provided by Services module on other Drupal sites.

Code

function clients_connection_call($connection_name, $method) {
  $connection = clients_connection_load($connection_name);
  if (!$connection) {
    throw new Exception(t('Client connection %connection not found.', array(
      '%connection' => $connection_name,
    )));
  }

  // Get all the arguments this function has been passed.
  $function_args = func_get_args();

  // Slice out the ones that are arguments to the method call: everything past
  // the 2nd argument.
  $method_args = array_slice($function_args, 2);
  $return = $connection
    ->callMethodArray($method, $method_args);
  return $return;
}