RapidGen API Class
<?php
class RGAPI
{
private $curl;
private $apikey;
private $api_domain = 'api.rapidgen.net';
public $use_ssl = false;
public function __construct($apikey)
{
$this->apikey = $apikey;
$this->curl = curl_init();
curl_setopt($this->curl, CURLOPT_HEADER, false);
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($this->curl, CURLOPT_TIMEOUT, 15);
curl_setopt($this->curl, CURLOPT_CONNECTTIMEOUT, 20);
}
public function __destruct()
{
curl_close($this->curl);
}
private function get_page($postvars=array())
{
if (!$postvars) trigger_error('You didn\'t specify api variables to send');
$posturl = ($this->use_ssl === true ? 'https' : 'http') . '://' . $this->api_domain . '/api/';
curl_setopt($this->curl, CURLOPT_URL, $posturl);
if ($postvars)
{
curl_setopt($this->curl, CURLOPT_POST, 1);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($postvars + array('api_key' => $this->apikey)));
}
if ($this->use_ssl === true)
{
curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, 0);
}
$response = curl_exec($this->curl);
$errors = curl_error($this->curl);
if ($errors) trigger_error($errors);
return json_decode($response,true);
}
public function getLinks($type='active')
{
$postfields['sub'] = 'getlinklist_' . trim($type);
return $this->get_page($postfields);
}
public function getBandwidth($type, $filehost)
{
$postfields['sub'] = 'getbw_' . trim($type);
$postfields['filehost'] = trim($filehost);
return $this->get_page($postfields);
}
public function generate($links)
{
$postfields['sub'] = 'linkgen';
$postfields['links'] = trim($links);
return $this->get_page($postfields);
}
}
Sample PHP Code for using API
<?php
require 'rgapi.php';
echo <<<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>RapidGen API Curl Sample Code</title>
<meta name="author" content="rapidgen" />
<meta name="description" content="Sample RapidGen API link generation code" />
</head>
<html>
<body>
<center>
<p>Enter some links to generate, one per line:</p>
<form action="" method="post">
<textarea rows="10" name="links" cols="50" onfocus="this.select();"></textarea><br /><br />
<input type="submit" />
</form>
</center>
<br /><br />
HTML;
// YOU SHOULD ALWAYS HARD-CODE YOUR API KEY INSIDE YOUR WEB APPLICATION FILES OR IN A DATABASE
$api_key = 'BKAy7UlBOhT92oFFC5r9YYsMMFTOqR'; // this is an example key only
$api = new RGAPI($api_key);
// $api->use_ssl = true; # if you want to use https://api.rapidgen.net/api/
$links = !empty($_REQUEST['links']) ? trim($_REQUEST['links']) : null;
if ($links)
{
$result = $api->generate($links);
if ($result['status'] == 'ERROR')
{
echo('<pre style="margin:0 auto; width:auto; min-width: 30%; text-align:center; background: lightgray; color: black;"><b>ERROR</b>: ' . $result['message'] . '</pre>');
}
else
{
echo '<table style="margin:0 auto; text-align:center" border="1">';
echo '<tr>';
echo '<th>';
echo 'Link Service';
echo '</th>';
echo '<th>';
echo 'Premium Link';
echo '</th>';
echo '<th>';
echo 'Filename';
echo '</th>';
echo '</tr>';
foreach ($result['data'] as $link)
{
echo '<tr>';
echo '<td>';
echo $link['service'];
echo '</td>';
echo '<td>';
echo '<a href="http://rapidgen.net/get/' . $link['sid'] . '/' . $link['filename'] . '">http://rapidgen.net/get/' . $link['sid'] . '/' . $link['filename'];
echo '</td>';
echo '<td>';
echo $link['filename'];
echo '</td>';
echo '</tr>';
}
echo '</table>';
}
}
echo <<<HTML
</body>
</html>
HTML;