Proxying Oahu API calls

If you want to access Oahu’s API from the client side, e.g. when providing data for a Flash site, you need to proxy it to your host and add the Consumer ID and Secret values there, so it can’t be accessed by the User.

PHP

Here is an example of a simple proxy in PHP

<?php
$consumer_id="OAHU_CONSUMER_ID";
$consumer_secret="OAHU_CONSUMER_SECRET";

/* PUT data comes in on the stdin stream */
$fp = fopen( "php://input", "r" );
$data="";

while( !feof( $fp ) ){
    $data .= fread( $fp, 8192 );
}

$opts = array('http' =>
    array(
        'method'  => 'GET',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $data
    )
);

$context  = stream_context_create($opts);
$url = $_GET['url'];

if ( !$url || substr(urldecode($url),0,19)!="http://api.oahu.fr/" ) {
  // Passed url not specified.
  $contents = 'ERROR: This proxy can only be used to access Oahu\'s API';  
} else {
    $contents = file_get_contents(urldecode($url."&consumer_id=".$consumer_id."&consumer_secret=".$consumer_secret), false, $context);
}
echo $contents;
fclose($fp);