Permalink
Browse files

added types

  • Loading branch information...
hrach committed Dec 23, 2017
1 parent 6bf2042 commit fca831beff2aba224df0c70ead4f05ce161fcde2
Showing with 8 additions and 13 deletions.
  1. +7 −11 Nextras/YoutubeApi/Reader.php
  2. +1 −2 Nextras/YoutubeApi/Video.php
@@ -17,7 +17,7 @@ class Reader
{
use Nette\SmartObject;
/** @var string */
const FETCH_URL = 'https://www.googleapis.com/youtube/v3/videos?key=%s&part=snippet,contentDetails&id=%s';
private const FETCH_URL = 'https://www.googleapis.com/youtube/v3/videos?key=%s&part=snippet,contentDetails&id=%s';
/** @var string */
private $apiKey;
@@ -26,7 +26,7 @@ class Reader
private $httpClient;
public function __construct($apiKey, Client $httpClient = null)
public function __construct(string $apiKey, ?Client $httpClient = null)
{
$this->apiKey = $apiKey;
if ($httpClient === null) {
@@ -38,10 +38,8 @@ public function __construct($apiKey, Client $httpClient = null)
/**
* Fetches video data by youtube url
* @param string $videoUrl YouTube url
* @return Video
*/
public function getVideoByUrl($videoUrl)
public function getVideoByUrl(string $videoUrl): Video
{
$url = new Nette\Http\Url($videoUrl);
@@ -59,17 +57,15 @@ public function getVideoByUrl($videoUrl)
/**
* Fetchs video data
* @param string $videoId
* @return Video
* Fetches video data
*/
public function getVideo($videoId)
public function getVideo(string $videoId): Video
{
return $this->parseData($this->getData($videoId), $videoId);
}
protected function getData($videoId)
protected function getData(string $videoId): string
{
$url = sprintf(self::FETCH_URL, $this->apiKey, $videoId);
$response = $this->httpClient->get($url, [
@@ -84,7 +80,7 @@ protected function getData($videoId)
}
protected function parseData($data, $videoId)
protected function parseData(string $data, string $videoId): Video
{
$data = Nette\Utils\Json::decode($data);
if (!isset($data->items[0]->snippet) || !isset($data->items[0]->contentDetails)) {
@@ -11,7 +11,6 @@
use Nette;
class Video
{
use Nette\SmartObject;
@@ -30,7 +29,7 @@ class Video
/** @var array */
public $thumbs;
/** @var string */
public $embed;
}

0 comments on commit fca831b

Please sign in to comment.