diff --git a/app/Item.php b/app/Item.php index 83de752c..ace78bb6 100644 --- a/app/Item.php +++ b/app/Item.php @@ -32,8 +32,9 @@ class Item extends Model 'pFsense' => \App\SupportedApps\Pfsense::class, 'Pihole' => \App\SupportedApps\Pihole::class, 'Plex' => \App\SupportedApps\Plex::class, - 'UniFi' => \App\SupportedApps\Unifi::class, 'Portainer' => \App\SupportedApps\Portainer::class, + 'UniFi' => \App\SupportedApps\Unifi::class, + 'Sabnzbd' => \App\SupportedApps\Sabnzbd::class, ]; } public static function supportedOptions() diff --git a/app/SupportedApps/Sabnzbd.php b/app/SupportedApps/Sabnzbd.php new file mode 100644 index 00000000..6a0b5c73 --- /dev/null +++ b/app/SupportedApps/Sabnzbd.php @@ -0,0 +1,76 @@ +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, ' ', ''); + $current_speed = format_bytes($rate*1000, false, ' '); + + if($size > 0 || $rate > 0) { + $output = ' + + '; + } + 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; + + } + +} \ No newline at end of file diff --git a/resources/lang/en/app.php b/resources/lang/en/app.php index 6379cbe6..d4276445 100644 --- a/resources/lang/en/app.php +++ b/resources/lang/en/app.php @@ -59,6 +59,7 @@ return [ 'apps.username' => 'Username', 'apps.password' => 'Password', 'apps.config' => 'Config', + 'apps.apikey' => 'Api Key', 'url' => 'Url', 'title' => 'Title', diff --git a/resources/views/supportedapps/sabnzbd.blade.php b/resources/views/supportedapps/sabnzbd.blade.php new file mode 100644 index 00000000..697ebed3 --- /dev/null +++ b/resources/views/supportedapps/sabnzbd.blade.php @@ -0,0 +1,9 @@ +

{{ __('app.apps.config') }} ({{ __('app.optional') }})

+
+ +
+ + {!! Form::text('config[apikey]', null, array('placeholder' => __('app.apps.apikey'), 'data-config' => 'apikey', 'class' => 'form-control config-item')) !!} +
+ +
\ No newline at end of file diff --git a/storage/app/public/supportedapps/sabnzbd.png b/storage/app/public/supportedapps/sabnzbd.png new file mode 100644 index 00000000..acf3d274 Binary files /dev/null and b/storage/app/public/supportedapps/sabnzbd.png differ