Skip to content

Commit

Permalink
Merge pull request #111 from mrquatsch/enhanced_plexpy
Browse files Browse the repository at this point in the history
Enhanced Plexpy - display stream count via api token
  • Loading branch information
KodeStar authored Feb 23, 2018
2 parents 196a843 + 4f93151 commit 35930f2
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 2 deletions.
68 changes: 66 additions & 2 deletions app/SupportedApps/Plexpy.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?php namespace App\SupportedApps;

class Plexpy implements Contracts\Applications {
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Client;

class Plexpy implements Contracts\Applications, Contracts\Livestats {

public $config;

public function defaultColour()
{
return '#2d2208';
Expand All @@ -9,4 +15,62 @@ public function icon()
{
return 'supportedapps/plexpy.png';
}
}
public function configDetails()
{
return 'plexpy';
}
public function testConfig()
{
$res = $this->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 = '
<ul class="livestats">
<li><span class="title">Stream Count</span><strong>'.$stream_count.'</strong></li>
</ul>
';

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;

}

}
11 changes: 11 additions & 0 deletions resources/views/supportedapps/plexpy.blade.app
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<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\Plexpy" />
<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>
<div class="input">
<button style="margin-top: 32px;" class="btn test" id="test_config">Test</button>
</div>
</div>

0 comments on commit 35930f2

Please sign in to comment.