5 changed files with 88 additions and 1 deletions
@ -0,0 +1,76 @@ |
|||
<?php namespace App\SupportedApps; |
|||
|
|||
use GuzzleHttp\Exception\GuzzleException; |
|||
use GuzzleHttp\Client; |
|||
|
|||
class Sabnzbd implements Contracts\Applications, Contracts\Livestats { |
|||
|
|||
public $config; |
|||
|
|||
public function defaultColour() |
|||
{ |
|||
return '#124019'; |
|||
} |
|||
public function icon() |
|||
{ |
|||
return 'supportedapps/sabnzbd.png'; |
|||
} |
|||
public function configDetails() |
|||
{ |
|||
return 'sabnzbd'; |
|||
} |
|||
public function testConfig() |
|||
{ |
|||
$res = $this->buildRequest('queue'); |
|||
switch($res->getStatusCode()) { |
|||
case 200: |
|||
echo 'Successfully connected to the API'; |
|||
break; |
|||
case 401: |
|||
echo 'Failed: Invalid credentials'; |
|||
break; |
|||
case 404: |
|||
echo 'Failed: Please make sure your URL is correct and that there is a trailing slash'; |
|||
break; |
|||
default: |
|||
echo 'Something went wrong... Code: '.$res->getStatusCode(); |
|||
break; |
|||
} |
|||
} |
|||
public function executeConfig() |
|||
{ |
|||
$output = ''; |
|||
$res = $this->buildRequest('queue'); |
|||
$data = json_decode($res->getBody()); |
|||
//$data->result->RemainingSizeMB = '10000000'; |
|||
//$data->result->DownloadRate = '100000000'; |
|||
$size = $data->queue->mbleft; |
|||
$rate = $data->queue->kbpersec; |
|||
$queue_size = format_bytes($size*1000*1000, false, ' <span>', '</span>'); |
|||
$current_speed = format_bytes($rate*1000, false, ' <span>'); |
|||
|
|||
if($size > 0 || $rate > 0) { |
|||
$output = ' |
|||
<ul class="livestats"> |
|||
<li><span class="title">Queue</span><strong>'.$queue_size.'</strong></li> |
|||
<li><span class="title">Speed</span><strong>'.$current_speed.'/s</span></strong></li> |
|||
</ul> |
|||
'; |
|||
} |
|||
return $output; |
|||
} |
|||
public function buildRequest($endpoint) |
|||
{ |
|||
$config = $this->config; |
|||
$url = $config->url; |
|||
$apikey = $config->apikey; |
|||
|
|||
$api_url = $url.'sabnzbd/api?output=json&apikey='.$apikey.'&mode='.$endpoint; |
|||
|
|||
$client = new Client(['http_errors' => false]); |
|||
$res = $client->request('GET', $api_url); |
|||
return $res; |
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,9 @@ |
|||
<h2>{{ __('app.apps.config') }} ({{ __('app.optional') }})</h2> |
|||
<div class="items"> |
|||
<input type="hidden" data-config="type" class="config-item" name="config[type]" value="\App\SupportedApps\Sabnzbd" /> |
|||
<div class="input"> |
|||
<label>{{ __('app.apps.apikey') }}</label> |
|||
{!! Form::text('config[apikey]', null, array('placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', 'class' => 'form-control config-item')) !!} |
|||
</div> |
|||
<button id="test_config">Test</button> |
|||
</div> |
After Width: | Height: | Size: 3.8 KiB |
Loading…
Reference in new issue