Quote from: BobRay at Feb 06, 2009, 01:35 PM
(still wondering, though, why Captcha is a plugin rather than a service since all the same arguments apply there, no?-- I’m sure there’s a good reason, I just can’t see it).
Because I didn’t implement it?

But seriously, I can’t see it either -- I would agree that a Captcha implementation could and should be a reusable "service" class.
Quote from: BobRay at Feb 06, 2009, 01:35 PM
How do I instantiate a new XML-RPC client?
I’d wrap the service client in something like this:
<?php
require_once MODX_CORE_PATH . 'model/modx/xmlrpc/xmlrpc.inc';
require_once MODX_CORE_PATH . 'model/modx/xmlrpc/xmlrpc_wrappers.inc';
class SampleService {
var $modx;
var $options;
var $client;
function SampleService(& $modx, $options = array()) {
$this->modx = & $modx;
$this->options = $options;
}
function &getServiceClient($url = '') {
if (empty($this->client)) {
$url = empty($url)
? (!isset($options['url']) ? '' : $options['url'])
: $url;
if (empty($url)) {
$this->client = null;
} else {
$modx->loadClass('xmlrpc');
$this->client = new xmlrpc_client($url);
}
}
return $this->client;
}
function _callServiceMethod($method, $params = array()) {
$response = null;
if ($this->getServiceClient()) {
$msgParams = array();
foreach ($params as $param) $msgParams[] = new xmlrpcval($param);
$msg = new xmlrpcmsg($method, $msgParams);
$response = $this->client->send($msg);
}
return $response;
}
/* Add specific service methods to format complex parameters and/or transform the responses
to make it easier for users to call specific business methods of the service */
}
/* Code to use it would be like...(though you would really want to call specific business methods) */
if ($modx->getService('sample', 'SampleService', '', array('url' => 'http://localhost/some/service/url/'))) {
$response = $modx->sample->_callServiceMethod('methodname', array('foo', 'bar', true));
if (!$response->faultCode()) {
/* do something with the expected response */
} else {
/* report an error */
}
}
?>
Quote from: BobRay at Feb 06, 2009, 01:35 PM
Is there an advantage to using the jsonrpc subclasses for it as we do with regard in the modTransportProvider class?
For communicating with a service that was being implemented in the JSON-RPC protocol that would be useful; that’s what the default transport provider server implementation is, but ultimately, it could be implemented as a server accessed via any remote protocol (i.e. XML-RPC, JSON-RPC, SOAP, plain XML, plain JSON, or whatever) we implement the service as.
In this case, it is an existing XML-RPC web service we are simply creating a custom client for, so JSON-RPC is irrelevant.
Quote from: BobRay at Feb 06, 2009, 01:35 PM
Are there guidelines somewhere for creating a MODx service?
Just what I said, as long as the constructor accepts the two parameters (the reference to modx and an array of configuration options) you can implement a "service" class like we are talking about here. Don’t get confused, these "service" classes are simply classes for closely and easily integrating just about any modular code with modX, and have nothing to do with "web services", other than in this instance we are creating a MODx "service" class the happens to communicate with an XML-RPC web service.