From 6d4b179d2bf2c795306aa92aa9d1ff72e1dca352 Mon Sep 17 00:00:00 2001
From: alxlaxv <35723598+alxlaxv@users.noreply.github.com>
Date: Fri, 19 Oct 2018 23:49:50 +0200
Subject: [PATCH] Update Radarr.php
---
app/SupportedApps/Radarr.php | 97 +++++++++++++++++++++++++++++++++++-
1 file changed, 95 insertions(+), 2 deletions(-)
diff --git a/app/SupportedApps/Radarr.php b/app/SupportedApps/Radarr.php
index 8a1d0fdc..a01188ea 100644
--- a/app/SupportedApps/Radarr.php
+++ b/app/SupportedApps/Radarr.php
@@ -1,6 +1,10 @@
getStatus();
+ $status = json_decode($res->getBody());
+ if (isset($status->version))
+ {
+ echo 'Successfully connected to Radarr API version '.$status->version;
+ }
+ else if (isset($status->error))
+ {
+ if ($status->error == "Unauthorized")
+ {
+ echo 'Incorrect API Key. You can find it in Settings > General';
+ }
+ else
+ {
+ echo 'Error: '.$status->error;
+ }
+ }
+ else
+ {
+ echo 'Something went wrong';
+ }
+ }
+
+ public function executeConfig()
+ {
+ $html = '';
+ $active = 'active';
+ $html = '
+
+ - Missing: '.$this->getMissing().'
+
+
+ - Activity: '.$this->getQueue().'
+
+ ';
+ return json_encode(['status' => $active, 'html' => $html]);
+ }
+
+ public function getStatus()
+ {
+ $config = $this->config;
+ $url = $config->url;
+ $url = rtrim($url, '/');
+ $api_url = $url.'/api/system/status?apikey='.$config->apiKey;
+ $client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]);
+ $res = $client->request('GET', $api_url);
+ return $res;
+ }
+
+ public function getMissing()
+ {
+ $config = $this->config;
+ $url = $config->url;
+ $url = rtrim($url, '/');
+ $api_url = $url.'/api/wanted/missing?apikey='.$config->apiKey.'&pageSize=1';
+ $client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]);
+ $res = $client->request('GET', $api_url);
+ $json = json_decode($res->getBody());
+ $missing = $json->totalRecords;
+ if (empty($missing))
+ {
+ $missing = 0;
+ }
+ return $missing;
+ }
+
+ public function getQueue()
+ {
+ $config = $this->config;
+ $url = $config->url;
+ $url = rtrim($url, '/');
+ $api_url = $url.'/api/queue?apikey='.$config->apiKey.'&pageSize=1';
+ $client = new Client(['http_errors' => false, 'timeout' => 15, 'connect_timeout' => 15]);
+ $res = $client->request('GET', $api_url);
+ $queue = 0;
+ if (empty($res->getBody()))
+ {
+ $queue = sizeof($res->getBody());
+ }
+ return $queue;
+ }
+}