From 3b1a4c1f2259d9ba1653b0d01e4cbd4634fe5e59 Mon Sep 17 00:00:00 2001 From: mrquatsch Date: Sun, 18 Feb 2018 08:36:45 -0600 Subject: [PATCH] Create Runeaudio enhanced app --- app/SupportedApps/Runeaudio.php | 89 +++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 app/SupportedApps/Runeaudio.php diff --git a/app/SupportedApps/Runeaudio.php b/app/SupportedApps/Runeaudio.php new file mode 100644 index 00000000..a5ed561b --- /dev/null +++ b/app/SupportedApps/Runeaudio.php @@ -0,0 +1,89 @@ +buildRequest('status'); + 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 = ''; + $artist = ''; + $song_title = ''; + $res = $this->buildRequest('currentsong'); + $array = explode("\n", $res->getBody()); + foreach($array as $item) { + $item_array = explode(": ", $item); + if ($item_array[0] == 'Artist') { + $artist = $item_array[1]; + if (strlen($artist) > 15) { + $artist = substr($artist,0,12).'...'; + } + } elseif ($item_array[0] == 'Title') { + $song_title = $item_array[1]; + if (strlen($song_title) > 15) { + $song_title = substr($song_title,0,12).'...'; + } + } + } + + $output = ' + + '; + + return $output; + } + + public function buildRequest($endpoint) + { + $config = $this->config; + $url = $config->url; + + $url = rtrim($url, '/'); + + $api_url = $url.'/command/?cmd='.$endpoint; + //die( $api_url.' --- '); + + $client = new Client(['http_errors' => false]); + $res = $client->request('GET', $api_url); + return $res; + + } + + +}