You are here

function clients_connection_drupal_services_5::callMethodArray in Web Service Clients 6.2

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

Call a remote method with an array of parameters.

TODO: REFACTOR this to look more like the static methods above -- separate methods for getuser, connect, etc etc.

Parameters

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

All other parameters are passed to the remote method.: Note that the D5 version of Services does not seem to respect optional parameters; you should pass in defaults (eg an empty string or 0) instead of omitting a parameter.

Return value

Whatever is returned from the remote site.

Overrides clients_connection_drupal_services_6_2::callMethodArray

1 call to clients_connection_drupal_services_5::callMethodArray()
clients_connection_drupal_services_5::testConnectionNodeLoad in connections/clients_drupal/clients_drupal.inc
Connection test button handler: loading a node.

File

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

Class

clients_connection_drupal_services_5
Drupal client for services on a Drupal 5 site.

Code

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

  //dsm($this);

  //dsm($method);
  $config = $this->configuration;
  $this->method = $method;
  $connect = xmlrpc($this->endpoint, 'system.connect');
  $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;
  }

  //dsm($login);

  // The node.load method on D5 is an evil special case because it's defined
  // to not use an API key.
  if ($method == 'node.load') {

    // Be nice. Let the caller specify just the nid, and provide the
    // empty default for the optional fields parameter.
    if (count($method_params) == 1) {
      $method_params[] = array();
    }

    // Be nice part 2: the number one (in my experience) cause of lost
    // hours on Services is the way XMLRPC and/or services get their
    // knickers in a twist when they want an integer but think they've got
    // a string because they're too damn stupid to try casting.
    // So cast the nid here, since we're already in a special case for this
    // method anyway.
    $method_params[0] = (int) $method_params[0];

    // Build the array of connection arguments for the method we want to call.
    $xmlrpc_args = array_merge(array(
      $this->endpoint,
      $method,
    ), array(
      $login_session_id,
    ), $method_params);

    //dsm($xmlrpc_args);

    // Call the xmlrpc method with our array of arguments.
    $result = call_user_func_array('xmlrpc', $xmlrpc_args);

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

  // Get the API key-related arguments.
  $key_args = $this
    ->xmlrpc_key_args($method);

  // Build the array of connection arguments for the method we want to call.
  $xmlrpc_args = array_merge(array(
    $this->endpoint,
    $method,
  ), $key_args, array(
    $login_session_id,
  ), $method_params);

  // Call the xmlrpc method with our array of arguments.
  $result = call_user_func_array('xmlrpc', $xmlrpc_args);

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