buildRequest('status');
switch($res->getStatusCode()) {
case 200:
echo 'Successfully connected to the API';
break;
case 401:
echo 'Failed: Invalid credentials';
break;
default:
throw new MyException("Invalid response from api...");
break;
}
}
public function executeConfig()
{
$res = $this->buildRequest('status');
$data = json_decode($res->getBody());
//$data->result->RemainingSizeMB = '10000000';
//$data->result->DownloadRate = '100000000';
$queue_size = format_bytes($data->result->RemainingSizeMB*1000*1000, false, ' ', '');
$current_speed = format_bytes($data->result->DownloadRate, false, ' ');
$output = '
- Queue'.$queue_size.'
- Speed'.$current_speed.'/s
';
return $output;
}
public function buildRequest($endpoint)
{
$config = $this->config;
$url = $config->url;
$username = $config->username;
$password = $config->password;
$rebuild_url = str_replace('http://', 'http://'.$username.':'.$password.'@', $url);
$rebuild_url = str_replace('https://', 'https://'.$username.':'.$password.'@', $rebuild_url);
$api_url = $rebuild_url.'jsonrpc/'.$endpoint;
$client = new Client(['http_errors' => false]);
$res = $client->request('GET', $api_url);
return $res;
}
}