Skip to content

Commit

Permalink
Merge pull request #55 from JavierMartinz/patch-1
Browse files Browse the repository at this point in the history
Add getChannelsById
  • Loading branch information
madcoda authored Mar 27, 2017
2 parents 4df5de3 + 45f7f83 commit 6494855
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Youtube.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,24 @@ public function getChannelById($id, $optionalParams = false)
return $this->decodeSingle($apiData);
}

/**
* @param array $ids
* @return \StdClass
* @throws \Exception
*/
public function getChannelsById($ids = array(), $optionalParams = false)
{
$API_URL = $this->getApi('channels.list');
$params = array(
'id' => implode(',', $ids),
'part' => 'id,snippet,contentDetails,statistics,invideoPromotion'
);
if($optionalParams){
$params = array_merge($params, $optionalParams);
}
$apiData = $this->api_get($API_URL, $params);
return $this->decodeList($apiData);
}

/**
* @param $channelId
Expand Down
13 changes: 13 additions & 0 deletions tests/YoutubeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ public function testGetChannelById()
$this->assertObjectHasAttribute('statistics', $response);
}

public function testGetChannelsById()
{
$channels = array('UCk1SpWNzOs4MYmr0uICEntg', 'UCK8sQmJBp8GCxrOtXWBpyEA');
$response = $this->youtube->getChannelsById($channels, $this->optionParams);

$this->assertTrue(count($response) === 2);
$this->assertEquals('youtube#channel', $response[0]->kind);
$this->assertObjectHasAttribute('snippet', $response[0]);
$this->assertObjectHasAttribute('contentDetails', $response[0]);
$this->assertObjectHasAttribute('statistics', $response[0]);
}


public function testGetPlaylistsByChannelId()
{
$GOOGLE_CHANNELID = 'UCK8sQmJBp8GCxrOtXWBpyEA';
Expand Down

0 comments on commit 6494855

Please sign in to comment.