I am building a class to send API calls to Rapidshare and return the results of said call. Here's how I want the call to be done:
$rs = new rs();
$params = array(
'sub' => 'listfiles_v1',
'type' => 'prem',
'login' => '10347455',
'password' => 'not_real_pass',
'realfolder' => '0',
'fields' => 'filename,downloads,size',
);
print_r($rs->apiCall($params));
And here's the class so far:
class RS
{
var $baseUrl = 'http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=';
function apiCall($params)
{
$newUrl = $baseUrl;
$keys = array_keys($params);
$count = count($params);
for($i = 0; $i < $count; $i++)
{
$newUrl .= $keys[$i];
$newUrl .= '&';
$newUrl .= $params[$keys[$i]];
}
return $newUrl;
}
}
Obviously i'm returning $newUrl
and using print_r()
to test the query string, and this is what it comes out as with the code shown above:
sub&listfiles_v1type&premlogin&10347455password&_not_real_passrealfolder&0fields&filename,downloads,size
When it should be:
http://api.rapidshare.com/cgi-bin/rsapi.cgi?sub=listfiles_v1&type=prem&login=10347455&password=not_real_pass&realfolder=0&fields=filename,downloads,size
Hopefully you can see what I'm trying to do here :P It's probably a silly mistake that I'm failing to find or a logical error.
Thanks in advance.