Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented the user controlled 'Limit' when getting a post Feed #3

Merged
merged 5 commits into from
Nov 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions classes/TwitchAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public function apiRequest($url)
* @param int $offset
* @return string
*/
public function getTopList($type, $limit = 10, $offset = 0)
public function getTopList($type, $limit = 10, $offset = 0, $client_id)
{
$this->setListTypeSettings($type);

$json = $this->apiRequest($this->typeUrl."?limit=".$limit."&offset=".$offset);
$json = $this->apiRequest($this->typeUrl."?limit=".$limit."&offset=".$offset."&client_id=".$client_id);
$object = json_decode($json, true);

return $object[$this->typePrefix];
Expand Down Expand Up @@ -70,7 +70,7 @@ private function setListTypeSettings($type)
{
switch ($type) {
case 'games':
$this->typeUrl = '/games/top';
$this->typeUrl = "/games/top";
$this->typePrefix = "top";
break;
case 'streams':
Expand Down
10 changes: 8 additions & 2 deletions components/Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function ComponentDetails()
{
return [
'name' => 'digitalronin.twitch::lang.check.name',
'description' => 'digitalronin.twitch::lang.check.description'
'description' => 'digitalronin.twitch::lang.check.description',
];
}

Expand All @@ -32,6 +32,12 @@ public function defineProperties()
'description' => 'digitalronin.twitch::lang.settings.channel_description',
'type' => 'string',
'required' => true
],
'client_id' => [
'title' => 'digitalronin.twitch::lang.settings.channel_client_id',
'description' => 'digitalronin.twitch::lang.settings.channel_client_description',
'type' => 'string',
'required' => true
]
];
}
Expand All @@ -52,6 +58,6 @@ public function onRun()
public function getChannelStatus()
{
$twitch = new TwitchAPI();
return $twitch->isChannelLive($this->property('channel'));
return $twitch->isChannelLive($this->property('channel')."?client_id=".$this->property('client_id'));
}
}
8 changes: 7 additions & 1 deletion components/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public function defineProperties()
'type' => 'string',
'default' => 'No posts found',
'showExternalParam' => false
],
'client_id' => [
'title' => 'digitalronin.twitch::lang.settings.channel_client_id',
'description' => 'digitalronin.twitch::lang.settings.channel_client_description',
'type' => 'string',
'required' => true
]
];
}
Expand All @@ -74,7 +80,7 @@ public function onRun()

protected function listPosts()
{
$requestUrl = "/feed/".$this->property('channel')."/posts";
$requestUrl = "/feed/".$this->property('channel')."/posts"."?client_id=".$this->property('client_id')."&limit=".($this->property('limit')?$this->property('limit'):"0");
$twitch = new TwitchAPI();

return json_decode($twitch->apiRequest($requestUrl), true)["posts"];
Expand Down
6 changes: 6 additions & 0 deletions components/Stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ public function defineProperties()
'description' => 'digitalronin.twitch::lang.settings.chat_width_description',
'type' => 'string',
'default' => '300'
],
'client_id' => [
'title' => 'digitalronin.twitch::lang.settings.channel_client_id',
'description' => 'digitalronin.twitch::lang.settings.channel_client_description',
'type' => 'string',
'required' => true
]
];
}
Expand Down
14 changes: 13 additions & 1 deletion components/Toplist.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ public function defineProperties()
'description' => 'digitalronin.twitch::lang.settings.limit_description',
'type' => 'string',
'default' => '10'
],
'offset' => [
'title' => 'digitalronin.twitch::lang.settings.offset_title',
'description' => 'digitalronin.twitch::lang.settings.offset_description',
'type' => 'string',
'default' => '0'
],
'client_id' => [
'title' => 'digitalronin.twitch::lang.settings.channel_client_id',
'description' => 'digitalronin.twitch::lang.settings.channel_client_description',
'type' => 'string',
'required' => true
]
];
}
Expand All @@ -73,7 +85,7 @@ public function onRun()
public function getTwitchItems()
{
$twitch = new TwitchAPI();
return $twitch->getTopList( $this->toplistType, $this->totalItems );
return $twitch->getTopList( $this->toplistType, $this->totalItems, $this->property('offset'), $this->property('client_id'));
}

/**
Expand Down
4 changes: 4 additions & 0 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
'settings' => [
'channel_name' => 'Channel Name',
'channel_description' => 'Name of the twitch channel.',
'channel_client_id' => 'Client ID',
'channel_client_description' => 'Enter the Client ID of the Twitch Channel you wish to connect to',
'twitch_id_title' => 'Twitch ID',
'twitch_id_description' => 'Channel name for live streams or video id for past broadcast.',
'width_name' => 'Stream Width',
Expand All @@ -18,6 +20,8 @@
'volume_description' => 'Default Volume of the embed Stream/Video.',
'limit_title' => 'Limit',
'limit_description' => 'Limit of Items to show. Default: 10',
'offset_title' => 'Offset',
'offset_description' => 'Offset the items to show. Default: 0',
'posts_no_posts' => 'Show Twitch Feed Posts.',
'posts_no_posts_description' => 'Show Twitch Feed Posts.',
'chat_name' => 'Chat',
Expand Down