Alaouy\Youtube\Youtube::getChannelByName PHP Method

getChannelByName() public method

public getChannelByName ( $username, $optionalParams = false, $part = ['id', 'snippet', 'contentDetails', 'statistics', 'invideoPromotion'] ) : StdClass
$username
return StdClass
    public function getChannelByName($username, $optionalParams = false, $part = ['id', 'snippet', 'contentDetails', 'statistics', 'invideoPromotion'])
    {
        $API_URL = $this->getApi('channels.list');
        $params = array('forUsername' => $username, 'part' => implode(', ', $part));
        if ($optionalParams) {
            $params = array_merge($params, $optionalParams);
        }
        $apiData = $this->api_get($API_URL, $params);
        return $this->decodeSingle($apiData);
    }

Usage Example

 public function testGetChannelByName()
 {
     $response = $this->youtube->getChannelByName('Google');
     $this->assertEquals('youtube#channel', $response->kind);
     //This is not a safe Assertion because the name can change, but include it anyway
     $this->assertEquals('Google', $response->snippet->title);
     //add all these assertions here in case the api is changed,
     //we can detect it instantly
     $this->assertObjectHasAttribute('snippet', $response);
     $this->assertObjectHasAttribute('contentDetails', $response);
     $this->assertObjectHasAttribute('statistics', $response);
 }