From c252829f6a369e0027f28301aa6349594e06f6a0 Mon Sep 17 00:00:00 2001 From: Vishal Sancheti Date: Fri, 14 Jul 2017 11:53:56 +0530 Subject: [PATCH 1/4] Added getCategories method --- src/Youtube.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 From 64bc3367b8bbffabaacf9b8613201ad110b080a4 Mon Sep 17 00:00:00 2001 From: Vishal Sancheti Date: Fri, 14 Jul 2017 12:34:55 +0530 Subject: [PATCH 2/4] Added test for getCategories method --- tests/YoutubeTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/YoutubeTest.php b/tests/YoutubeTest.php index 2df3d7f..50063f8 100644 --- a/tests/YoutubeTest.php +++ b/tests/YoutubeTest.php @@ -56,6 +56,18 @@ public function testInvalidApiKey() $this->youtube->getVideoInfo($vID); } + public function testGetCategoriesInfo() + { + $region = 'US'; + $response = $this->youtube->getCategories($region); + + $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); + } + public function testGetVideoInfo() { $vID = 'rie-hPVJ7Sw'; From 9404b2c0e04a213c7c76d24e0b9840421914ed0b Mon Sep 17 00:00:00 2001 From: Vishal Sancheti Date: Fri, 14 Jul 2017 12:39:15 +0530 Subject: [PATCH 3/4] fixed test case typo --- tests/YoutubeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/YoutubeTest.php b/tests/YoutubeTest.php index 50063f8..9336e0b 100644 --- a/tests/YoutubeTest.php +++ b/tests/YoutubeTest.php @@ -56,7 +56,7 @@ public function testInvalidApiKey() $this->youtube->getVideoInfo($vID); } - public function testGetCategoriesInfo() + public function testGetCategories() { $region = 'US'; $response = $this->youtube->getCategories($region); From 8400383557ff155e2c51a83d60db00a071826c81 Mon Sep 17 00:00:00 2001 From: Vishal Sancheti Date: Fri, 14 Jul 2017 12:59:32 +0530 Subject: [PATCH 4/4] fixed testcase --- tests/YoutubeTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/YoutubeTest.php b/tests/YoutubeTest.php index 9336e0b..641e7a7 100644 --- a/tests/YoutubeTest.php +++ b/tests/YoutubeTest.php @@ -59,13 +59,14 @@ public function testInvalidApiKey() public function testGetCategories() { $region = 'US'; - $response = $this->youtube->getCategories($region); + $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); + $this->assertObjectHasAttribute('snippet', $response[0]); } public function testGetVideoInfo()