From 4f9315132b19eb3aea561bed96231a925616e145 Mon Sep 17 00:00:00 2001 From: mrquatsch Date: Thu, 22 Feb 2018 13:27:44 -0600 Subject: [PATCH] Enhanced Plexpy - display stream count via api token --- app/SupportedApps/Plexpy.php | 68 ++++++++++++++++++- .../views/supportedapps/plexpy.blade.app | 11 +++ 2 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 resources/views/supportedapps/plexpy.blade.app diff --git a/app/SupportedApps/Plexpy.php b/app/SupportedApps/Plexpy.php index 212c3dd1..93aac88e 100644 --- a/app/SupportedApps/Plexpy.php +++ b/app/SupportedApps/Plexpy.php @@ -1,6 +1,12 @@ buildRequest('arnold'); + switch($res->getStatusCode()) { + case 200: + $data = json_decode($res->getBody()); + if(isset($data->error) && !empty($data->error)) { + echo 'Failed: '.$data->error; + } else { + 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('get_activity'); + $data = json_decode($res->getBody()); + $stream_count = $data->response->data->stream_count; + + $output = ' + + '; + + return $output; + } + public function buildRequest($endpoint) + { + $config = $this->config; + $url = $config->url; + $apikey = $config->apikey; + + $url = rtrim($url, '/'); + + $api_url = $url.'/api/v2?apikey='.$apikey.'&cmd='.$endpoint; + + $client = new Client(['http_errors' => false]); + $res = $client->request('GET', $api_url); + return $res; + + } + +} diff --git a/resources/views/supportedapps/plexpy.blade.app b/resources/views/supportedapps/plexpy.blade.app new file mode 100644 index 00000000..fc904101 --- /dev/null +++ b/resources/views/supportedapps/plexpy.blade.app @@ -0,0 +1,11 @@ +

{{ __('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