Skip to content

Commit

Permalink
Merge pull request #69 from v1shky/master
Browse files Browse the repository at this point in the history
Added getCategories method
  • Loading branch information
alaouy authored Jul 14, 2017
2 parents f1b84de + 8400383 commit e6c0056
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Youtube.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions tests/YoutubeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit e6c0056

Please sign in to comment.