Skip to content

Commit 28533fe

Browse files
committed
Merge pull request #26 from marvin255/get_videos_info
Add getVideosInfo method
2 parents ce61c26 + c8132ce commit 28533fe

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/Madcoda/Youtube.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,24 @@ public function getVideoInfo($vId)
6464
return $this->decodeSingle($apiData);
6565
}
6666

67+
/**
68+
* @param $vIds
69+
* @return \StdClass
70+
* @throws \Exception
71+
*/
72+
public function getVideosInfo($vIds)
73+
{
74+
$ids = is_array($vIds) ? implode(',', $vIds) : $vIds;
75+
$API_URL = $this->getApi('videos.list');
76+
$params = array(
77+
'id' => $ids,
78+
'part' => 'id, snippet, contentDetails, player, statistics, status'
79+
);
80+
81+
$apiData = $this->api_get($API_URL, $params);
82+
return $this->decodeList($apiData);
83+
}
84+
6785
/**
6886
* Simple search interface, this search all stuffs
6987
* and order by relevance

test/Madcoda/Tests/YoutubeTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,24 @@ public function testGetVideoInfo()
8282
$this->assertObjectHasAttribute('contentDetails', $response);
8383
}
8484

85+
public function testGetVideosInfo()
86+
{
87+
$vID = array('rie-hPVJ7Sw', 'lRRk97FYLJM');
88+
$response = $this->youtube->getVideosInfo($vID);
89+
$this->assertInternalType('array', $response);
90+
91+
foreach ($response as $value) {
92+
$this->assertContains($value->id, $vID);
93+
$this->assertEquals('youtube#video', $value->kind);
94+
//add all these assertions here in case the api is changed,
95+
//we can detect it instantly
96+
$this->assertObjectHasAttribute('statistics', $value);
97+
$this->assertObjectHasAttribute('status', $value);
98+
$this->assertObjectHasAttribute('snippet', $value);
99+
$this->assertObjectHasAttribute('contentDetails', $value);
100+
}
101+
}
102+
85103
public function testSearch()
86104
{
87105
$limit = rand(3, 10);

0 commit comments

Comments
 (0)