You are here

function clients_connection_drupal_services_6_2::callMethodArray in Web Service Clients 7.3

Same name and namespace in other branches
  1. 6.2 connections/clients_drupal/clients_drupal.inc \clients_connection_drupal_services_6_2::callMethodArray()
  2. 7.2 connections/clients_drupal/clients_drupal.inc \clients_connection_drupal_services_6_2::callMethodArray()

Call a remote method with an array of parameters.

This is technically internal; use the more DX-friendly callMethod() or the all-in-one clients_connection_call().

Parameters

$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.

Overrides clients_connection_base::callMethodArray

1 method overrides clients_connection_drupal_services_6_2::callMethodArray()
clients_connection_drupal_services_5::callMethodArray in connections/clients_drupal/clients_drupal.inc
Call a remote method with an array of parameters.

File

connections/clients_drupal/clients_drupal.inc, line 385
Contains classes for Client connections handlers.

Class

clients_connection_drupal_services_6_2
Drupal client for services on a Drupal 6 site for Services 6.x-2.x.

Code

function callMethodArray($method, $method_params = array()) {

  // If HTTP requests are enabled, report the error and do nothing.
  // (Cribbed from Content distribution module.)
  if (variable_get('drupal_http_request_fails', FALSE) == TRUE) {
    drupal_set_message(t('Drupal is unable to make HTTP requests. Please reset the HTTP request status.'), 'error', FALSE);
    watchdog('clients', 'Drupal is unable to make HTTP requests. Please reset the HTTP request status.', array(), WATCHDOG_CRITICAL);
    return;
  }
  $config = $this->configuration;
  $this->method = $method;

  // Connect to the remote system service to get an initial session id to log in with.
  $connect = xmlrpc($this->endpoint, array(
    'system.connect' => array(),
  ));
  $session_id = $connect['sessid'];
  $this
    ->handleXmlrpcError();

  // We may want to call only system.connect for testing purposes.
  if ($method == 'system.connect') {
    return $connect;
  }

  // Log in and get the user's session ID.
  $login = $this
    ->call_user_login($session_id);
  $login_session_id = $login['sessid'];
  $this
    ->handleXmlrpcError();

  // If the requested method is user.login, we're done.
  if ($method == 'user.login') {
    return $login;
  }

  // Get the API key-related arguments.
  $key_args = $this
    ->xmlrpc_key_args($method);
  $method_args = array_merge($key_args, array(
    $login_session_id,
  ), $method_params);
  $result = xmlrpc($this->endpoint, array(
    $method => $method_args,
  ));

  // Throw an exception for errors from the remote call.
  $this
    ->handleXmlrpcError();
  return $result;
}