diff --git a/src/Youtube.php b/src/Youtube.php index ca76448..db28306 100644 --- a/src/Youtube.php +++ b/src/Youtube.php @@ -14,6 +14,7 @@ class Youtube * @var array */ public $APIs = array( + 'categories.list' => 'https://www.googleapis.com/youtube/v3/videoCategories', 'videos.list' => 'https://www.googleapis.com/youtube/v3/videos', 'search.list' => 'https://www.googleapis.com/youtube/v3/search', 'channels.list' => 'https://www.googleapis.com/youtube/v3/channels', @@ -43,6 +44,24 @@ public function __construct($key) } } + /** + * @param $regionCode + * @return \StdClass + * @throws \Exception + */ + public function getCategories($regionCode = 'US', $part = ['snippet']) + { + $API_URL = $this->getApi('categories.list'); + $params = array( + 'key' => $this->youtube_key, + 'part' => implode(', ', $part), + 'regionCode' => $regionCode + ); + + $apiData = $this->api_get($API_URL, $params); + return $this->decodeMultiple($apiData); + } + /** * @param $vId * @param array $part diff --git a/tests/YoutubeTest.php b/tests/YoutubeTest.php index 2df3d7f..641e7a7 100644 --- a/tests/YoutubeTest.php +++ b/tests/YoutubeTest.php @@ -56,6 +56,19 @@ public function testInvalidApiKey() $this->youtube->getVideoInfo($vID); } + public function testGetCategories() + { + $region = 'US'; + $part = ['snippet']; + $response = $this->youtube->getCategories($region,$part); + + $this->assertNotNull('response'); + $this->assertEquals('youtube#videoCategory', $response[0]->kind); + //add all these assertions here in case the api is changed, + //we can detect it instantly + $this->assertObjectHasAttribute('snippet', $response[0]); + } + public function testGetVideoInfo() { $vID = 'rie-hPVJ7Sw';