As a followup to my eCommerce site series, I’ll be writing up a project I’m starting for the same Server Programming class. It’s a XML-RPC PHP server that handles beer! Yum.

Beer.

The professor was nice enough to allow us to use a library that handles the nitty-gritty of XML-RPC, so I’ve started to stub in the necessary methods.

[php]
<?php
include "lib/xmlrpc.inc";
include "lib/xmlrpcs.inc";
include "lib/xmlrpc_wrappers.inc";

/*
* getMethods returns a Vector of methods accessable to a client
*/
function getMethods( $params ) {
$methods = array(
‘getPrice(String beer)’,
‘setPrice(String beer, Double price)’,
‘getBeers()’,
‘getCheapest()’,
‘getCostliest()’
);
return new xmlrpcresp( new xmlrpcval($methods), "vector");
}

/*
* getPrice returns a Double price for a beer
*/
function getPrice( $beer ){

}

/*
* setPrice returns true if set correctly; sets the price for a beer given
* String $beer
* Double $price
*/
function setPrice( $beer, $price ){

}

/*
* getBeers accepts no parameters, returns a Vector of beers and their prices
*/
function getBeers() {

}

/*
* getCheapest accepts no parameters, returns a String of the cheapest beer on tap
*/
function getCheapest(){

}

/*
* getCostliest accepts no parameters, returns a String of the costliest beer on tap
*/
function getCostliest(){

}

//declare signature, provide documentation
//the php server supports remote introspection
$getMethods_sig = array(array($xmlrpcArray));
$getMethods_doc = "Returns a Vector of methods accessable to a client.";

$getPrice_sig = array(array($xmlrpcArray, $xmlrpcDouble));
$getPrice_doc = "Returns a Double price for a given beer.";

$setPrice_sig = array(array($xmlrpcArray, $xmlrpcString, $xmlrpcDouble));
$setPrice_doc = "Returns true if set correctly; sets the price for a beer given.";

$getBeers_sig = array(array($xmlrpcArray));
$getBeers_doc = "Returns a Vector of the beers on tap";

$getCheapest_sig = array(array($xmlrpcArray));
$getCheapest_doc = "Returns a String of the cheapest beer on tap";

$getCostliest_sig = array(array($xmlrpcArray));
$getCostliest_doc = "Returns a String of the costliest beer on tap";

new xmlrpc_server(array(‘beer.getMethods’ =>
array(
‘function’ => ‘getMethods’,
‘signature’ => $getMethods_sig,
‘docstring’ => $getMethods_doc),
‘beer.getPrice’ =>
array(
‘function’ => ‘getPrice’,
‘signature’ => $getPrice_sig,
‘docstring’ => $getPrice_doc),
‘beer.setPrice’ =>
array(
‘function’ => ‘setPrice’,
‘signature’ => $setPrice_sig,
‘docstring’ => $setPrice_doc),
‘beer.getBeers’ =>
array(
‘function’ => ‘getBeers’,
‘signature’ => $getBeers_sig,
‘docstring’ => $getBeers_doc),
‘beer.getCheapest’ =>
array(
‘function’ => ‘getCheapest’,
‘signature’ => $getCheapest_sig,
‘docstring’ => $getCheapest_doc),
‘beer.getCostliest’ =>
array(
‘function’ => ‘getCostliest’,
‘signature’ => $getCostliest_sig,
‘docstring’ => $getCostliest_doc)
));

?>
[/php]

So thanks to the awesomeness that is Edd Dumbill’s XML-RPC PHP library, that’s pretty much everything besides the body of each method. Tune in next time for part two!

Leave a Reply

Your email address will not be published. Required fields are marked *