1
0
Fork 0
forked from blallo/rss-bridge

[TwitchApiBridge] Simplify parameters and remove useless code

Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
Pierre Mazière 2016-08-27 18:06:19 +02:00
parent 7857325d9c
commit 720b7924c5

View file

@ -1,6 +1,5 @@
<?php <?php
define('TWITCH_LIMIT', 10); // The default limit define('TWITCH_LIMIT', 10); // The default limit
define('TWITCH_BROADCASTS', 'false'); // The default flag for broadcasts
class TwitchApiBridge extends BridgeAbstract{ class TwitchApiBridge extends BridgeAbstract{
@ -11,37 +10,18 @@ class TwitchApiBridge extends BridgeAbstract{
$this->uri = "http://www.twitch.tv"; $this->uri = "http://www.twitch.tv";
$this->description = "Returns the newest broadcasts or highlights by channel name using the Twitch API (v3)"; $this->description = "Returns the newest broadcasts or highlights by channel name using the Twitch API (v3)";
$this->parameters["Get channel without limit"] = array( $this->parameters['Show Channel Videos']=array(
'channel'=>array( 'channel'=>array(
'name'=>'Channel', 'name'=>'Channel',
'required'=>true 'required'=>true
), ),
'broadcasts'=>array( 'broadcasts'=>array(
'name'=>'Broadcasts', 'name'=>'Show Broadcasts rather than Highlights',
'type'=>'list', 'type'=>'checkbox'
'values'=>array(
'Show broadcasts'=>'true',
'Show highlights'=>'false'
)
)
);
$this->parameters["Get channel with limit"] = array(
'channel'=>array(
'name'=>'Channel',
'required'=>true
), ),
'limit'=>array( 'limit'=>array(
'name'=>'Limit', 'name'=>'Limit',
'type'=>'number' 'type'=>'number'
),
'broadcasts'=>array(
'name'=>'Broadcasts',
'type'=>'list',
'values'=>array(
'Show broadcasts'=>'true',
'Show highlights'=>'false'
)
) )
); );
} }
@ -61,24 +41,27 @@ class TwitchApiBridge extends BridgeAbstract{
$context = stream_context_create($opts); $context = stream_context_create($opts);
if(!isset($param['limit']['value']) ||
empty($param['limit']['value'])){
$limit = TWITCH_LIMIT; $limit = TWITCH_LIMIT;
$broadcasts = TWITCH_BROADCASTS; }else{
$requests = 1;
if(isset($param['limit']['value'])) {
$limit = (int)$param['limit']['value']; $limit = (int)$param['limit']['value'];
} else {
$limit = TWITCH_LIMIT;
} }
// The Twitch API allows a limit between 1 .. 100. Therefore any value below must be set to 1, any greater must result in multiple requests. // The Twitch API allows a limit between 1 .. 100. Therefore any value below must be set to 1, any greater must result in multiple requests.
$requests=1;
if($limit < 1) { $limit = 1; } if($limit < 1) { $limit = 1; }
if($limit > 100) { if($limit > 100) {
$requests = (int)($limit / 100); $requests = (int)($limit / 100);
if($limit % 100 != 0) { $requests++; } if($limit % 100 != 0) { $requests++; }
} }
$broadcasts = $param['broadcasts']['value']; if($param['broadcasts']['value']){
$broadcasts='true';
}else{
$broadcasts='false';
}
// Build the initial request, see also: https://github.com/justintv/Twitch-API/blob/master/v3_resources/videos.md#get-channelschannelvideos // Build the initial request, see also: https://github.com/justintv/Twitch-API/blob/master/v3_resources/videos.md#get-channelschannelvideos
$request = ''; $request = '';
@ -125,7 +108,7 @@ class TwitchApiBridge extends BridgeAbstract{
public function getName(){ public function getName(){
$param=$this->parameters[$this->queriedContext]; $param=$this->parameters[$this->queriedContext];
return $param['channel'] . ' - Twitch API Bridge'; return $param['channel']['value'] . ' - Twitch API Bridge';
} }
public function getCacheDuration(){ public function getCacheDuration(){