Hi, JSONP I’ve almost got that nailed now, a lot simpler than I thought.
if( isset( $_GET['callback'])
return $_GET['callback'] . '(' . json_encode( $array ) ,')';
// else return json_encode( $array );
As far as XML goes the data will not suit RSS as it will not link on to anything, and anyway contains about 15 custom fields, kinda:
<collection>
<job>
<title>Pole Dancer</title>
<office>Aston</office>
<location>B12 5AJ</location>
.... and so on
</job>
<job>
<title>Christmas Elves</title>
<office>Edgbaston</office>
<location>B11 3SS</location>
... and so on
</job>
</collection>
By looking at the Flickr API docs (and having consumed their data too) they just seem to wrap xml with
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="ok">
[xml-payload-here]
</rsp>
and then they call it a REST response, so I guess that is something I should be doing.
It’s good to read their own specs too because they are explicit in describing how failure will be flagged for the API users e.g.
If an error occurs, the following is returned:
<?xml version="1.0" encoding="utf-8" ?>
<rsp stat="fail">
<err code="[error-code]" msg="[error-message]" />
</rsp>
So, walking the dogs, it dawns on me that if I think of each of the “options” is merely an algorithm and that I can build up a class structure to deal with error handling, logging, caching etc which I may be able to use many times in the future.
Part of my brain is telling me that “I-spy a Strategy pattern”, but the other half is telling me to get SimpleTest out and start from scratch.
$array = array(
0 => array(
'title' => 'Pole Dancer',
'office' => 'Aston',
'Location' => 'B12 5AJ',
),
1 => array(
'title' => 'Christmas Elves',
'office' => 'Edgbaston',
'Location' => 'B11 3SS',
),
);
Thats what I’m starting out with, and I guess I’ll end up with the likes of:
$a = new webserviceFromMultiArray( $array ) ;
$a->setLogger( $logger );
$a->setCacher( $cacher );
$a->setResponseFormatter( 'WS_xml' );
return $a->getOutput(); // which may be the err msg
But then the webserviceFromMultiArray seems tied to the ‘WS_xml’ … so if I then decide to create a webserviceFromArray … anyway, I’ll start from inside and work my way out.
YAML, right, will take a look at the spec.