From b55f894db05e843f1fea698556e9eaea3383d444 Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Wed, 3 Sep 2014 23:47:09 +0200 Subject: [PATCH 01/23] Updated composer.json & api factory --- composer.json | 19 +++++++++------ lib/Nekland/YoutubeApi/Youtube.php | 37 ++++++++++-------------------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/composer.json b/composer.json index 92d246b..515b72c 100644 --- a/composer.json +++ b/composer.json @@ -1,21 +1,26 @@ { "name": "nekland/youtube-api", "type": "library", - "description": "Simple library you can build you're api upon.", - "keywords": ["nekland", "api", "base"], + "description": "Youtube API made easy !", + "keywords": ["nekland", "api", "youtube"], "license": "MIT", "authors": [ { "name": "Maxime Veber", - "email": "nekland@gmail.com", + "email": "nek.dev@gmail.com", "homepage": "http://nekland.fr" + }, + { + "name": "Nekland Team", + "email": "team@nekland.fr", + "homepage": "http://team.nekland.fr" } ], "require": { - "php": ">=5.4", - "guzzle/guzzle": ">=3.7", - "nekland/base-api": "~0.0.1", - "namshi/jose": "~1.2" + "php": ">=5.4", + "guzzlehttp/guzzle": "~4.0", + "nekland/base-api": "~1.0", + "namshi/jose": "~1.2" }, "suggest": { "nekland/soundcloud-api": "Soundcloud API made easy !" diff --git a/lib/Nekland/YoutubeApi/Youtube.php b/lib/Nekland/YoutubeApi/Youtube.php index f7442f5..765ce0b 100644 --- a/lib/Nekland/YoutubeApi/Youtube.php +++ b/lib/Nekland/YoutubeApi/Youtube.php @@ -12,37 +12,24 @@ namespace Nekland\YoutubeApi; use Nekland\BaseApi\Api; +use Nekland\BaseApi\ApiFactory; use Nekland\BaseApi\Http\ClientInterface; use Nekland\YoutubeApi\Http\HttpClient; -class Youtube extends Api +/** + * Class Youtube + * @method \Nekland\YoutubeApi\Api\Videos getVideosApi + */ +class Youtube extends ApiFactory { /** - * @param ClientInterface $httpClient - */ - public function __construct(ClientInterface $httpClient=null) - { - if (null === $httpClient) { - parent::__construct(new HttpClient()); - } else { - parent::__construct($httpClient); - } - } - - /** - * @param string $name - * @return Api\AbstractApi - * @throws \InvalidArgumentException + * Return array of namespaces where AbstractApi instance are localized + * + * + * @return string[] Example: ['Nekland\BaseApi\Api'] */ - public function api($name) + protected function getApiNamespaces() { - switch($name) { - case 'videos': - return new \Nekland\YoutubeApi\Api\Videos($this); - case 'playlists': - return new \Nekland\YoutubeApi\Api\Playlists($this); - default: - throw new \InvalidArgumentException(sprintf('Undefined api instance called: "%s"', $name)); - } + return ['Nekland\YoutubeApi\Api']; } } From a0450fe759984960e8cfd2722adb0b285777873e Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Wed, 3 Sep 2014 23:59:26 +0200 Subject: [PATCH 02/23] Added more adaptations for base api --- .../YoutubeApi/Api/Behavior/ListTrait.php | 8 ++++---- lib/Nekland/YoutubeApi/Api/Videos.php | 2 +- .../Http/Auth/PublicApiAccessAuth.php | 20 +++++++------------ lib/Nekland/YoutubeApi/Youtube.php | 3 +-- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/lib/Nekland/YoutubeApi/Api/Behavior/ListTrait.php b/lib/Nekland/YoutubeApi/Api/Behavior/ListTrait.php index 5ec779b..4c37154 100644 --- a/lib/Nekland/YoutubeApi/Api/Behavior/ListTrait.php +++ b/lib/Nekland/YoutubeApi/Api/Behavior/ListTrait.php @@ -21,12 +21,12 @@ trait ListTrait */ public function listById($id, array $parts = ['snippet'], array $otherParameters = []) { - $parameters = array_merge( + $body = array_merge( ['part' => implode(',', $parts), 'id' => $id], $otherParameters ); - return $this->get(static::URL, $parameters); + return $this->get(static::URL, $body); } /** @@ -50,12 +50,12 @@ public function getById($id, array $parts = ['snippet'], array $otherParameters */ public function listBy(array $filters, array $parts = ['snippet'], array $otherParameters = []) { - $parameters = array_merge( + $body = array_merge( ['part' => $parts], $filters, $otherParameters ); - return $this->get(static::URL, $parameters); + return $this->get(static::URL, $body); } } diff --git a/lib/Nekland/YoutubeApi/Api/Videos.php b/lib/Nekland/YoutubeApi/Api/Videos.php index 3bf8d07..e0517c3 100644 --- a/lib/Nekland/YoutubeApi/Api/Videos.php +++ b/lib/Nekland/YoutubeApi/Api/Videos.php @@ -10,10 +10,10 @@ */ namespace Nekland\YoutubeApi\Api; + use Nekland\BaseApi\Api\AbstractApi; use Nekland\YoutubeApi\Api\Behavior\ListTrait; - /** * Class Videos * diff --git a/lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccessAuth.php b/lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccessAuth.php index f8d8c8d..edd4000 100644 --- a/lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccessAuth.php +++ b/lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccessAuth.php @@ -12,21 +12,17 @@ namespace Nekland\YoutubeApi\Http\Auth; -use Nekland\BaseApi\Http\Auth\AuthInterface; +use Nekland\BaseApi\Http\Auth\AuthStrategyInterface; +use Nekland\BaseApi\Http\Event\RequestEvent; use Nekland\YoutubeApi\Exception\MissingOptionException; -class PublicApiAccessAuth implements AuthInterface +class PublicApiAccessAuth implements AuthStrategyInterface { /** * @var array */ private $options; - /** - * @param array $options - * @return self - * @throws \Nekland\YoutubeApi\Exception\MissingOptionException - */ public function setOptions(array $options) { if (empty($options['key'])) { @@ -38,16 +34,14 @@ public function setOptions(array $options) $this->options = $options; } - /** - * @param \Guzzle\Http\Message\Request $request - */ - public function auth(\Guzzle\Http\Message\Request $request) + public function auth(RequestEvent $event) { - $url = (string) $request->getUrl(); + $request = $event->getRequest(); + $url = $request->getPath(); $url .= (false === strpos($url, '?') ? '?' : '&'); $url .= 'key=' . $this->options['key']; - $request->setUrl($url); + $request->setPath($url); } } diff --git a/lib/Nekland/YoutubeApi/Youtube.php b/lib/Nekland/YoutubeApi/Youtube.php index 765ce0b..8b74739 100644 --- a/lib/Nekland/YoutubeApi/Youtube.php +++ b/lib/Nekland/YoutubeApi/Youtube.php @@ -17,15 +17,14 @@ use Nekland\YoutubeApi\Http\HttpClient; /** - * Class Youtube * @method \Nekland\YoutubeApi\Api\Videos getVideosApi + * @method \Nekland\YoutubeApi\Api\Playlists getPlaylistsApi */ class Youtube extends ApiFactory { /** * Return array of namespaces where AbstractApi instance are localized * - * * @return string[] Example: ['Nekland\BaseApi\Api'] */ protected function getApiNamespaces() From 9b2de717b389fbdb8994d3921d049a5fb1975e92 Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sat, 6 Sep 2014 01:03:38 +0200 Subject: [PATCH 03/23] Fixed api factory --- lib/Nekland/YoutubeApi/Youtube.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/Nekland/YoutubeApi/Youtube.php b/lib/Nekland/YoutubeApi/Youtube.php index 8b74739..df7dee7 100644 --- a/lib/Nekland/YoutubeApi/Youtube.php +++ b/lib/Nekland/YoutubeApi/Youtube.php @@ -14,6 +14,7 @@ use Nekland\BaseApi\Api; use Nekland\BaseApi\ApiFactory; use Nekland\BaseApi\Http\ClientInterface; +use Nekland\BaseApi\Http\HttpClientFactory; use Nekland\YoutubeApi\Http\HttpClient; /** @@ -22,6 +23,20 @@ */ class Youtube extends ApiFactory { + /** + * @var array + */ + private $options = [ + 'base_url' => 'https://www.googleapis.com/', + 'user_agent' => 'php-youtube-api (https://github.com/Nekland/YoutubeApi)' + ]; + + public function __construct(array $option = []) + { + $this->options = array_merge_recursive($this->options, $option); + parent::__construct(new HttpClientFactory($this->options)); + } + /** * Return array of namespaces where AbstractApi instance are localized * From 8fbe5f7273f17107d6b5f6e9ef9ce7610b85de76 Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sat, 6 Sep 2014 09:56:55 +0200 Subject: [PATCH 04/23] Added youtube api namespace for auth strategies --- lib/Nekland/YoutubeApi/Youtube.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Nekland/YoutubeApi/Youtube.php b/lib/Nekland/YoutubeApi/Youtube.php index df7dee7..5b71cbe 100644 --- a/lib/Nekland/YoutubeApi/Youtube.php +++ b/lib/Nekland/YoutubeApi/Youtube.php @@ -13,9 +13,7 @@ use Nekland\BaseApi\Api; use Nekland\BaseApi\ApiFactory; -use Nekland\BaseApi\Http\ClientInterface; use Nekland\BaseApi\Http\HttpClientFactory; -use Nekland\YoutubeApi\Http\HttpClient; /** * @method \Nekland\YoutubeApi\Api\Videos getVideosApi @@ -35,6 +33,8 @@ public function __construct(array $option = []) { $this->options = array_merge_recursive($this->options, $option); parent::__construct(new HttpClientFactory($this->options)); + + $this->getAuthFactory()->addNamespace('Nekland\YoutubeApi\Http\Auth'); } /** From 6aa32719c54ae0c17788385908c4f6d83eeb72fa Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sat, 6 Sep 2014 10:24:53 +0200 Subject: [PATCH 05/23] Fixed auths --- composer.json | 8 +++++++- .../Auth/{PublicApiAccessAuth.php => PublicApiAccess.php} | 2 +- .../YoutubeApi/Http/Auth/{ServiceAuth.php => Service.php} | 3 ++- lib/Nekland/YoutubeApi/Youtube.php | 4 ++-- 4 files changed, 12 insertions(+), 5 deletions(-) rename lib/Nekland/YoutubeApi/Http/Auth/{PublicApiAccessAuth.php => PublicApiAccess.php} (94%) rename lib/Nekland/YoutubeApi/Http/Auth/{ServiceAuth.php => Service.php} (97%) diff --git a/composer.json b/composer.json index 515b72c..368185e 100644 --- a/composer.json +++ b/composer.json @@ -29,6 +29,12 @@ "psr-0": { "Nekland\\": "lib/" } }, "require-dev": { - "phpunit/phpunit": ">=3.7" + "phpspec/phpspec": "~2.0" + }, + "minimum-stability": "dev", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } } } diff --git a/lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccessAuth.php b/lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccess.php similarity index 94% rename from lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccessAuth.php rename to lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccess.php index edd4000..62326f2 100644 --- a/lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccessAuth.php +++ b/lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccess.php @@ -16,7 +16,7 @@ use Nekland\BaseApi\Http\Event\RequestEvent; use Nekland\YoutubeApi\Exception\MissingOptionException; -class PublicApiAccessAuth implements AuthStrategyInterface +class PublicApiAccess implements AuthStrategyInterface { /** * @var array diff --git a/lib/Nekland/YoutubeApi/Http/Auth/ServiceAuth.php b/lib/Nekland/YoutubeApi/Http/Auth/Service.php similarity index 97% rename from lib/Nekland/YoutubeApi/Http/Auth/ServiceAuth.php rename to lib/Nekland/YoutubeApi/Http/Auth/Service.php index 54efff5..6d4363c 100644 --- a/lib/Nekland/YoutubeApi/Http/Auth/ServiceAuth.php +++ b/lib/Nekland/YoutubeApi/Http/Auth/Service.php @@ -15,10 +15,11 @@ use Guzzle\Http\Client; use Namshi\JOSE\JWS; use Nekland\BaseApi\Http\Auth\AuthInterface; +use Nekland\BaseApi\Http\Auth\AuthStrategyInterface; use Nekland\YoutubeApi\Exception\AuthException; use Nekland\YoutubeApi\Exception\MissingOptionException; -class ServiceAuth implements AuthInterface +class Service implements AuthStrategyInterface { /** * @var array diff --git a/lib/Nekland/YoutubeApi/Youtube.php b/lib/Nekland/YoutubeApi/Youtube.php index 5b71cbe..c007bac 100644 --- a/lib/Nekland/YoutubeApi/Youtube.php +++ b/lib/Nekland/YoutubeApi/Youtube.php @@ -29,9 +29,9 @@ class Youtube extends ApiFactory 'user_agent' => 'php-youtube-api (https://github.com/Nekland/YoutubeApi)' ]; - public function __construct(array $option = []) + public function __construct(array $options = []) { - $this->options = array_merge_recursive($this->options, $option); + $this->options = array_merge($this->options, $options); parent::__construct(new HttpClientFactory($this->options)); $this->getAuthFactory()->addNamespace('Nekland\YoutubeApi\Http\Auth'); From baa0db9a400bbedf865f82a06f318ed11501d67c Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sat, 6 Sep 2014 11:01:35 +0200 Subject: [PATCH 06/23] Switched to phpspec --- .travis.yml | 6 +--- CHANGELOG.md | 14 ++++++++ .../YoutubeApi/Http/Auth/PublicApiAccess.php | 1 - lib/Nekland/YoutubeApi/Youtube.php | 11 ++++++- .../Http/Auth/PublicApiAccessSpec.php | 28 ++++++++++++++++ spec/Nekland/YoutubeApi/YoutubeSpec.php | 33 +++++++++++++++++++ 6 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 spec/Nekland/YoutubeApi/Http/Auth/PublicApiAccessSpec.php create mode 100644 spec/Nekland/YoutubeApi/YoutubeSpec.php diff --git a/.travis.yml b/.travis.yml index e0b70af..5412970 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,7 @@ php: - 5.5 - hhvm -matrix: - allow_failures: - - php: hhvm - before_script: - composer install --dev --prefer-source -script: phpunit --coverage-text \ No newline at end of file +script: vendor/bin/phpspec run diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..11291d7 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,14 @@ +1.0.0 (2014-09-XX) +================== + +Most changes are because of the new base api release. + +New features +------------ + + +Changes +----------- + +* Configuring authentication is now possible by using the method `useAuthentication` +* Getting API classes is done via getter, before: `->api('videos')`, now: `->getVideosApi()` this method is IDE-friendly diff --git a/lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccess.php b/lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccess.php index 62326f2..f0e6b78 100644 --- a/lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccess.php +++ b/lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccess.php @@ -11,7 +11,6 @@ namespace Nekland\YoutubeApi\Http\Auth; - use Nekland\BaseApi\Http\Auth\AuthStrategyInterface; use Nekland\BaseApi\Http\Event\RequestEvent; use Nekland\YoutubeApi\Exception\MissingOptionException; diff --git a/lib/Nekland/YoutubeApi/Youtube.php b/lib/Nekland/YoutubeApi/Youtube.php index c007bac..88eeb45 100644 --- a/lib/Nekland/YoutubeApi/Youtube.php +++ b/lib/Nekland/YoutubeApi/Youtube.php @@ -13,7 +13,10 @@ use Nekland\BaseApi\Api; use Nekland\BaseApi\ApiFactory; +use Nekland\BaseApi\Http\Auth\AuthFactory; use Nekland\BaseApi\Http\HttpClientFactory; +use Nekland\BaseApi\Transformer\TransformerInterface; +use Symfony\Component\EventDispatcher\EventDispatcher; /** * @method \Nekland\YoutubeApi\Api\Videos getVideosApi @@ -29,7 +32,13 @@ class Youtube extends ApiFactory 'user_agent' => 'php-youtube-api (https://github.com/Nekland/YoutubeApi)' ]; - public function __construct(array $options = []) + public function __construct( + array $options = [], + HttpClientFactory $httpClientFactory = null, + EventDispatcher $dispatcher = null, + TransformerInterface $transformer = null, + AuthFactory $authFactory = null + ) { $this->options = array_merge($this->options, $options); parent::__construct(new HttpClientFactory($this->options)); diff --git a/spec/Nekland/YoutubeApi/Http/Auth/PublicApiAccessSpec.php b/spec/Nekland/YoutubeApi/Http/Auth/PublicApiAccessSpec.php new file mode 100644 index 0000000..2a886c8 --- /dev/null +++ b/spec/Nekland/YoutubeApi/Http/Auth/PublicApiAccessSpec.php @@ -0,0 +1,28 @@ +shouldHaveType('Nekland\YoutubeApi\Http\Auth\PublicApiAccess'); + $this->shouldHaveType('Nekland\BaseApi\Http\Auth\AuthStrategyInterface'); + } + + public function it_should_add_a_key_to_the_url_of_the_request(RequestEvent $requestEvent, Request $request) + { + $requestEvent->getRequest()->willReturn($request); + + $request->getPath()->willReturn('http://foo.bar/api'); + $request->setPath('http://foo.bar/api?key=my_custom_api_key')->shouldBeCalled(); + + $this->setOptions(['key' => 'my_custom_api_key']); + $this->auth($requestEvent); + } +} diff --git a/spec/Nekland/YoutubeApi/YoutubeSpec.php b/spec/Nekland/YoutubeApi/YoutubeSpec.php new file mode 100644 index 0000000..2d76da4 --- /dev/null +++ b/spec/Nekland/YoutubeApi/YoutubeSpec.php @@ -0,0 +1,33 @@ +shouldHaveType('Nekland\YoutubeApi\Youtube'); + } + + public function let( + HttpClientFactory $httpClientFactory, + EventDispatcher $dispatcher, + TransformerInterface $transformer, + AuthFactory $authFactory + ) { + $this->beConstructedWith( + [], + $httpClientFactory, + $dispatcher, + $transformer, + $authFactory + ); + } +} From 2c6d7085a6828524214332b75a8a62d6c8356d1c Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Wed, 10 Sep 2014 20:57:30 +0200 Subject: [PATCH 07/23] Started fixed service auth --- CHANGELOG.md | 1 + lib/Nekland/YoutubeApi/Http/Auth/Service.php | 23 ++++---------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11291d7..4a4871a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Most changes are because of the new base api release. New features ------------ +* Compatibility with HHVM Changes ----------- diff --git a/lib/Nekland/YoutubeApi/Http/Auth/Service.php b/lib/Nekland/YoutubeApi/Http/Auth/Service.php index 6d4363c..932868e 100644 --- a/lib/Nekland/YoutubeApi/Http/Auth/Service.php +++ b/lib/Nekland/YoutubeApi/Http/Auth/Service.php @@ -16,6 +16,7 @@ use Namshi\JOSE\JWS; use Nekland\BaseApi\Http\Auth\AuthInterface; use Nekland\BaseApi\Http\Auth\AuthStrategyInterface; +use Nekland\BaseApi\Http\Event\RequestEvent; use Nekland\YoutubeApi\Exception\AuthException; use Nekland\YoutubeApi\Exception\MissingOptionException; @@ -27,27 +28,11 @@ class Service implements AuthStrategyInterface private $options; /** - * @var \Guzzle\Http\ClientInterface + * @param RequestEvent $request */ - private $client; - - /** - * @param \Guzzle\Http\ClientInterface $client - */ - public function __construct(\Guzzle\Http\ClientInterface $client=null) - { - if (null === $client) { - $this->client = new Client(); - } else { - $this->client = $client; - } - } - - /** - * @param \Guzzle\Http\Message\Request $request - */ - public function auth(\Guzzle\Http\Message\Request $request) + public function auth(RequestEvent $requestEvent) { + $request = $requestEvent->getRequest(); if (!$request->hasHeader('Authorization')) { $token = $this->getToken(); $request->addHeader('Authorization', 'Bearer '.$token); From c3dcdf79dfa2f16854774bbfebf7f7d2d1873c27 Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sat, 13 Sep 2014 13:15:15 +0200 Subject: [PATCH 08/23] Adapt auths --- .../YoutubeApi/Http/Auth/PublicApiAccess.php | 6 +---- lib/Nekland/YoutubeApi/Http/Auth/Service.php | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccess.php b/lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccess.php index f0e6b78..f16b4f9 100644 --- a/lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccess.php +++ b/lib/Nekland/YoutubeApi/Http/Auth/PublicApiAccess.php @@ -36,11 +36,7 @@ public function setOptions(array $options) public function auth(RequestEvent $event) { $request = $event->getRequest(); - $url = $request->getPath(); - $url .= (false === strpos($url, '?') ? '?' : '&'); - $url .= 'key=' . $this->options['key']; - - $request->setPath($url); + $request->setParameter('key', $this->options['key']); } } diff --git a/lib/Nekland/YoutubeApi/Http/Auth/Service.php b/lib/Nekland/YoutubeApi/Http/Auth/Service.php index 932868e..3de9205 100644 --- a/lib/Nekland/YoutubeApi/Http/Auth/Service.php +++ b/lib/Nekland/YoutubeApi/Http/Auth/Service.php @@ -11,12 +11,13 @@ namespace Nekland\YoutubeApi\Http\Auth; - use Guzzle\Http\Client; use Namshi\JOSE\JWS; +use Nekland\BaseApi\Http\AbstractHttpClient; use Nekland\BaseApi\Http\Auth\AuthInterface; use Nekland\BaseApi\Http\Auth\AuthStrategyInterface; use Nekland\BaseApi\Http\Event\RequestEvent; +use Nekland\BaseApi\Http\Request; use Nekland\YoutubeApi\Exception\AuthException; use Nekland\YoutubeApi\Exception\MissingOptionException; @@ -28,14 +29,21 @@ class Service implements AuthStrategyInterface private $options; /** - * @param RequestEvent $request + * @var AbstractHttpClient + */ + private $client; + + /** + * @param RequestEvent $requestEvent */ public function auth(RequestEvent $requestEvent) { $request = $requestEvent->getRequest(); + if (!$request->hasHeader('Authorization')) { + $this->client = $requestEvent->getClient(); $token = $this->getToken(); - $request->addHeader('Authorization', 'Bearer '.$token); + $request->setHeader('Authorization', 'Bearer '.$token); } } @@ -55,17 +63,17 @@ private function getToken() $jws->sign($this->getPrivateKey()); - $response = $this->client->post( + $response = $this->client->send(new Request( + 'post', 'https://accounts.google.com/o/oauth2/token', - ['Content-Type' => 'application/x-www-form-urlencoded'], [ 'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer', 'assertion' => $jws->getTokenString() ], - ['debug' => true] - ); + ['Content-Type' => 'application/x-www-form-urlencoded'] + ), false); - $finalArray = json_decode((string) $response->send()->getBody(), true); + $finalArray = json_decode($response, true); return $finalArray['access_token']; } @@ -110,7 +118,7 @@ private function getOption($option, $default=null) /** * @param array $options - * @return AuthInterface + * @return self */ public function setOptions(array $options) { From 5047a8bc0cbb8c7eff80f7b7364db179fdc482a9 Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sat, 13 Sep 2014 14:09:06 +0200 Subject: [PATCH 09/23] Added service class --- lib/Nekland/YoutubeApi/Http/Auth/Service.php | 2 +- .../Http/Auth/PublicApiAccessSpec.php | 2 +- .../YoutubeApi/Http/Auth/ServiceSpec.php | 44 ++++++++++++++++++ {test/test_data => spec/fixtures}/cert.p12 | Bin 4 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 spec/Nekland/YoutubeApi/Http/Auth/ServiceSpec.php rename {test/test_data => spec/fixtures}/cert.p12 (100%) diff --git a/lib/Nekland/YoutubeApi/Http/Auth/Service.php b/lib/Nekland/YoutubeApi/Http/Auth/Service.php index 3de9205..216833b 100644 --- a/lib/Nekland/YoutubeApi/Http/Auth/Service.php +++ b/lib/Nekland/YoutubeApi/Http/Auth/Service.php @@ -43,7 +43,7 @@ public function auth(RequestEvent $requestEvent) if (!$request->hasHeader('Authorization')) { $this->client = $requestEvent->getClient(); $token = $this->getToken(); - $request->setHeader('Authorization', 'Bearer '.$token); + $request->setHeader('Authorization', 'Bearer ' . $token); } } diff --git a/spec/Nekland/YoutubeApi/Http/Auth/PublicApiAccessSpec.php b/spec/Nekland/YoutubeApi/Http/Auth/PublicApiAccessSpec.php index 2a886c8..f83c6ac 100644 --- a/spec/Nekland/YoutubeApi/Http/Auth/PublicApiAccessSpec.php +++ b/spec/Nekland/YoutubeApi/Http/Auth/PublicApiAccessSpec.php @@ -20,7 +20,7 @@ public function it_should_add_a_key_to_the_url_of_the_request(RequestEvent $requ $requestEvent->getRequest()->willReturn($request); $request->getPath()->willReturn('http://foo.bar/api'); - $request->setPath('http://foo.bar/api?key=my_custom_api_key')->shouldBeCalled(); + $request->setParameter('key','my_custom_api_key')->shouldBeCalled(); $this->setOptions(['key' => 'my_custom_api_key']); $this->auth($requestEvent); diff --git a/spec/Nekland/YoutubeApi/Http/Auth/ServiceSpec.php b/spec/Nekland/YoutubeApi/Http/Auth/ServiceSpec.php new file mode 100644 index 0000000..3953279 --- /dev/null +++ b/spec/Nekland/YoutubeApi/Http/Auth/ServiceSpec.php @@ -0,0 +1,44 @@ +shouldHaveType('Nekland\YoutubeApi\Http\Auth\Service'); + $this->shouldHaveType('Nekland\BaseApi\Http\Auth\AuthStrategyInterface'); + } + + public function it_should_do_nothing_if_header_already_defined(RequestEvent $requestEvent, Request $request) + { + $requestEvent->getRequest()->willReturn($request); + $request->hasHeader('Authorization')->willReturn(true); + $requestEvent->getClient()->shouldNotBeCalled(); + + $this->auth($requestEvent); + } + + public function it_should_send_a_request_and_add_a_header(RequestEvent $requestEvent, Request $request, AbstractHttpClient $client) + { + $requestEvent->getRequest()->willReturn($request); + $requestEvent->getClient()->willReturn($client); + + $request->hasHeader(Argument::any())->willReturn(false); + $request->setHeader('Authorization', 'Bearer foobar')->shouldBeCalled(); + $client->send(Argument::type('Nekland\BaseApi\Http\Request'), Argument::any())->willReturn('{"access_token": "foobar"}'); + + // Notice: this certificate is a fake one + $this->setOptions([ + 'cert_file' => __DIR__ . '/../../../../fixtures/cert.p12', + 'email' => 'myemail_for_google_service@googleapi_etc.com' + ]); + $this->auth($requestEvent); + } +} diff --git a/test/test_data/cert.p12 b/spec/fixtures/cert.p12 similarity index 100% rename from test/test_data/cert.p12 rename to spec/fixtures/cert.p12 From 43f228629e5b271f61641d1f938f1a651ee5221d Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sun, 14 Sep 2014 17:20:23 +0200 Subject: [PATCH 10/23] Removed old tests and add transformers --- .travis.yml | 4 + docs/Api/playlists.md | 4 +- lib/Nekland/YoutubeApi/Api/Playlists.php | 12 ++- lib/Nekland/YoutubeApi/Api/Videos.php | 12 ++- lib/Nekland/YoutubeApi/Http/Auth/Service.php | 5 ++ lib/Nekland/YoutubeApi/Http/HttpClient.php | 32 ------- .../Transformer/Hydrator/Hydrator.php | 26 ++++++ .../Hydrator/HydratorInterface.php | 23 +++++ .../Transformer/Model/Collection.php | 18 ++++ .../YoutubeApi/Transformer/Model/Item.php | 23 +++++ .../YoutubeApi/Transformer/Model/Video.php | 18 ++++ .../Transformer/ModelTransformer.php | 63 +++++++++++++ phpunit.xml | 31 ------- test/Nekland/Tests/Api/PlaylistsTest.php | 88 ------------------- test/Nekland/Tests/Api/TestCase.php | 36 -------- test/Nekland/Tests/Api/VideosTest.php | 74 ---------------- .../Http/Auth/PublicApiAccessAuthTest.php | 48 ---------- .../Tests/Http/Auth/ServiceAuthTest.php | 85 ------------------ test/Nekland/Tests/Http/HttpClientTest.php | 36 -------- test/Nekland/Tests/YoutubeTest.php | 36 -------- test/bootstrap.php | 18 ---- 21 files changed, 202 insertions(+), 490 deletions(-) delete mode 100644 lib/Nekland/YoutubeApi/Http/HttpClient.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Hydrator/Hydrator.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Hydrator/HydratorInterface.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Collection.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Item.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Video.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php delete mode 100644 phpunit.xml delete mode 100644 test/Nekland/Tests/Api/PlaylistsTest.php delete mode 100644 test/Nekland/Tests/Api/TestCase.php delete mode 100644 test/Nekland/Tests/Api/VideosTest.php delete mode 100644 test/Nekland/Tests/Http/Auth/PublicApiAccessAuthTest.php delete mode 100644 test/Nekland/Tests/Http/Auth/ServiceAuthTest.php delete mode 100644 test/Nekland/Tests/Http/HttpClientTest.php delete mode 100644 test/Nekland/Tests/YoutubeTest.php delete mode 100644 test/bootstrap.php diff --git a/.travis.yml b/.travis.yml index 5412970..c86437b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,3 +9,7 @@ before_script: - composer install --dev --prefer-source script: vendor/bin/phpspec run + +matrix: + allow_failures: + - php: hhvm diff --git a/docs/Api/playlists.md b/docs/Api/playlists.md index 3dc8d4a..bcc2688 100644 --- a/docs/Api/playlists.md +++ b/docs/Api/playlists.md @@ -7,7 +7,7 @@ First retrieve the playlist api object (`Nekland\YoutubeApi\Api\Playlists`). api('playlists'); +$playlistApi = $youtube->getPlayslistsApi(); ``` List playlists @@ -72,6 +72,6 @@ The day this lines are written, it's: * id: 0 * player: 0 * snippet: 2 -*status: 2 +* status: 2 > For now the playlist api only retrieve information. More coming ! PRs are accepted on the topic :) . diff --git a/lib/Nekland/YoutubeApi/Api/Playlists.php b/lib/Nekland/YoutubeApi/Api/Playlists.php index 5665269..decca5a 100644 --- a/lib/Nekland/YoutubeApi/Api/Playlists.php +++ b/lib/Nekland/YoutubeApi/Api/Playlists.php @@ -25,7 +25,15 @@ */ class Playlists extends AbstractApi { - const URL = 'youtube/v3/playlists'; - use ListTrait; + + public function getUrl() + { + return 'youtube/v3/playlists'; + } + + public function getType() + { + return 'playlist'; + } } diff --git a/lib/Nekland/YoutubeApi/Api/Videos.php b/lib/Nekland/YoutubeApi/Api/Videos.php index e0517c3..8052c59 100644 --- a/lib/Nekland/YoutubeApi/Api/Videos.php +++ b/lib/Nekland/YoutubeApi/Api/Videos.php @@ -26,7 +26,15 @@ */ class Videos extends AbstractApi { - const URL = 'youtube/v3/videos'; - use ListTrait; + + public function getUrl() + { + return 'youtube/v3/videos'; + } + + public function getType() + { + return 'video'; + } } diff --git a/lib/Nekland/YoutubeApi/Http/Auth/Service.php b/lib/Nekland/YoutubeApi/Http/Auth/Service.php index 216833b..2d47c16 100644 --- a/lib/Nekland/YoutubeApi/Http/Auth/Service.php +++ b/lib/Nekland/YoutubeApi/Http/Auth/Service.php @@ -21,6 +21,11 @@ use Nekland\YoutubeApi\Exception\AuthException; use Nekland\YoutubeApi\Exception\MissingOptionException; +/** + * Allow Service Auth + * + * @see https://developers.google.com/accounts/docs/OAuth2#serviceaccount + */ class Service implements AuthStrategyInterface { /** diff --git a/lib/Nekland/YoutubeApi/Http/HttpClient.php b/lib/Nekland/YoutubeApi/Http/HttpClient.php deleted file mode 100644 index b1fa952..0000000 --- a/lib/Nekland/YoutubeApi/Http/HttpClient.php +++ /dev/null @@ -1,32 +0,0 @@ - - * - * For the full license, take a look to the LICENSE file - * on the root directory of this project - */ - -namespace Nekland\YoutubeApi\Http; - -use Nekland\BaseApi\Http\HttpClient as BaseHttpClient; - -class HttpClient extends BaseHttpClient -{ - /** - * @param array $options - */ - public function __construct(array $options = []) - { - $options = array_merge([ - 'base_url' => 'https://www.googleapis.com/', - 'user_agent' => 'php-youtube-api (https://github.com/Nekland/YoutubeApi)' - ], $options); - - parent::__construct($options); - $this->getAuthFactory()->addNamespace('Nekland\\YoutubeApi\\Http\\Auth'); - } - -} diff --git a/lib/Nekland/YoutubeApi/Transformer/Hydrator/Hydrator.php b/lib/Nekland/YoutubeApi/Transformer/Hydrator/Hydrator.php new file mode 100644 index 0000000..afe018a --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Hydrator/Hydrator.php @@ -0,0 +1,26 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Hydrator; + + +class Hydrator implements HydratorInterface +{ + /** + * @param string $class + * @param array $data + * @return mixed + */ + public function hydrate($class, $data) + { + + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Hydrator/HydratorInterface.php b/lib/Nekland/YoutubeApi/Transformer/Hydrator/HydratorInterface.php new file mode 100644 index 0000000..a0845b2 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Hydrator/HydratorInterface.php @@ -0,0 +1,23 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Hydrator; + + +interface HydratorInterface +{ + /** + * @param string $class + * @param array $data + * @return mixed + */ + public function hydrate($class, $data); +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Collection.php b/lib/Nekland/YoutubeApi/Transformer/Model/Collection.php new file mode 100644 index 0000000..66f0ef7 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Collection.php @@ -0,0 +1,18 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + + +class Collection +{ + private $type; +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Item.php b/lib/Nekland/YoutubeApi/Transformer/Model/Item.php new file mode 100644 index 0000000..51578fb --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Item.php @@ -0,0 +1,23 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + + +class ItemInterface +{ + private $etag; + + public function getEtag() + { + + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Video.php b/lib/Nekland/YoutubeApi/Transformer/Model/Video.php new file mode 100644 index 0000000..806dc46 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Video.php @@ -0,0 +1,18 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + + +class Video +{ + +} diff --git a/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php b/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php new file mode 100644 index 0000000..03c5134 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php @@ -0,0 +1,63 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer; + + +use Nekland\BaseApi\Transformer\TransformerInterface; +use Nekland\YoutubeApi\Transformer\Hydrator\Hydrator; +use Nekland\YoutubeApi\Transformer\Hydrator\HydratorInterface; +use Nekland\YoutubeApi\Transformer\Model\Collection; + +class ModelTransformer implements TransformerInterface +{ + /** + * @var HydratorInterface + */ + private $hydrator; + + public function __construct(HydratorInterface $hydrator = null) + { + $this->hydrator = $hydrator ?: new Hydrator(); + } + + public function transform($data, $type = self::UNKNOWN) + { + if ($type === self::UNKNOWN) { + $data = json_decode($data, true); + + switch ($data['kind']) { + case 'youtube#videoListResponse': + return $this->transformList($data, 'video'); + } + } + } + + /** + * @param array $data + * @param string $type + * @return Collection + */ + public function transformList($data, $type) + { + $final = $this->hydrator->hydrate('\Nekland\YoutubeApi\Transformer\Model\Collection', $data); + $type = $type === 'video' ? + '\Nekland\YoutubeApi\Transformer\Model\Video' : + '\Nekland\YoutubeApi\Transformer\Model\Playlist' + ; + + foreach ($data['items'] as $item) { + $final->add($this->hydrator->hydrate($type, $item)); + } + + return $final; + } +} diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index 90eb7e2..0000000 --- a/phpunit.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - ./test/Nekland/ - - - - - - functional - - - - - - ./lib/Nekland/ - - - \ No newline at end of file diff --git a/test/Nekland/Tests/Api/PlaylistsTest.php b/test/Nekland/Tests/Api/PlaylistsTest.php deleted file mode 100644 index 2ce2a56..0000000 --- a/test/Nekland/Tests/Api/PlaylistsTest.php +++ /dev/null @@ -1,88 +0,0 @@ - - * - * For the full license, take a look to the LICENSE file - * on the root directory of this project - */ - -namespace Nekland\Tests\Api; - - -use Nekland\YoutubeApi\Youtube; - -class PlaylistsTest extends TestCase -{ - - /** - * @test - */ - public function shouldReturnYoutubeArrayAsJson() - { - $youtube = $this->getYoutubeMock(['get' => $this->getPlaylistsList()]); - /** @var \Nekland\YoutubeApi\Api\Videos $videos */ - $videos = $youtube->api('videos'); - - $this->assertEquals($videos->listById('PLXONb89nemXsCa5-v7kO8qbLnCjG9O80f')['etag'], '"gMjDJfS6nsym0T-NKCXALC_u_rM/OS-dz8DrzAjFW7CsH_RCbY99MJc"'); - $this->assertEquals($videos->getById('PLXONb89nemXsCa5-v7kO8qbLnCjG9O80f')['id'], 'PLXONb89nemXsCa5-v7kO8qbLnCjG9O80f'); - $this->assertEquals($videos->listBy(['id' => 'PLXONb89nemXsCa5-v7kO8qbLnCjG9O80f'])['etag'], '"gMjDJfS6nsym0T-NKCXALC_u_rM/OS-dz8DrzAjFW7CsH_RCbY99MJc"'); - } - - private function getPlaylistsList() - { - return << - * - * For the full license, take a look to the LICENSE file - * on the root directory of this project - */ - -namespace Nekland\Tests\Api; - - -use Nekland\YoutubeApi\Youtube; - -class TestCase extends \PHPUnit_Framework_TestCase -{ - /** - * @param array $data an array of method => return for the httpclient mocked - * @return Youtube - */ - protected function getYoutubeMock(array $data) - { - $httpClient = $this->getMock('Nekland\BaseApi\Http\ClientInterface'); - - foreach($data as $method => $return) { - $httpClient->expects($this->any()) - ->method($method) - ->willReturn($return) - ; - } - - return new Youtube($httpClient); - } -} diff --git a/test/Nekland/Tests/Api/VideosTest.php b/test/Nekland/Tests/Api/VideosTest.php deleted file mode 100644 index cd36136..0000000 --- a/test/Nekland/Tests/Api/VideosTest.php +++ /dev/null @@ -1,74 +0,0 @@ - - * - * For the full license, take a look to the LICENSE file - * on the root directory of this project - */ - -namespace Nekland\Tests\Api; - - - -class VideosTest extends TestCase -{ - /** - * @test - */ - public function shouldReturnYoutubeArrayAsJson() - { - $youtube = $this->getYoutubeMock(['get' => $this->getYoutubeList()]); - /** @var \Nekland\YoutubeApi\Api\Playlists $playlists */ - $playlists = $youtube->api('playlists'); - - $this->assertEquals($playlists->listById('DR7e0DoHZ2Y')['etag'], '"X98aQHqGvPBJLZLOiSGUHCM9jnE/DqrNg5r4X93fnTIO0si3XjQXUwY"'); - $this->assertEquals($playlists->getById('DR7e0DoHZ2Y')['id'], 'DR7e0DoHZ2Y'); - $this->assertEquals($playlists->listBy(['id' => 'DR7e0DoHZ2Y'])['etag'], '"X98aQHqGvPBJLZLOiSGUHCM9jnE/DqrNg5r4X93fnTIO0si3XjQXUwY"'); - } - - private function getYoutubeList() - { - return ' -{ - "kind": "youtube#videoListResponse", - "etag": "\\"X98aQHqGvPBJLZLOiSGUHCM9jnE/DqrNg5r4X93fnTIO0si3XjQXUwY\\"", - "pageInfo": { - "totalResults": 1, - "resultsPerPage": 1 - }, - "items": [ - { - "kind": "youtube#video", - "etag": "\\"X98aQHqGvPBJLZLOiSGUHCM9jnE/PYBJAtNy79ShJyHHToh-N89kDH4\\"", - "id": "DR7e0DoHZ2Y", - "snippet": { - "publishedAt": "2014-02-19T18:00:04.000Z", - "channelId": "UCvOGElQWhX8tyTxwzv1rKzg", - "title": "Mystery Skulls - Ghost (Solidisco Remix)\u200f", - "description": "ENM ● New Songs every Monday, Wednesday & Friday!\nDownload it from iTunes: http://bit.ly/1e5u2pM\n\nBecome a fan of Solidisco\nFB: https://facebook.com/solidisco\nSoundcloud: http://soundcloud.com/solidisco\n\nBecome a fan of Mystery Skulls\nFB: https://facebook.com/mysteryskulls\nSoundcloud: http://soundcloud.com/mysteryskulls\n\nFollow Warner bros. Records\nFB: http://facebook.com/WarnerBrosRecords\nYouTube: http://youtube.com/warnerbrosrecords\nhttp://warnerbrosrecords.com\n\nOriginal artwork: http://bit.ly/1bK1bge\n------------------------------------------------------------\nStay connected with us\nFB: http://on.fb.me/tWNN6B\n@epicnetwork\nGoogle+ http://google.com/+EpicNetworkMusic\nSoundcloud: http://snd.sc/1hQlDce\n------------------------------------------------------------\nTrack\'s title: Mystery Skulls - Ghost (Solidisco Remix)\u200f", - "thumbnails": { - "default": { - "url": "https://i1.ytimg.com/vi/DR7e0DoHZ2Y/default.jpg" - }, - "medium": { - "url": "https://i1.ytimg.com/vi/DR7e0DoHZ2Y/mqdefault.jpg" - }, - "high": { - "url": "https://i1.ytimg.com/vi/DR7e0DoHZ2Y/hqdefault.jpg" - }, - "standard": { - "url": "https://i1.ytimg.com/vi/DR7e0DoHZ2Y/sddefault.jpg" - } - }, - "channelTitle": "ENM", - "categoryId": "10", - "liveBroadcastContent": "none" - } - } - ] -}'; - } -} diff --git a/test/Nekland/Tests/Http/Auth/PublicApiAccessAuthTest.php b/test/Nekland/Tests/Http/Auth/PublicApiAccessAuthTest.php deleted file mode 100644 index 97fbf5f..0000000 --- a/test/Nekland/Tests/Http/Auth/PublicApiAccessAuthTest.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * For the full license, take a look to the LICENSE file - * on the root directory of this project - */ - -namespace Nekland\Tests\Http\Auth; - -use Nekland\YoutubeApi\Http\Auth\PublicApiAccessAuth; - -class PublicApiAccessAuthTest extends \PHPUnit_Framework_TestCase -{ - /** - * @test - */ - public function shouldBeConstructWithoutAnyParameter() - { - $auth = new PublicApiAccessAuth(); - $this->assertInstanceOf('Nekland\\YoutubeApi\\Http\\Auth\\PublicApiAccessAuth', $auth); - } - - /** - * @test - */ - public function shouldAddParameterToUrl() - { - $auth = new PublicApiAccessAuth(); - $auth->setOptions(['key' => 'SOME_YOUTUBE_API_KEY']); - - $request = $this->getMockBuilder('Guzzle\Http\Message\Request')->disableOriginalConstructor()->getMock(); - $request - ->expects($this->once()) - ->method('getUrl') - ->willReturn('http://fake.com') - ; - $request - ->expects($this->once()) - ->method('setUrl') - ->with($this->equalTo('http://fake.com?key=SOME_YOUTUBE_API_KEY')) - ; - $auth->auth($request); - } -} diff --git a/test/Nekland/Tests/Http/Auth/ServiceAuthTest.php b/test/Nekland/Tests/Http/Auth/ServiceAuthTest.php deleted file mode 100644 index 934a38a..0000000 --- a/test/Nekland/Tests/Http/Auth/ServiceAuthTest.php +++ /dev/null @@ -1,85 +0,0 @@ - - * - * For the full license, take a look to the LICENSE file - * on the root directory of this project - */ - -namespace Nekland\Tests\Http\Auth; - - -use Guzzle\Http\Message\Request; -use Nekland\YoutubeApi\Http\Auth\ServiceAuth; - -class ServiceAuthTest extends \PHPUnit_Framework_TestCase -{ - /** - * @test - */ - public function shouldBeConstructWithOrWithoutClient() - { - $auth = new ServiceAuth(); - $this->assertInstanceOf('Nekland\\YoutubeApi\\Http\\Auth\\ServiceAuth', $auth); - - $auth = new ServiceAuth($this->getMock('Guzzle\\Http\\ClientInterface')); - $this->assertInstanceOf('Nekland\\YoutubeApi\\Http\\Auth\\ServiceAuth', $auth); - } - - /** - * @test - */ - public function shouldAddTokenToRequest() - { - $auth = new ServiceAuth($this->getClientMock()); - $auth->setOptions(['cert_file' => __DIR__ . '/../../../../test_data/cert.p12', 'email' => 'myemail_for_google_service@googleapi_etc.com']); - $request = new Request('POST', 'http://fake.com'); - $auth->auth($request); - - $this->assertContains('ya29.1.AADHN_WnGjqYiAcnONRLFDOfXia5XZLFO4RSyEhWtQPAvYpgPYiQj89c7UsrAs5_',(string)$request->getHeader('Authorization')); - } - - private function getClientMock() - { - $client = $this->getMock('Guzzle\\Http\\ClientInterface'); - - $request = $this->getMock('Guzzle\\Http\\Message\\EntityEnclosingRequestInterface'); - - $response = $this - ->getMockBuilder('Guzzle\\Http\\Message\\Response') - ->disableOriginalConstructor() - ->getMock() - ; - $response - ->expects($this->any()) - ->method('getBody') - ->willReturn($this->getGoogleResponse()) - ; - - $request - ->expects($this->any()) - ->method('send') - ->willReturn($response) - ; - - $client - ->expects($this->any()) - ->method('post') - ->willReturn($request) - ; - - return $client; - } - - private function getGoogleResponse() - { - return '{ - "access_token" : "ya29.1.AADHN_WnGjqYiAcnONRLFDOfXia5XZLFO4RSyEhWtQPAvYpgPYiQj89c7UsrAs5_", - "token_type" : "Bearer", - "expires_in" : 3600 -}'; - } -} diff --git a/test/Nekland/Tests/Http/HttpClientTest.php b/test/Nekland/Tests/Http/HttpClientTest.php deleted file mode 100644 index 7ba31a7..0000000 --- a/test/Nekland/Tests/Http/HttpClientTest.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full license, take a look to the LICENSE file - * on the root directory of this project - */ - -namespace Nekland\Tests\Http; - - -use Nekland\YoutubeApi\Http\HttpClient; - -class HttpClientTest extends \PHPUnit_Framework_TestCase -{ - /** - * @test - */ - public function isInitializable() - { - $client = new HttpClient(); - $this->assertInstanceOf('Nekland\\YoutubeApi\\Http\\HttpClient', $client); - } - - /** - * @test - */ - public function shouldAcceptASetOfOptions() - { - $client = new HttpClient(['user_agent' => 'Nekland Website']); - $this->assertInstanceOf('Nekland\\YoutubeApi\\Http\\HttpClient', $client); - } -} diff --git a/test/Nekland/Tests/YoutubeTest.php b/test/Nekland/Tests/YoutubeTest.php deleted file mode 100644 index 167ee97..0000000 --- a/test/Nekland/Tests/YoutubeTest.php +++ /dev/null @@ -1,36 +0,0 @@ - - * - * For the full license, take a look to the LICENSE file - * on the root directory of this project - */ - -namespace Nekland\Tests; - - -use Nekland\YoutubeApi\Youtube; - -class YoutubeTest extends \PHPUnit_Framework_TestCase -{ - /** - * @test - */ - public function shouldNotHaveToPassHttpClientToConstructor() - { - $api = new Youtube(); - $this->assertInstanceOf('Nekland\\YoutubeApi\\Http\\HttpClient', $api->getClient()); - } - - /** - * @test - */ - public function shouldAllowToPassHttpClientToConstructor() - { - $api = new Youtube($this->getMock('Nekland\\BaseApi\\Http\\ClientInterface')); - $this->assertInstanceOf('Nekland\\BaseApi\\Http\\ClientInterface', $api->getClient()); - } -} diff --git a/test/bootstrap.php b/test/bootstrap.php deleted file mode 100644 index ade4cbd..0000000 --- a/test/bootstrap.php +++ /dev/null @@ -1,18 +0,0 @@ -add('Nekland\Tests', __DIR__); - -return $loader; \ No newline at end of file From 3b5df98ae9458d13cd12dab2eeffd060f1e3929b Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Mon, 6 Oct 2014 17:07:20 +0200 Subject: [PATCH 11/23] Added Model Transformer --- .travis.yml | 2 + CHANGELOG.md | 1 + .../YoutubeApi/Api/Behavior/ListTrait.php | 14 +- lib/Nekland/YoutubeApi/Cache/Etag.php | 43 +++ .../Transformer/Hydrator/Hydrator.php | 50 +++- .../Hydrator/HydratorInterface.php | 8 +- .../Transformer/Model/Collection.php | 224 ++++++++++++++- .../Transformer/Model/Details/FileDetails.php | 62 +++++ .../Model/Details/LiveStreamingDetails.php | 40 +++ .../Model/Details/ProcessingDetails.php | 55 ++++ .../Model/Details/RecordingDetails.php | 30 ++ .../Transformer/Model/Details/Thumbnail.php | 30 ++ .../Model/Details/TopicDetails.php | 25 ++ .../Model/Details/VideoDetails.php | 50 ++++ .../YoutubeApi/Transformer/Model/Item.php | 64 ++++- .../Transformer/Model/ModelInterface.php | 20 ++ .../YoutubeApi/Transformer/Model/PageInfo.php | 64 +++++ .../Model/Snippet/VideoSnippet.php | 233 ++++++++++++++++ .../Transformer/Model/Standard/Location.php | 30 ++ .../Model/Statistics/VideoStatistics.php | 40 +++ .../Transformer/Model/Status/VideoStatus.php | 55 ++++ .../Model/Suggestions/VideoSuggestions.php | 40 +++ .../YoutubeApi/Transformer/Model/Video.php | 256 +++++++++++++++++- .../Transformer/ModelTransformer.php | 6 +- 24 files changed, 1426 insertions(+), 16 deletions(-) create mode 100644 lib/Nekland/YoutubeApi/Cache/Etag.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Details/FileDetails.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Details/LiveStreamingDetails.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Details/ProcessingDetails.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Details/RecordingDetails.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Details/Thumbnail.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Details/TopicDetails.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Details/VideoDetails.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/ModelInterface.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/PageInfo.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Snippet/VideoSnippet.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Standard/Location.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Statistics/VideoStatistics.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Status/VideoStatus.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Suggestions/VideoSuggestions.php diff --git a/.travis.yml b/.travis.yml index c86437b..c7d627c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,7 @@ language: php php: - 5.4 - 5.5 + - 5.6 - hhvm before_script: @@ -10,6 +11,7 @@ before_script: script: vendor/bin/phpspec run +# YoutubeAPI should be compatible hhvm but tests are not ! matrix: allow_failures: - php: hhvm diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a4871a..6ccacf2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,3 +13,4 @@ Changes * Configuring authentication is now possible by using the method `useAuthentication` * Getting API classes is done via getter, before: `->api('videos')`, now: `->getVideosApi()` this method is IDE-friendly +* Authentication can now use the same client as the api itself diff --git a/lib/Nekland/YoutubeApi/Api/Behavior/ListTrait.php b/lib/Nekland/YoutubeApi/Api/Behavior/ListTrait.php index 4c37154..9b7ba5d 100644 --- a/lib/Nekland/YoutubeApi/Api/Behavior/ListTrait.php +++ b/lib/Nekland/YoutubeApi/Api/Behavior/ListTrait.php @@ -11,6 +11,8 @@ namespace Nekland\YoutubeApi\Api\Behavior; +use Nekland\YoutubeApi\Transformer\Model\Collection; + trait ListTrait { /** @@ -26,7 +28,7 @@ public function listById($id, array $parts = ['snippet'], array $otherParameters $otherParameters ); - return $this->get(static::URL, $body); + return $this->get($this->getUrl(), $body); } /** @@ -39,7 +41,13 @@ public function listById($id, array $parts = ['snippet'], array $otherParameters */ public function getById($id, array $parts = ['snippet'], array $otherParameters = []) { - return $this->listById($id, $parts, $otherParameters)['items'][0]; + $res = $this->listById($id, $parts, $otherParameters); + + if ($res instanceof Collection) { + return $res[0]; + } + + return $res['items'][0]; } /** @@ -56,6 +64,6 @@ public function listBy(array $filters, array $parts = ['snippet'], array $otherP $otherParameters ); - return $this->get(static::URL, $body); + return $this->get($this->getUrl(), $body); } } diff --git a/lib/Nekland/YoutubeApi/Cache/Etag.php b/lib/Nekland/YoutubeApi/Cache/Etag.php new file mode 100644 index 0000000..de88381 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Cache/Etag.php @@ -0,0 +1,43 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +use Nekland\BaseApi\Cache\CacheStrategyInterface; +use Nekland\BaseApi\Http\Event\RequestEvent; +use Nekland\BaseApi\Cache\Provider\CacheProviderInterface; + +class Etag implements CacheStrategyInterface +{ + /** + * @var CacheProviderInterface + */ + private $provider; + + public function execute(RequestEvent $event) + { + $request = $event->getRequest(); + $etag = $this->provider->get($request->getId()); + + if ($etag) { + $request->setHeader('If-None-Match', $etag); + } + } + + public function cache(RequestEvent $event) + { + $body = json_decode($event->getResponse()->getBody(), true); + $this->provider->set($event->getRequest()->getId(), $body['etag']); + } + + public function setProvider(CacheProviderInterface $provider) + { + $this->provider = $provider; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Hydrator/Hydrator.php b/lib/Nekland/YoutubeApi/Transformer/Hydrator/Hydrator.php index afe018a..d4686d2 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Hydrator/Hydrator.php +++ b/lib/Nekland/YoutubeApi/Transformer/Hydrator/Hydrator.php @@ -16,11 +16,57 @@ class Hydrator implements HydratorInterface { /** * @param string $class - * @param array $data + * @param array $data + * @return \Nekland\YoutubeApi\Transformer\Model\Collection + */ + public function hydrateCollection($class, $data) + { + $collection = $this->hydrate('\Nekland\YoutubeApi\Transformer\Model\Collection', $data, ['items']); + + foreach ($data['items'] as $item) { + $collection->add($this->hydrate($class, $item)); + } + + return $collection; + } + + /** + * Hydrate a class + * Create sub classes and hydrate them if needed + * + * @param string $class + * @param mixed $data + * @param array $exclude * @return mixed */ - public function hydrate($class, $data) + public function hydrate($class, $data, array $exclude = []) { + if ($class === 'DateTime') { + return new \DateTime($data); + } + + $item = new $class(); + $reflection = new \ReflectionClass($item); + + foreach ($data as $dataKey => $dataItem) { + if (in_array($dataKey, $exclude)) { + continue; + } + + $setter = 'set' . ucfirst($dataKey); + + $method = $reflection->getMethod($setter); + $parameter = $method->getParameters(); + $parameter = $parameter[0]; + + if ($parameter->getClass() !== null) { + $subItemClass = $parameter->getClass(); + $item->$setter($this->hydrate($subItemClass->getName(), $dataItem)); + } else { + $item->$setter($dataItem); + } + } + return $item; } } diff --git a/lib/Nekland/YoutubeApi/Transformer/Hydrator/HydratorInterface.php b/lib/Nekland/YoutubeApi/Transformer/Hydrator/HydratorInterface.php index a0845b2..6992aa9 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Hydrator/HydratorInterface.php +++ b/lib/Nekland/YoutubeApi/Transformer/Hydrator/HydratorInterface.php @@ -15,9 +15,13 @@ interface HydratorInterface { /** + * Hydrate a class + * Create sub classes and hydrate them if needed + * * @param string $class - * @param array $data + * @param mixed $data + * @param array $exclude * @return mixed */ - public function hydrate($class, $data); + public function hydrate($class, $data, array $exclude = []); } diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Collection.php b/lib/Nekland/YoutubeApi/Transformer/Model/Collection.php index 66f0ef7..d0de958 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Collection.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Collection.php @@ -12,7 +12,227 @@ namespace Nekland\YoutubeApi\Transformer\Model; -class Collection +use Traversable; + +class Collection implements \IteratorAggregate, \ArrayAccess { - private $type; + /** + * @var string + */ + private $kind; + + /** + * @var string + */ + private $etag; + + /** + * @var string + */ + private $nextPageToken; + + /** + * @var string + */ + private $prevPageToken; + + /** + * @var PageInfo + */ + private $pageInfo; + + /** + * @var object[] + */ + private $items; + + /** + * @return string + */ + public function getEtag() + { + return $this->etag; + } + + /** + * @param string $etag + * @return self + */ + public function setEtag($etag) + { + $this->etag = $etag; + + return $this; + } + + /** + * @return object[] + */ + public function getItems() + { + return $this->items; + } + + /** + * @param object $item + */ + public function add($item) + { + $this->items[] = $item; + } + + /** + * @return string + */ + public function getKind() + { + return $this->kind; + } + + /** + * @param string $kind + * @return self + */ + public function setKind($kind) + { + $this->kind = $kind; + + return $this; + } + + /** + * @return string + */ + public function getNextPageToken() + { + return $this->nextPageToken; + } + + /** + * @param string $nextPageToken + * @return self + */ + public function setNextPageToken($nextPageToken) + { + $this->nextPageToken = $nextPageToken; + + return $this; + } + + /** + * @return PageInfo + */ + public function getPageInfo() + { + return $this->pageInfo; + } + + /** + * @param PageInfo $pageInfo + * @return self + */ + public function setPageInfo(PageInfo $pageInfo) + { + $this->pageInfo = $pageInfo; + + return $this; + } + + /** + * @return string + */ + public function getPrevPageToken() + { + return $this->prevPageToken; + } + + /** + * @param string $prevPageToken + * @return self + */ + public function setPrevPageToken($prevPageToken) + { + $this->prevPageToken = $prevPageToken; + + return $this; + } + + /** + * (PHP 5 >= 5.0.0)
+ * Retrieve an external iterator + * + * @link http://php.net/manual/en/iteratoraggregate.getiterator.php + * @return Traversable An instance of an object implementing Iterator or + * Traversable + */ + public function getIterator() + { + return new \ArrayIterator($this->items); + } + + /** + * (PHP 5 >= 5.0.0)
+ * Whether a offset exists + * + * @link http://php.net/manual/en/arrayaccess.offsetexists.php + * @param mixed $offset

+ * An offset to check for. + *

+ * @return boolean true on success or false on failure. + *

+ *

+ * The return value will be casted to boolean if non-boolean was returned. + */ + public function offsetExists($offset) + { + return isset($this->items[$offset]); + } + + /** + * (PHP 5 >= 5.0.0)
+ * Offset to retrieve + * + * @link http://php.net/manual/en/arrayaccess.offsetget.php + * @param mixed $offset

+ * The offset to retrieve. + *

+ * @return mixed Can return all value types. + */ + public function offsetGet($offset) + { + return $this->items[$offset]; + } + + /** + * (PHP 5 >= 5.0.0)
+ * Offset to set + * + * @link http://php.net/manual/en/arrayaccess.offsetset.php + * @param mixed $offset

+ * The offset to assign the value to. + *

+ * @param mixed $value

+ * The value to set. + *

+ * @return void + */ + public function offsetSet($offset, $value) + { + throw new \RuntimeException('You should not change items.'); + } + + /** + * (PHP 5 >= 5.0.0)
+ * Offset to unset + * + * @link http://php.net/manual/en/arrayaccess.offsetunset.php + * @param mixed $offset

+ * The offset to unset. + *

+ * @return void + */ + public function offsetUnset($offset) + { + unset($this->items[$offset]); + } } diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/FileDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/FileDetails.php new file mode 100644 index 0000000..ec414e8 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/FileDetails.php @@ -0,0 +1,62 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Details; + +class FileDetails +{ + /** + * @var string + */ + private $fileName; + + /** + * @var integer + */ + private $fileSize; + + /** + * @var string + */ + private $fileType; + + /** + * @var string + */ + private $container; + + /** + * @var array + */ + private $videoStreams; + + /** + * @var array + */ + private $audioStreams; + + /** + * @var integer + */ + private $durationMs; + + /** + * @var integer + */ + private $bitrateBps; + + /** + * @var \Nekland\YoutubeApi\Transformer\Model\Standard\Location + */ + private $recordingLocation; + + private $creationTime; +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/LiveStreamingDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/LiveStreamingDetails.php new file mode 100644 index 0000000..9155558 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/LiveStreamingDetails.php @@ -0,0 +1,40 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Details; + +class LiveStreamingDetails +{ + /** + * @var \DateTime + */ + private $actualStartTime; + + /** + * @var \DateTime + */ + private $actualEndTime; + + /** + * @var \DateTime + */ + private $scheduledStartTime; + + /** + * @var \DateTime + */ + private $scheduledEndTime; + + /** + * @var integer + */ + private $concurrentViewers; +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/ProcessingDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/ProcessingDetails.php new file mode 100644 index 0000000..276d355 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/ProcessingDetails.php @@ -0,0 +1,55 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Details; + +class ProcessingDetails +{ + /** + * @var string + */ + private $processingStatus; + + /** + * @var array + */ + private $processingProgress; + + /** + * @var string + */ + private $processingFailureReason; + + /** + * @var string + */ + private $fileDetailsAvailability; + + /** + * @var string + */ + private $processingIssuesAvailability; + + /** + * @var string + */ + private $tagSuggestionsAvailability; + + /** + * @var string + */ + private $editorSuggestionsAvailability; + + /** + * @var string + */ + private $thumbnailsAvailability; +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/RecordingDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/RecordingDetails.php new file mode 100644 index 0000000..57fe050 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/RecordingDetails.php @@ -0,0 +1,30 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Details; + +class RecordingDetails +{ + /** + * @var string + */ + private $locationDescription; + + /** + * @var \Nekland\YoutubeApi\Transformer\Model\Standard\Location + */ + private $location; + + /** + * @var \DateTime + */ + private $recordingDate; +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/Thumbnail.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/Thumbnail.php new file mode 100644 index 0000000..5443bf5 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/Thumbnail.php @@ -0,0 +1,30 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Details; + +class Thumbnail +{ + /** + * @var string + */ + private $url; + + /** + * @var integer + */ + private $width; + + /** + * @var integer + */ + private $height; +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/TopicDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/TopicDetails.php new file mode 100644 index 0000000..7b26946 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/TopicDetails.php @@ -0,0 +1,25 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Details; + +class TopicDetails +{ + /** + * @var string[] + */ + private $topicIds; + + /** + * @var string[] + */ + private $relevantTopicIds; +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/VideoDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/VideoDetails.php new file mode 100644 index 0000000..4223ba1 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/VideoDetails.php @@ -0,0 +1,50 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Details; + +class VideoDetails +{ + /** + * @var string + */ + private $duration; + + /** + * @var string + */ + private $dimension; + + /** + * @var string + */ + private $definition; + + /** + * @var string + */ + private $caption; + + /** + * @var boolean + */ + private $licensedContent; + + /** + * @var array[] + */ + private $regionRestriction; + + /** + * @var string[] + */ + private $contentRating; +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Item.php b/lib/Nekland/YoutubeApi/Transformer/Model/Item.php index 51578fb..ba7c1a3 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Item.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Item.php @@ -12,12 +12,74 @@ namespace Nekland\YoutubeApi\Transformer\Model; -class ItemInterface +abstract class Item implements ModelInterface { + /** + * @var string + */ + private $kind; + + /** + * @var string + */ private $etag; + /** + * @var string + */ + private $id; + + /** + * @return string + */ public function getEtag() { + return $this->etag; + } + + /** + * @param string $etag + * @return self + */ + public function setEtag($etag) + { + $this->etag = $etag; + return $this; + } + + /** + * @return string + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $id + * @return self + */ + public function setId($id) + { + $this->id = $id; + return $this; + } + /** + * @return string + */ + public function getKind() + { + return $this->kind; + } + + /** + * @param string $kind + * @return self + */ + public function setKind($kind) + { + $this->kind = $kind; + return $this; } } diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/ModelInterface.php b/lib/Nekland/YoutubeApi/Transformer/Model/ModelInterface.php new file mode 100644 index 0000000..0b76102 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/ModelInterface.php @@ -0,0 +1,20 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + +interface ModelInterface +{ + /** + * @return string + */ + public function getKind(); +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/PageInfo.php b/lib/Nekland/YoutubeApi/Transformer/Model/PageInfo.php new file mode 100644 index 0000000..11ce47c --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/PageInfo.php @@ -0,0 +1,64 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + + +class PageInfo +{ + /** + * @var integer + */ + private $totalResults; + + /** + * @var integer + */ + private $resultsPerPage; + + /** + * @return int + */ + public function getResultsPerPage() + { + return $this->resultsPerPage; + } + + /** + * @param int $resultsPerPage + * @return self + */ + public function setResultsPerPage($resultsPerPage) + { + $this->resultsPerPage = $resultsPerPage; + + return $this; + } + + /** + * @return int + */ + public function getTotalResults() + { + return $this->totalResults; + } + + /** + * @param int $totalResults + * @return self + */ + public function setTotalResults($totalResults) + { + $this->totalResults = $totalResults; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/VideoSnippet.php b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/VideoSnippet.php new file mode 100644 index 0000000..2dddda0 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/VideoSnippet.php @@ -0,0 +1,233 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Snippet; + +use Nekland\YoutubeApi\Transformer\Model\Details\Thumbnail; + +class VideoSnippet +{ + /** + * @var \DateTime + */ + private $publishedAt; + + /** + * @var string + */ + private $channelId; + + /** + * @var string + */ + private $title; + + /** + * @var string + */ + private $description; + + /** + * @var Thumbnail[] + */ + private $thumbnails; + + /** + * @var string + */ + private $channelTitle; + + /** + * @var string[] + */ + private $tags; + + /** + * @var string + */ + private $categoryId; + + /** + * @var string + */ + private $liveBroadcastContent; + + /** + * @return string + */ + public function getCategoryId() + { + return $this->categoryId; + } + + /** + * @param string $categoryId + * @return self + */ + public function setCategoryId($categoryId) + { + $this->categoryId = $categoryId; + + return $this; + } + + /** + * @return string + */ + public function getChannelId() + { + return $this->channelId; + } + + /** + * @param string $channelId + * @return self + */ + public function setChannelId($channelId) + { + $this->channelId = $channelId; + + return $this; + } + + /** + * @return string + */ + public function getChannelTitle() + { + return $this->channelTitle; + } + + /** + * @param string $channelTitle + * @return self + */ + public function setChannelTitle($channelTitle) + { + $this->channelTitle = $channelTitle; + + return $this; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param string $description + * @return self + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + /** + * @return string + */ + public function getLiveBroadcastContent() + { + return $this->liveBroadcastContent; + } + + /** + * @param string $liveBroadcastContent + * @return self + */ + public function setLiveBroadcastContent($liveBroadcastContent) + { + $this->liveBroadcastContent = $liveBroadcastContent; + + return $this; + } + + /** + * @return \DateTime + */ + public function getPublishedAt() + { + return $this->publishedAt; + } + + /** + * @param \DateTime $publishedAt + * @return self + */ + public function setPublishedAt(\DateTime $publishedAt) + { + $this->publishedAt = $publishedAt; + + return $this; + } + + /** + * @return \string[] + */ + public function getTags() + { + return $this->tags; + } + + /** + * @param \string[] $tags + * @return self + */ + public function setTags(array $tags) + { + $this->tags = $tags; + + return $this; + } + + /** + * @return \Nekland\YoutubeApi\Transformer\Model\Details\Thumbnail[] + */ + public function getThumbnails() + { + return $this->thumbnails; + } + + /** + * @param \Nekland\YoutubeApi\Transformer\Model\Details\Thumbnail[] $thumbnails + * @return self + */ + public function setThumbnails(array $thumbnails) + { + $this->thumbnails = $thumbnails; + + return $this; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + * @return self + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Standard/Location.php b/lib/Nekland/YoutubeApi/Transformer/Model/Standard/Location.php new file mode 100644 index 0000000..ed20997 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Standard/Location.php @@ -0,0 +1,30 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Standard; + +class Location +{ + /** + * @var double + */ + private $latitude; + + /** + * @var double + */ + private $longitude; + + /** + * @var double + */ + private $altitude; +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Statistics/VideoStatistics.php b/lib/Nekland/YoutubeApi/Transformer/Model/Statistics/VideoStatistics.php new file mode 100644 index 0000000..4c1b3d6 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Statistics/VideoStatistics.php @@ -0,0 +1,40 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Statistics; + +class VideoStatistics +{ + /** + * @var integer + */ + private $viewCount; + + /** + * @var integer + */ + private $likeCount; + + /** + * @var integer + */ + private $dislikeCount; + + /** + * @var integer + */ + private $favoriteCount; + + /** + * @var integer + */ + private $commentCount; +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Status/VideoStatus.php b/lib/Nekland/YoutubeApi/Transformer/Model/Status/VideoStatus.php new file mode 100644 index 0000000..3793d45 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Status/VideoStatus.php @@ -0,0 +1,55 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Status; + +class VideoStatus +{ + /** + * @var string + */ + private $uploadStatus; + + /** + * @var string + */ + private $failureReason; + + /** + * @var string + */ + private $rejectionReason; + + /** + * @var string + */ + private $privacyStatus; + + /** + * @var \DateTime + */ + private $publishedAt; + + /** + * @var string + */ + private $license; + + /** + * @var boolean + */ + private $embeddable; + + /** + * @var boolean + */ + private $publicStatsViewable; +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Suggestions/VideoSuggestions.php b/lib/Nekland/YoutubeApi/Transformer/Model/Suggestions/VideoSuggestions.php new file mode 100644 index 0000000..a2b8061 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Suggestions/VideoSuggestions.php @@ -0,0 +1,40 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Suggestions; + +class VideoSuggestions +{ + /** + * @var string[] + */ + private $processingErrors; + + /** + * @var string[] + */ + private $processingWarnings; + + /** + * @var string[] + */ + private $processingHints; + + /** + * @var array + */ + private $tagSuggestions; + + /** + * @var string + */ + private $editorSuggestions; +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Video.php b/lib/Nekland/YoutubeApi/Transformer/Model/Video.php index 806dc46..42f03dc 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Video.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Video.php @@ -12,7 +12,261 @@ namespace Nekland\YoutubeApi\Transformer\Model; -class Video +use Nekland\YoutubeApi\Transformer\Model\Snippet\VideoSnippet; + +class Video extends Item { + /** + * @var VideoSnippet + */ + private $snippet; + + /** + * @var Details\VideoDetails + */ + private $contentDetails; + + /** + * @var Status\VideoStatus + */ + private $status; + + /** + * @var Statistics\VideoStatistics + */ + private $statistics; + + /** + * @var array + */ + private $player; + + /** + * @var Details\TopicDetails + */ + private $topicDetails; + + /** + * @var Details\RecordingDetails + */ + private $recordingDetails; + + /** + * @var Details\FileDetails + */ + private $fileDetails; + + /** + * @var Details\ProcessingDetails + */ + private $processingDetails; + + /** + * @var Suggestions\VideoSuggestions + */ + private $suggestions; + + /** + * @var Details\LiveStreamingDetails + */ + private $liveStreamingDetails; + + /** + * @return Details\VideoDetails + */ + public function getContentDetails() + { + return $this->contentDetails; + } + + /** + * @param Details\VideoDetails $contentDetails + * @return self + */ + public function setContentDetails(Details\VideoDetails $contentDetails) + { + $this->contentDetails = $contentDetails; + return $this; + } + + /** + * @return Details\FileDetails + */ + public function getFileDetails() + { + return $this->fileDetails; + } + + /** + * @param Details\FileDetails $fileDetails + * @return self + */ + public function setFileDetails(Details\FileDetails $fileDetails) + { + $this->fileDetails = $fileDetails; + return $this; + } + + /** + * @return Details\LiveStreamingDetails + */ + public function getLiveStreamingDetails() + { + return $this->liveStreamingDetails; + } + + /** + * @param Details\LiveStreamingDetails $liveStreamingDetails + * @return self + */ + public function setLiveStreamingDetails($liveStreamingDetails) + { + $this->liveStreamingDetails = $liveStreamingDetails; + return $this; + } + + /** + * @return array + */ + public function getPlayer() + { + return $this->player; + } + + /** + * @param array $player + * @return self + */ + public function setPlayer($player) + { + $this->player = $player; + return $this; + } + + /** + * @return Details\ProcessingDetails + */ + public function getProcessingDetails() + { + return $this->processingDetails; + } + + /** + * @param Details\ProcessingDetails $processingDetails + * @return self + */ + public function setProcessingDetails(Details\ProcessingDetails $processingDetails) + { + $this->processingDetails = $processingDetails; + + return $this; + } + + /** + * @return Details\RecordingDetails + */ + public function getRecordingDetails() + { + return $this->recordingDetails; + } + + /** + * @param Details\RecordingDetails $recordingDetails + * @return self + */ + public function setRecordingDetails(Details\RecordingDetails $recordingDetails) + { + $this->recordingDetails = $recordingDetails; + return $this; + } + + /** + * @return VideoSnippet + */ + public function getSnippet() + { + return $this->snippet; + } + + /** + * @param VideoSnippet $snippet + * @return self + */ + public function setSnippet(VideoSnippet $snippet) + { + $this->snippet = $snippet; + return $this; + } + + /** + * @return Statistics\VideoStatistics + */ + public function getStatistics() + { + return $this->statistics; + } + + /** + * @param Statistics\VideoStatistics $statistics + * @return self + */ + public function setStatistics(Statistics\VideoStatistics $statistics) + { + $this->statistics = $statistics; + return $this; + } + + /** + * @return Status\VideoStatus + */ + public function getStatus() + { + return $this->status; + } + + /** + * @param Status\VideoStatus $status + * @return self + */ + public function setStatus(Status\VideoStatus $status) + { + $this->status = $status; + return $this; + } + + /** + * @return Suggestions\VideoSuggestions + */ + public function getSuggestions() + { + return $this->suggestions; + } + + /** + * @param Suggestions\VideoSuggestions $suggestions + * @return self + */ + public function setSuggestions(Suggestions\VideoSuggestions $suggestions) + { + $this->suggestions = $suggestions; + return $this; + } + + /** + * @return Details\TopicDetails + */ + public function getTopicDetails() + { + return $this->topicDetails; + } + /** + * @param Details\TopicDetails $topicDetails + * @return self + */ + public function setTopicDetails(Details\TopicDetails $topicDetails) + { + $this->topicDetails = $topicDetails; + return $this; + } } diff --git a/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php b/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php index 03c5134..9ef5bed 100644 --- a/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php +++ b/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php @@ -48,15 +48,11 @@ public function transform($data, $type = self::UNKNOWN) */ public function transformList($data, $type) { - $final = $this->hydrator->hydrate('\Nekland\YoutubeApi\Transformer\Model\Collection', $data); $type = $type === 'video' ? '\Nekland\YoutubeApi\Transformer\Model\Video' : '\Nekland\YoutubeApi\Transformer\Model\Playlist' ; - - foreach ($data['items'] as $item) { - $final->add($this->hydrator->hydrate($type, $item)); - } + $final = $this->hydrator->hydrateCollection($type, $data); return $final; } From 5de87944539b419735ff9dc711602e13075a2e67 Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sun, 12 Oct 2014 14:46:52 +0200 Subject: [PATCH 12/23] Added new models --- lib/Nekland/YoutubeApi/Api/Activities.php | 39 +++ .../Transformer/Hydrator/Hydrator.php | 30 +- .../YoutubeApi/Transformer/Model/Activity.php | 64 +++++ .../YoutubeApi/Transformer/Model/Channel.php | 42 +++ .../Model/Details/ActivityDetails.php | 256 ++++++++++++++++++ .../Model/Details/ChannelDetails.php | 64 +++++ .../Model/Details/PlaylistDetails.php | 40 +++ .../Transformer/Model/Details/Thumbnail.php | 57 ++++ .../YoutubeApi/Transformer/Model/Playlist.php | 112 ++++++++ .../Model/Snippet/ActivitySnippet.php | 88 ++++++ .../Model/Snippet/PlaylistSnippet.php | 88 ++++++ .../Transformer/Model/Snippet/Snippet.php | 120 ++++++++ .../Model/Snippet/VideoSnippet.php | 100 +------ .../Transformer/Model/Standard/Player.php | 40 +++ .../Model/Statistics/ChannelStatistics.php | 88 ++++++ .../Model/Statistics/Statistics.php | 65 +++++ .../Model/Statistics/VideoStatistics.php | 63 ++++- .../Transformer/Model/Status/SimpleStatus.php | 40 +++ .../Transformer/Model/Status/VideoStatus.php | 140 +++++++++- .../YoutubeApi/Transformer/Model/Video.php | 13 +- .../Transformer/ModelTransformer.php | 8 +- 21 files changed, 1432 insertions(+), 125 deletions(-) create mode 100644 lib/Nekland/YoutubeApi/Api/Activities.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Activity.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Channel.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Details/ActivityDetails.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Details/ChannelDetails.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Details/PlaylistDetails.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Playlist.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Snippet/ActivitySnippet.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Snippet/PlaylistSnippet.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Snippet/Snippet.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Standard/Player.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Statistics/ChannelStatistics.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Statistics/Statistics.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Status/SimpleStatus.php diff --git a/lib/Nekland/YoutubeApi/Api/Activities.php b/lib/Nekland/YoutubeApi/Api/Activities.php new file mode 100644 index 0000000..d16e042 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Api/Activities.php @@ -0,0 +1,39 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Api; + +use Nekland\BaseApi\Api\AbstractApi; +use Nekland\YoutubeApi\Api\Behavior\ListTrait; + +/** + * Class Activities + * + * Note about the "parts" array: it can take the following values: + * id, contentDetails, snippet. + * + * @see https://developers.google.com/youtube/v3/docs/activities/list for more information about paramaters + * @see https://developers.google.com/youtube/v3/docs/activities#resource for more information about json format + */ +class Activities extends AbstractApi +{ + use ListTrait; + + public function getUrl() + { + return 'youtube/v3/activities'; + } + + public function getType() + { + return 'playlist'; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Hydrator/Hydrator.php b/lib/Nekland/YoutubeApi/Transformer/Hydrator/Hydrator.php index d4686d2..4f37e77 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Hydrator/Hydrator.php +++ b/lib/Nekland/YoutubeApi/Transformer/Hydrator/Hydrator.php @@ -53,20 +53,40 @@ public function hydrate($class, $data, array $exclude = []) continue; } - $setter = 'set' . ucfirst($dataKey); - - $method = $reflection->getMethod($setter); + $method = $this->getMethod($reflection, $dataKey); $parameter = $method->getParameters(); $parameter = $parameter[0]; if ($parameter->getClass() !== null) { $subItemClass = $parameter->getClass(); - $item->$setter($this->hydrate($subItemClass->getName(), $dataItem)); + $method->invoke($item, [$this->hydrate($subItemClass->getName(), $dataItem)]); } else { - $item->$setter($dataItem); + $method->invoke($item, [$dataItem]); } } return $item; } + + /** + * @param \ReflectionClass $reflection + * @param string $dataKey + * @return \ReflectionMethod + */ + private function getMethod(\ReflectionClass $reflection, $dataKey) + { + $setter = 'set' . ucfirst($dataKey); + $method = $reflection->getMethod($setter); + $parameters = $method->getParameters(); + + if ($parameters[0]->isArray()) { + $adder = 'add' . ucfirst($dataKey); + + if ($reflection->hasMethod($adder)) { + $method = $reflection->getMethod($adder); + } + } + + return $method; + } } diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Activity.php b/lib/Nekland/YoutubeApi/Transformer/Model/Activity.php new file mode 100644 index 0000000..ab46c35 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Activity.php @@ -0,0 +1,64 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + + +class Activity extends Item +{ + /** + * @var Snippet\ActivitySnippet + */ + private $snippet; + + /** + * @var Details\ActivityDetails + */ + private $contentDetails; + + /** + * @return Details\ActivityDetails + */ + public function getContentDetails() + { + return $this->contentDetails; + } + + /** + * @param Details\ActivityDetails $contentDetails + * @return self + */ + public function setContentDetails(Details\ActivityDetails $contentDetails) + { + $this->contentDetails = $contentDetails; + + return $this; + } + + /** + * @return Snippet\ActivitySnippet + */ + public function getSnippet() + { + return $this->snippet; + } + + /** + * @param Snippet\ActivitySnippet $snippet + * @return self + */ + public function setSnippet(Snippet\ActivitySnippet $snippet) + { + $this->snippet = $snippet; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Channel.php b/lib/Nekland/YoutubeApi/Transformer/Model/Channel.php new file mode 100644 index 0000000..b8b3975 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Channel.php @@ -0,0 +1,42 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + + +class Channel extends Item +{ + /** + * @var Snippet\Snippet + */ + private $snippet; + + /** + * @var Details\ChannelDetails + */ + private $contentDetails; + + private $statistics; + + private $topicDetails; + + private $status; + + private $brandingSettings; + + private $position; + + private $items; + + private $auditDetails; + + private $contentOwnerDetails; +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/ActivityDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/ActivityDetails.php new file mode 100644 index 0000000..55dc6b0 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/ActivityDetails.php @@ -0,0 +1,256 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Details; + + +class ActivityDetails +{ + /** + * @var array + */ + private $upload; + + /** + * @var array + */ + private $like; + + /** + * @var array + */ + private $favorite; + + /** + * @var array + */ + private $comment; + + /** + * @var array + */ + private $subscription; + + /** + * @var array + */ + private $playlistItem; + + /** + * @var array + */ + private $recommendation; + + /** + * @var array + */ + private $bulletin; + + /** + * @var array + */ + private $social; + + /** + * @var array + */ + private $channelItem; + + /** + * @return array + */ + public function getBulletin() + { + return $this->bulletin; + } + + /** + * @param array $bulletin + * @return self + */ + public function setBulletin(array $bulletin) + { + $this->bulletin = $bulletin; + + return $this; + } + + /** + * @return array + */ + public function getChannelItem() + { + return $this->channelItem; + } + + /** + * @param array $channelItem + * @return self + */ + public function setChannelItem(array $channelItem) + { + $this->channelItem = $channelItem; + + return $this; + } + + /** + * @return array + */ + public function getComment() + { + return $this->comment; + } + + /** + * @param array $comment + * @return self + */ + public function setComment(array $comment) + { + $this->comment = $comment; + + return $this; + } + + /** + * @return array + */ + public function getFavorite() + { + return $this->favorite; + } + + /** + * @param array $favorite + * @return self + */ + public function setFavorite(array $favorite) + { + $this->favorite = $favorite; + + return $this; + } + + /** + * @return array + */ + public function getLike() + { + return $this->like; + } + + /** + * @param array $like + * @return self + */ + public function setLike(array $like) + { + $this->like = $like; + + return $this; + } + + /** + * @return array + */ + public function getPlaylistItem() + { + return $this->playlistItem; + } + + /** + * @param array $playlistItem + * @return self + */ + public function setPlaylistItem(array $playlistItem) + { + $this->playlistItem = $playlistItem; + + return $this; + } + + /** + * @return array + */ + public function getRecommendation() + { + return $this->recommendation; + } + + /** + * @param array $recommendation + * @return self + */ + public function setRecommendation(array $recommendation) + { + $this->recommendation = $recommendation; + + return $this; + } + + /** + * @return array + */ + public function getSocial() + { + return $this->social; + } + + /** + * @param array $social + * @return self + */ + public function setSocial(array $social) + { + $this->social = $social; + + return $this; + } + + /** + * @return array + */ + public function getSubscription() + { + return $this->subscription; + } + + /** + * @param array $subscription + * @return self + */ + public function setSubscription(array $subscription) + { + $this->subscription = $subscription; + + return $this; + } + + /** + * @return array + */ + public function getUpload() + { + return $this->upload; + } + + /** + * @param array $upload + * @return self + */ + public function setUpload(array $upload) + { + $this->upload = $upload; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/ChannelDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/ChannelDetails.php new file mode 100644 index 0000000..189cfef --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/ChannelDetails.php @@ -0,0 +1,64 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Details; + + +class ChannelDetails +{ + /** + * @var array + */ + private $relatedPlaylists; + + /** + * @var string + */ + private $googlePlusUserId; + + /** + * @return string + */ + public function getGooglePlusUserId() + { + return $this->googlePlusUserId; + } + + /** + * @param string $googlePlusUserId + * @return self + */ + public function setGooglePlusUserId($googlePlusUserId) + { + $this->googlePlusUserId = $googlePlusUserId; + + return $this; + } + + /** + * @return array + */ + public function getRelatedPlaylists() + { + return $this->relatedPlaylists; + } + + /** + * @param array $relatedPlaylists + * @return self + */ + public function setRelatedPlaylists(array $relatedPlaylists) + { + $this->relatedPlaylists = $relatedPlaylists; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/PlaylistDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/PlaylistDetails.php new file mode 100644 index 0000000..d18bbcd --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/PlaylistDetails.php @@ -0,0 +1,40 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Details; + + +class PlaylistDetails +{ + /** + * @var string + */ + private $itemCount; + + /** + * @return string + */ + public function getItemCount() + { + return $this->itemCount; + } + + /** + * @param string $itemCount + * @return self + */ + public function setItemCount($itemCount) + { + $this->itemCount = $itemCount; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/Thumbnail.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/Thumbnail.php index 5443bf5..7017b48 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Details/Thumbnail.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/Thumbnail.php @@ -27,4 +27,61 @@ class Thumbnail * @var integer */ private $height; + + /** + * @return int + */ + public function getHeight() + { + return $this->height; + } + + /** + * @param int $height + * @return self + */ + public function setHeight($height) + { + $this->height = $height; + + return $this; + } + + /** + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * @param string $url + * @return self + */ + public function setUrl($url) + { + $this->url = $url; + + return $this; + } + + /** + * @return int + */ + public function getWidth() + { + return $this->width; + } + + /** + * @param int $width + * @return self + */ + public function setWidth($width) + { + $this->width = $width; + + return $this; + } } diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Playlist.php b/lib/Nekland/YoutubeApi/Transformer/Model/Playlist.php new file mode 100644 index 0000000..e587714 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Playlist.php @@ -0,0 +1,112 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + + +class Playlist extends Item +{ + /** + * @var Snippet\PlaylistSnippet + */ + private $snippet; + + /** + * @var Status\SimpleStatus + */ + private $status; + + /** + * @var Details\PlaylistDetails + */ + private $contentDetails; + + /** + * @var Standard\Player + */ + private $player; + + /** + * @return Snippet\PlaylistSnippet + */ + public function getSnippet() + { + return $this->snippet; + } + + /** + * @param Snippet\PlaylistSnippet $snippet + * @return self + */ + public function setSnippet(Snippet\PlaylistSnippet $snippet) + { + $this->snippet = $snippet; + + return $this; + } + + /** + * @return Details\PlaylistDetails + */ + public function getContentDetails() + { + return $this->contentDetails; + } + + /** + * @param Details\PlaylistDetails $contentDetails + * @return self + */ + public function setContentDetails(Details\PlaylistDetails $contentDetails) + { + $this->contentDetails = $contentDetails; + + return $this; + } + + /** + * @return Standard\Player + */ + public function getPlayer() + { + return $this->player; + } + + /** + * @param Standard\Player $player + * @return self + */ + public function setPlayer(Standard\Player $player) + { + $this->player = $player; + + return $this; + } + + /** + * @return Status\SimpleStatus + */ + public function getStatus() + { + return $this->status; + } + + /** + * @param Status\SimpleStatus $status + * @return self + */ + public function setStatus(Status\SimpleStatus $status) + { + $this->status = $status; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/ActivitySnippet.php b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/ActivitySnippet.php new file mode 100644 index 0000000..454ef01 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/ActivitySnippet.php @@ -0,0 +1,88 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Snippet; + + +class ActivitySnippet extends Snippet +{ + /** + * @var string + */ + private $channelTitle; + + /** + * @var string + */ + private $type; + + /** + * @var string + */ + private $groupId; + + /** + * @return string + */ + public function getChannelTitle() + { + return $this->channelTitle; + } + + /** + * @param string $channelTitle + * @return self + */ + public function setChannelTitle($channelTitle) + { + $this->channelTitle = $channelTitle; + + return $this; + } + + /** + * @return string + */ + public function getGroupId() + { + return $this->groupId; + } + + /** + * @param string $groupId + * @return self + */ + public function setGroupId($groupId) + { + $this->groupId = $groupId; + + return $this; + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + * @return self + */ + public function setType($type) + { + $this->type = $type; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/PlaylistSnippet.php b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/PlaylistSnippet.php new file mode 100644 index 0000000..fe71bae --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/PlaylistSnippet.php @@ -0,0 +1,88 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Snippet; + + +class PlaylistSnippet extends Snippet +{ + /** + * @var string + */ + private $channelId; + + /** + * @var string + */ + private $channelTitle; + + /** + * @var string[] + */ + private $tags; + + /** + * @return string + */ + public function getChannelId() + { + return $this->channelId; + } + + /** + * @param string $channelId + * @return self + */ + public function setChannelId($channelId) + { + $this->channelId = $channelId; + + return $this; + } + + /** + * @return string + */ + public function getChannelTitle() + { + return $this->channelTitle; + } + + /** + * @param string $channelTitle + * @return self + */ + public function setChannelTitle($channelTitle) + { + $this->channelTitle = $channelTitle; + + return $this; + } + + /** + * @return \string[] + */ + public function getTags() + { + return $this->tags; + } + + /** + * @param \string[] $tags + * @return self + */ + public function setTags(array $tags) + { + $this->tags = $tags; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/Snippet.php b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/Snippet.php new file mode 100644 index 0000000..c6388d1 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/Snippet.php @@ -0,0 +1,120 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Snippet; + + +use Nekland\YoutubeApi\Transformer\Model\Details\Thumbnail; + +class Snippet +{ + /** + * @var \DateTime + */ + private $publishedAt; + + /** + * @var string + */ + private $title; + + /** + * @var Thumbnail[] + */ + private $thumbnails; + + /** + * @var string + */ + private $description; + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + * @return self + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * @return \Nekland\YoutubeApi\Transformer\Model\Details\Thumbnail[] + */ + public function getThumbnails() + { + return $this->thumbnails; + } + + /** + * @param \Nekland\YoutubeApi\Transformer\Model\Details\Thumbnail[] $thumbnails + * @return self + */ + public function setThumbnails(array $thumbnails) + { + $this->thumbnails = $thumbnails; + + return $this; + } + + public function addThumbnail(Thumbnail $thumbnail) + { + $this->thumbnails[] = $thumbnail; + } + + /** + * @return \DateTime + */ + public function getPublishedAt() + { + return $this->publishedAt; + } + + /** + * @param \DateTime $publishedAt + * @return self + */ + public function setPublishedAt(\DateTime $publishedAt) + { + $this->publishedAt = $publishedAt; + + return $this; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param string $description + * @return self + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/VideoSnippet.php b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/VideoSnippet.php index 2dddda0..1764cba 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/VideoSnippet.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/VideoSnippet.php @@ -11,35 +11,13 @@ namespace Nekland\YoutubeApi\Transformer\Model\Snippet; -use Nekland\YoutubeApi\Transformer\Model\Details\Thumbnail; - -class VideoSnippet +class VideoSnippet extends Snippet { - /** - * @var \DateTime - */ - private $publishedAt; - /** * @var string */ private $channelId; - /** - * @var string - */ - private $title; - - /** - * @var string - */ - private $description; - - /** - * @var Thumbnail[] - */ - private $thumbnails; - /** * @var string */ @@ -117,25 +95,6 @@ public function setChannelTitle($channelTitle) return $this; } - /** - * @return string - */ - public function getDescription() - { - return $this->description; - } - - /** - * @param string $description - * @return self - */ - public function setDescription($description) - { - $this->description = $description; - - return $this; - } - /** * @return string */ @@ -155,25 +114,6 @@ public function setLiveBroadcastContent($liveBroadcastContent) return $this; } - /** - * @return \DateTime - */ - public function getPublishedAt() - { - return $this->publishedAt; - } - - /** - * @param \DateTime $publishedAt - * @return self - */ - public function setPublishedAt(\DateTime $publishedAt) - { - $this->publishedAt = $publishedAt; - - return $this; - } - /** * @return \string[] */ @@ -192,42 +132,4 @@ public function setTags(array $tags) return $this; } - - /** - * @return \Nekland\YoutubeApi\Transformer\Model\Details\Thumbnail[] - */ - public function getThumbnails() - { - return $this->thumbnails; - } - - /** - * @param \Nekland\YoutubeApi\Transformer\Model\Details\Thumbnail[] $thumbnails - * @return self - */ - public function setThumbnails(array $thumbnails) - { - $this->thumbnails = $thumbnails; - - return $this; - } - - /** - * @return string - */ - public function getTitle() - { - return $this->title; - } - - /** - * @param string $title - * @return self - */ - public function setTitle($title) - { - $this->title = $title; - - return $this; - } } diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Standard/Player.php b/lib/Nekland/YoutubeApi/Transformer/Model/Standard/Player.php new file mode 100644 index 0000000..da1dfb9 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Standard/Player.php @@ -0,0 +1,40 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Standard; + + +class Player +{ + /** + * @var string + */ + private $embedHtml; + + /** + * @return string + */ + public function getEmbedHtml() + { + return $this->embedHtml; + } + + /** + * @param string $embedHtml + * @return self + */ + public function setEmbedHtml($embedHtml) + { + $this->embedHtml = $embedHtml; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Statistics/ChannelStatistics.php b/lib/Nekland/YoutubeApi/Transformer/Model/Statistics/ChannelStatistics.php new file mode 100644 index 0000000..b70f4b5 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Statistics/ChannelStatistics.php @@ -0,0 +1,88 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Statistics; + + +class ChannelStatistics extends Statistics +{ + /** + * @var int + */ + private $subscriberCount; + + /** + * @var bool + */ + private $hiddenSubscriberCount; + + /** + * @var int + */ + private $videoCount; + + /** + * @return boolean + */ + public function isHiddenSubscriberCount() + { + return $this->hiddenSubscriberCount; + } + + /** + * @param boolean $hiddenSubscriberCount + * @return self + */ + public function setHiddenSubscriberCount($hiddenSubscriberCount) + { + $this->hiddenSubscriberCount = $hiddenSubscriberCount; + + return $this; + } + + /** + * @return int + */ + public function getSubscriberCount() + { + return $this->subscriberCount; + } + + /** + * @param int $subscriberCount + * @return self + */ + public function setSubscriberCount($subscriberCount) + { + $this->subscriberCount = $subscriberCount; + + return $this; + } + + /** + * @return int + */ + public function getVideoCount() + { + return $this->videoCount; + } + + /** + * @param int $videoCount + * @return self + */ + public function setVideoCount($videoCount) + { + $this->videoCount = $videoCount; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Statistics/Statistics.php b/lib/Nekland/YoutubeApi/Transformer/Model/Statistics/Statistics.php new file mode 100644 index 0000000..914e70a --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Statistics/Statistics.php @@ -0,0 +1,65 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Statistics; + + +class Statistics +{ + /** + * @var integer + */ + private $viewCount; + + + /** + * @var integer + */ + private $commentCount; + + /** + * @return int + */ + public function getCommentCount() + { + return $this->commentCount; + } + + /** + * @param int $commentCount + * @return self + */ + public function setCommentCount($commentCount) + { + $this->commentCount = $commentCount; + + return $this; + } + + /** + * @return int + */ + public function getViewCount() + { + return $this->viewCount; + } + + /** + * @param int $viewCount + * @return self + */ + public function setViewCount($viewCount) + { + $this->viewCount = $viewCount; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Statistics/VideoStatistics.php b/lib/Nekland/YoutubeApi/Transformer/Model/Statistics/VideoStatistics.php index 4c1b3d6..fda6673 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Statistics/VideoStatistics.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Statistics/VideoStatistics.php @@ -11,13 +11,8 @@ namespace Nekland\YoutubeApi\Transformer\Model\Statistics; -class VideoStatistics +class VideoStatistics extends Statistics { - /** - * @var integer - */ - private $viewCount; - /** * @var integer */ @@ -34,7 +29,59 @@ class VideoStatistics private $favoriteCount; /** - * @var integer + * @return int + */ + public function getDislikeCount() + { + return $this->dislikeCount; + } + + /** + * @param int $dislikeCount + * @return self + */ + public function setDislikeCount($dislikeCount) + { + $this->dislikeCount = $dislikeCount; + + return $this; + } + + /** + * @return int */ - private $commentCount; + public function getFavoriteCount() + { + return $this->favoriteCount; + } + + /** + * @param int $favoriteCount + * @return self + */ + public function setFavoriteCount($favoriteCount) + { + $this->favoriteCount = $favoriteCount; + + return $this; + } + + /** + * @return int + */ + public function getLikeCount() + { + return $this->likeCount; + } + + /** + * @param int $likeCount + * @return self + */ + public function setLikeCount($likeCount) + { + $this->likeCount = $likeCount; + + return $this; + } } diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Status/SimpleStatus.php b/lib/Nekland/YoutubeApi/Transformer/Model/Status/SimpleStatus.php new file mode 100644 index 0000000..066b545 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Status/SimpleStatus.php @@ -0,0 +1,40 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Status; + + +class SimpleStatus +{ + /** + * @var string + */ + private $privacyStatus; + + /** + * @return string + */ + public function getPrivacyStatus() + { + return $this->privacyStatus; + } + + /** + * @param string $privacyStatus + * @return self + */ + public function setPrivacyStatus($privacyStatus) + { + $this->privacyStatus = $privacyStatus; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Status/VideoStatus.php b/lib/Nekland/YoutubeApi/Transformer/Model/Status/VideoStatus.php index 3793d45..694fb03 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Status/VideoStatus.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Status/VideoStatus.php @@ -11,7 +11,7 @@ namespace Nekland\YoutubeApi\Transformer\Model\Status; -class VideoStatus +class VideoStatus extends SimpleStatus { /** * @var string @@ -28,11 +28,6 @@ class VideoStatus */ private $rejectionReason; - /** - * @var string - */ - private $privacyStatus; - /** * @var \DateTime */ @@ -52,4 +47,137 @@ class VideoStatus * @var boolean */ private $publicStatsViewable; + + /** + * @return boolean + */ + public function isEmbeddable() + { + return $this->embeddable; + } + + /** + * @param boolean $embeddable + * @return self + */ + public function setEmbeddable($embeddable) + { + $this->embeddable = $embeddable; + + return $this; + } + + /** + * @return string + */ + public function getFailureReason() + { + return $this->failureReason; + } + + /** + * @param string $failureReason + * @return self + */ + public function setFailureReason($failureReason) + { + $this->failureReason = $failureReason; + + return $this; + } + + /** + * @return string + */ + public function getLicense() + { + return $this->license; + } + + /** + * @param string $license + * @return self + */ + public function setLicense($license) + { + $this->license = $license; + + return $this; + } + + /** + * @return boolean + */ + public function isPublicStatsViewable() + { + return $this->publicStatsViewable; + } + + /** + * @param boolean $publicStatsViewable + * @return self + */ + public function setPublicStatsViewable($publicStatsViewable) + { + $this->publicStatsViewable = $publicStatsViewable; + + return $this; + } + + /** + * @return \DateTime + */ + public function getPublishedAt() + { + return $this->publishedAt; + } + + /** + * @param \DateTime $publishedAt + * @return self + */ + public function setPublishedAt(\DateTime $publishedAt) + { + $this->publishedAt = $publishedAt; + + return $this; + } + + /** + * @return string + */ + public function getRejectionReason() + { + return $this->rejectionReason; + } + + /** + * @param string $rejectionReason + * @return self + */ + public function setRejectionReason($rejectionReason) + { + $this->rejectionReason = $rejectionReason; + + return $this; + } + + /** + * @return string + */ + public function getUploadStatus() + { + return $this->uploadStatus; + } + + /** + * @param string $uploadStatus + * @return self + */ + public function setUploadStatus($uploadStatus) + { + $this->uploadStatus = $uploadStatus; + + return $this; + } } diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Video.php b/lib/Nekland/YoutubeApi/Transformer/Model/Video.php index 42f03dc..53f2ed9 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Video.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Video.php @@ -37,7 +37,7 @@ class Video extends Item private $statistics; /** - * @var array + * @var Standard\Player */ private $player; @@ -86,6 +86,7 @@ public function getContentDetails() public function setContentDetails(Details\VideoDetails $contentDetails) { $this->contentDetails = $contentDetails; + return $this; } @@ -104,6 +105,7 @@ public function getFileDetails() public function setFileDetails(Details\FileDetails $fileDetails) { $this->fileDetails = $fileDetails; + return $this; } @@ -122,6 +124,7 @@ public function getLiveStreamingDetails() public function setLiveStreamingDetails($liveStreamingDetails) { $this->liveStreamingDetails = $liveStreamingDetails; + return $this; } @@ -137,9 +140,10 @@ public function getPlayer() * @param array $player * @return self */ - public function setPlayer($player) + public function setPlayer(Standard\Player$player) { $this->player = $player; + return $this; } @@ -195,6 +199,7 @@ public function getSnippet() public function setSnippet(VideoSnippet $snippet) { $this->snippet = $snippet; + return $this; } @@ -213,6 +218,7 @@ public function getStatistics() public function setStatistics(Statistics\VideoStatistics $statistics) { $this->statistics = $statistics; + return $this; } @@ -231,6 +237,7 @@ public function getStatus() public function setStatus(Status\VideoStatus $status) { $this->status = $status; + return $this; } @@ -249,6 +256,7 @@ public function getSuggestions() public function setSuggestions(Suggestions\VideoSuggestions $suggestions) { $this->suggestions = $suggestions; + return $this; } @@ -267,6 +275,7 @@ public function getTopicDetails() public function setTopicDetails(Details\TopicDetails $topicDetails) { $this->topicDetails = $topicDetails; + return $this; } } diff --git a/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php b/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php index 9ef5bed..ed98982 100644 --- a/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php +++ b/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php @@ -36,7 +36,9 @@ public function transform($data, $type = self::UNKNOWN) switch ($data['kind']) { case 'youtube#videoListResponse': - return $this->transformList($data, 'video'); + return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\Video'); + case 'youtube#playlistListResponse': + return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\Playlist'); } } } @@ -48,10 +50,6 @@ public function transform($data, $type = self::UNKNOWN) */ public function transformList($data, $type) { - $type = $type === 'video' ? - '\Nekland\YoutubeApi\Transformer\Model\Video' : - '\Nekland\YoutubeApi\Transformer\Model\Playlist' - ; $final = $this->hydrator->hydrateCollection($type, $data); return $final; From 3d9a751d36cdee42a912136f88065d33401bdd82 Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sun, 12 Oct 2014 17:09:28 +0200 Subject: [PATCH 13/23] Fixed bug on hydrator and added channel model --- .../Transformer/Hydrator/Hydrator.php | 15 +- .../BrandingSettings/BrandingSettings.php | 88 +++ .../Model/BrandingSettings/Channel.php | 304 ++++++++++ .../Model/BrandingSettings/Image.php | 546 ++++++++++++++++++ .../Model/BrandingSettings/Watch.php | 88 +++ .../YoutubeApi/Transformer/Model/Channel.php | 196 ++++++- .../Model/Details/AuditDetails.php | 112 ++++ .../Model/Details/ContentOwnerDetails.php | 64 ++ .../Model/Details/TopicDetails.php | 38 ++ .../InvideoPromotion/InvideoPromotion.php | 128 ++++ .../Model/InvideoPromotion/Item.php | 112 ++++ .../Model/InvideoPromotion/Timing.php | 88 +++ .../Transformer/Model/Standard/Url.php | 86 +++ .../Model/Status/ChannelStatus.php | 64 ++ 14 files changed, 1925 insertions(+), 4 deletions(-) create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/BrandingSettings/BrandingSettings.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/BrandingSettings/Channel.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/BrandingSettings/Image.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/BrandingSettings/Watch.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Details/AuditDetails.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Details/ContentOwnerDetails.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/InvideoPromotion.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/Item.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/Timing.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Standard/Url.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Status/ChannelStatus.php diff --git a/lib/Nekland/YoutubeApi/Transformer/Hydrator/Hydrator.php b/lib/Nekland/YoutubeApi/Transformer/Hydrator/Hydrator.php index 4f37e77..fb92572 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Hydrator/Hydrator.php +++ b/lib/Nekland/YoutubeApi/Transformer/Hydrator/Hydrator.php @@ -80,7 +80,7 @@ private function getMethod(\ReflectionClass $reflection, $dataKey) $parameters = $method->getParameters(); if ($parameters[0]->isArray()) { - $adder = 'add' . ucfirst($dataKey); + $adder = 'add' . ucfirst($this->removeLastS($dataKey)); if ($reflection->hasMethod($adder)) { $method = $reflection->getMethod($adder); @@ -89,4 +89,17 @@ private function getMethod(\ReflectionClass $reflection, $dataKey) return $method; } + + /** + * @param string $str + * @return string + */ + private function removeLastS($str) + { + if (substr($str, -1) === 's') { + return substr($str, 0, strlen($str)-1); + } + + return $str; + } } diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/BrandingSettings/BrandingSettings.php b/lib/Nekland/YoutubeApi/Transformer/Model/BrandingSettings/BrandingSettings.php new file mode 100644 index 0000000..9fbb37b --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/BrandingSettings/BrandingSettings.php @@ -0,0 +1,88 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\BrandingSettings; + + +class BrandingSettings +{ + /** + * @var Channel + */ + private $channel; + + /** + * @var Image + */ + private $image; + + /** + * @var array + */ + private $hints; + + /** + * @return Channel + */ + public function getChannel() + { + return $this->channel; + } + + /** + * @param Channel $channel + * @return self + */ + public function setChannel($channel) + { + $this->channel = $channel; + + return $this; + } + + /** + * @return array + */ + public function getHints() + { + return $this->hints; + } + + /** + * @param array $hints + * @return self + */ + public function setHints(array $hints) + { + $this->hints = $hints; + + return $this; + } + + /** + * @return Image + */ + public function getImage() + { + return $this->image; + } + + /** + * @param Image $image + * @return self + */ + public function setImage($image) + { + $this->image = $image; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/BrandingSettings/Channel.php b/lib/Nekland/YoutubeApi/Transformer/Model/BrandingSettings/Channel.php new file mode 100644 index 0000000..dcc56f7 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/BrandingSettings/Channel.php @@ -0,0 +1,304 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\BrandingSettings; + + +class Channel +{ + /** + * @var string + */ + private $title; + + /** + * @var string + */ + private $description; + + /** + * @var string + */ + private $keyword; + + /** + * @var string + */ + private $defaultTab; + + /** + * @var string + */ + private $trackingAnalyticsAccountId; + + /** + * @var bool + */ + private $moderateComments; + + /** + * @var bool + */ + private $showRelatedChannels; + + /** + * @var bool + */ + private $showBrowseView; + + /** + * @var string + */ + private $featuredChannelsTitle; + + /** + * @var array + */ + private $featuredChannelsUrls; + + /** + * @var string + */ + private $unsubscribedTrailer; + + /** + * @var string + */ + private $profileColor; + + /** + * @return string + */ + public function getDefaultTab() + { + return $this->defaultTab; + } + + /** + * @param string $defaultTab + * @return self + */ + public function setDefaultTab($defaultTab) + { + $this->defaultTab = $defaultTab; + + return $this; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param string $description + * @return self + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + /** + * @return string + */ + public function getFeaturedChannelsTitle() + { + return $this->featuredChannelsTitle; + } + + /** + * @param string $featuredChannelsTitle + * @return self + */ + public function setFeaturedChannelsTitle($featuredChannelsTitle) + { + $this->featuredChannelsTitle = $featuredChannelsTitle; + + return $this; + } + + /** + * @return array + */ + public function getFeaturedChannelsUrls() + { + return $this->featuredChannelsUrls; + } + + /** + * @param array $featuredChannelsUrls + * @return self + */ + public function setFeaturedChannelsUrls(array $featuredChannelsUrls) + { + $this->featuredChannelsUrls = $featuredChannelsUrls; + + return $this; + } + + /** + * @return string + */ + public function getKeyword() + { + return $this->keyword; + } + + /** + * @param string $keyword + * @return self + */ + public function setKeyword($keyword) + { + $this->keyword = $keyword; + + return $this; + } + + /** + * @return boolean + */ + public function isModerateComments() + { + return $this->moderateComments; + } + + /** + * @param boolean $moderateComments + * @return self + */ + public function setModerateComments($moderateComments) + { + $this->moderateComments = $moderateComments; + + return $this; + } + + /** + * @return string + */ + public function getProfileColor() + { + return $this->profileColor; + } + + /** + * @param string $profileColor + * @return self + */ + public function setProfileColor($profileColor) + { + $this->profileColor = $profileColor; + + return $this; + } + + /** + * @return boolean + */ + public function isShowBrowseView() + { + return $this->showBrowseView; + } + + /** + * @param boolean $showBrowseView + * @return self + */ + public function setShowBrowseView($showBrowseView) + { + $this->showBrowseView = $showBrowseView; + + return $this; + } + + /** + * @return boolean + */ + public function isShowRelatedChannels() + { + return $this->showRelatedChannels; + } + + /** + * @param boolean $showRelatedChannels + * @return self + */ + public function setShowRelatedChannels($showRelatedChannels) + { + $this->showRelatedChannels = $showRelatedChannels; + + return $this; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + * @return self + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * @return string + */ + public function getTrackingAnalyticsAccountId() + { + return $this->trackingAnalyticsAccountId; + } + + /** + * @param string $trackingAnalyticsAccountId + * @return self + */ + public function setTrackingAnalyticsAccountId($trackingAnalyticsAccountId) + { + $this->trackingAnalyticsAccountId = $trackingAnalyticsAccountId; + + return $this; + } + + /** + * @return string + */ + public function getUnsubscribedTrailer() + { + return $this->unsubscribedTrailer; + } + + /** + * @param string $unsubscribedTrailer + * @return self + */ + public function setUnsubscribedTrailer($unsubscribedTrailer) + { + $this->unsubscribedTrailer = $unsubscribedTrailer; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/BrandingSettings/Image.php b/lib/Nekland/YoutubeApi/Transformer/Model/BrandingSettings/Image.php new file mode 100644 index 0000000..86a3769 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/BrandingSettings/Image.php @@ -0,0 +1,546 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\BrandingSettings; + + +use Nekland\YoutubeApi\Transformer\Model\Standard\Url; + +class Image +{ + /** + * @var string + */ + private $bannerImageUrl; + + /** + * @var string + */ + private $bannerMobileImageUrl; + + /** + * @var Url + */ + private $backgroundImageUrl; + + /** + * @var Url + */ + private $largeBrandedBannerImageImapScript; + + /** + * @var Url + */ + private $largeBrandedBannerImageUrl; + + /** + * @var Url + */ + private $smallBrandedBannerImageImapScript; + + /** + * @var Url + */ + private $smallBrandedBannerImageUrl; + + /** + * @var string + */ + private $watchIconImageUrl; + + /** + * @var string + */ + private $trackingImageUrl; + + /** + * @var string + */ + private $bannerTabletLowImageUrl; + + /** + * @var string + */ + private $bannerTabletImageUrl; + + /** + * @var string + */ + private $bannerTabletHdImageUrl; + + /** + * @var string + */ + private $bannerTabletExtraHdImageUrl; + + /** + * @var string + */ + private $bannerMobileLowImageUrl; + + /** + * @var string + */ + private $bannerMobileMediumHdImageUrl; + + /** + * @var string + */ + private $bannerMobileHdImageUrl; + + /** + * @var string + */ + private $bannerMobileExtraHdImageUrl; + + /** + * @var string + */ + private $bannerTvImageUrl; + + /** + * @var string + */ + private $bannerTvLowImageUrl; + + /** + * @var string + */ + private $bannerTvMediumImageUrl; + + /** + * @var string + */ + private $bannerTvHighImageUrl; + + /** + * @var string + */ + private $bannerExternalUrl; + + /** + * @return Url + */ + public function getBackgroundImageUrl() + { + return $this->backgroundImageUrl; + } + + /** + * @param Url $backgroundImageUrl + * @return self + */ + public function setBackgroundImageUrl(Url $backgroundImageUrl) + { + $this->backgroundImageUrl = $backgroundImageUrl; + + return $this; + } + + /** + * @return string + */ + public function getBannerExternalUrl() + { + return $this->bannerExternalUrl; + } + + /** + * @param string $bannerExternalUrl + * @return self + */ + public function setBannerExternalUrl($bannerExternalUrl) + { + $this->bannerExternalUrl = $bannerExternalUrl; + + return $this; + } + + /** + * @return string + */ + public function getBannerImageUrl() + { + return $this->bannerImageUrl; + } + + /** + * @param string $bannerImageUrl + * @return self + */ + public function setBannerImageUrl($bannerImageUrl) + { + $this->bannerImageUrl = $bannerImageUrl; + + return $this; + } + + /** + * @return string + */ + public function getBannerMobileExtraHdImageUrl() + { + return $this->bannerMobileExtraHdImageUrl; + } + + /** + * @param string $bannerMobileExtraHdImageUrl + * @return self + */ + public function setBannerMobileExtraHdImageUrl($bannerMobileExtraHdImageUrl) + { + $this->bannerMobileExtraHdImageUrl = $bannerMobileExtraHdImageUrl; + + return $this; + } + + /** + * @return string + */ + public function getBannerMobileHdImageUrl() + { + return $this->bannerMobileHdImageUrl; + } + + /** + * @param string $bannerMobileHdImageUrl + * @return self + */ + public function setBannerMobileHdImageUrl($bannerMobileHdImageUrl) + { + $this->bannerMobileHdImageUrl = $bannerMobileHdImageUrl; + + return $this; + } + + /** + * @return string + */ + public function getBannerMobileImageUrl() + { + return $this->bannerMobileImageUrl; + } + + /** + * @param string $bannerMobileImageUrl + * @return self + */ + public function setBannerMobileImageUrl($bannerMobileImageUrl) + { + $this->bannerMobileImageUrl = $bannerMobileImageUrl; + + return $this; + } + + /** + * @return string + */ + public function getBannerMobileLowImageUrl() + { + return $this->bannerMobileLowImageUrl; + } + + /** + * @param string $bannerMobileLowImageUrl + * @return self + */ + public function setBannerMobileLowImageUrl($bannerMobileLowImageUrl) + { + $this->bannerMobileLowImageUrl = $bannerMobileLowImageUrl; + + return $this; + } + + /** + * @return string + */ + public function getBannerMobileMediumHdImageUrl() + { + return $this->bannerMobileMediumHdImageUrl; + } + + /** + * @param string $bannerMobileMediumHdImageUrl + * @return self + */ + public function setBannerMobileMediumHdImageUrl($bannerMobileMediumHdImageUrl) + { + $this->bannerMobileMediumHdImageUrl = $bannerMobileMediumHdImageUrl; + + return $this; + } + + /** + * @return string + */ + public function getBannerTabletExtraHdImageUrl() + { + return $this->bannerTabletExtraHdImageUrl; + } + + /** + * @param string $bannerTabletExtraHdImageUrl + * @return self + */ + public function setBannerTabletExtraHdImageUrl($bannerTabletExtraHdImageUrl) + { + $this->bannerTabletExtraHdImageUrl = $bannerTabletExtraHdImageUrl; + + return $this; + } + + /** + * @return string + */ + public function getBannerTabletHdImageUrl() + { + return $this->bannerTabletHdImageUrl; + } + + /** + * @param string $bannerTabletHdImageUrl + * @return self + */ + public function setBannerTabletHdImageUrl($bannerTabletHdImageUrl) + { + $this->bannerTabletHdImageUrl = $bannerTabletHdImageUrl; + + return $this; + } + + /** + * @return string + */ + public function getBannerTabletImageUrl() + { + return $this->bannerTabletImageUrl; + } + + /** + * @param string $bannerTabletImageUrl + * @return self + */ + public function setBannerTabletImageUrl($bannerTabletImageUrl) + { + $this->bannerTabletImageUrl = $bannerTabletImageUrl; + + return $this; + } + + /** + * @return string + */ + public function getBannerTabletLowImageUrl() + { + return $this->bannerTabletLowImageUrl; + } + + /** + * @param string $bannerTabletLowImageUrl + * @return self + */ + public function setBannerTabletLowImageUrl($bannerTabletLowImageUrl) + { + $this->bannerTabletLowImageUrl = $bannerTabletLowImageUrl; + + return $this; + } + + /** + * @return string + */ + public function getBannerTvHighImageUrl() + { + return $this->bannerTvHighImageUrl; + } + + /** + * @param string $bannerTvHighImageUrl + * @return self + */ + public function setBannerTvHighImageUrl($bannerTvHighImageUrl) + { + $this->bannerTvHighImageUrl = $bannerTvHighImageUrl; + + return $this; + } + + /** + * @return string + */ + public function getBannerTvImageUrl() + { + return $this->bannerTvImageUrl; + } + + /** + * @param string $bannerTvImageUrl + * @return self + */ + public function setBannerTvImageUrl($bannerTvImageUrl) + { + $this->bannerTvImageUrl = $bannerTvImageUrl; + + return $this; + } + + /** + * @return string + */ + public function getBannerTvLowImageUrl() + { + return $this->bannerTvLowImageUrl; + } + + /** + * @param string $bannerTvLowImageUrl + * @return self + */ + public function setBannerTvLowImageUrl($bannerTvLowImageUrl) + { + $this->bannerTvLowImageUrl = $bannerTvLowImageUrl; + + return $this; + } + + /** + * @return string + */ + public function getBannerTvMediumImageUrl() + { + return $this->bannerTvMediumImageUrl; + } + + /** + * @param string $bannerTvMediumImageUrl + * @return self + */ + public function setBannerTvMediumImageUrl($bannerTvMediumImageUrl) + { + $this->bannerTvMediumImageUrl = $bannerTvMediumImageUrl; + + return $this; + } + + /** + * @return Url + */ + public function getLargeBrandedBannerImageImapScript() + { + return $this->largeBrandedBannerImageImapScript; + } + + /** + * @param Url $largeBrandedBannerImageImapScript + * @return self + */ + public function setLargeBrandedBannerImageImapScript(Url $largeBrandedBannerImageImapScript) + { + $this->largeBrandedBannerImageImapScript = $largeBrandedBannerImageImapScript; + + return $this; + } + + /** + * @return Url + */ + public function getLargeBrandedBannerImageUrl() + { + return $this->largeBrandedBannerImageUrl; + } + + /** + * @param Url $largeBrandedBannerImageUrl + * @return self + */ + public function setLargeBrandedBannerImageUrl(Url $largeBrandedBannerImageUrl) + { + $this->largeBrandedBannerImageUrl = $largeBrandedBannerImageUrl; + + return $this; + } + + /** + * @return Url + */ + public function getSmallBrandedBannerImageImapScript() + { + return $this->smallBrandedBannerImageImapScript; + } + + /** + * @param Url $smallBrandedBannerImageImapScript + * @return self + */ + public function setSmallBrandedBannerImageImapScript(Url $smallBrandedBannerImageImapScript) + { + $this->smallBrandedBannerImageImapScript = $smallBrandedBannerImageImapScript; + + return $this; + } + + /** + * @return Url + */ + public function getSmallBrandedBannerImageUrl() + { + return $this->smallBrandedBannerImageUrl; + } + + /** + * @param Url $smallBrandedBannerImageUrl + * @return self + */ + public function setSmallBrandedBannerImageUrl(Url $smallBrandedBannerImageUrl) + { + $this->smallBrandedBannerImageUrl = $smallBrandedBannerImageUrl; + + return $this; + } + + /** + * @return string + */ + public function getTrackingImageUrl() + { + return $this->trackingImageUrl; + } + + /** + * @param string $trackingImageUrl + * @return self + */ + public function setTrackingImageUrl($trackingImageUrl) + { + $this->trackingImageUrl = $trackingImageUrl; + + return $this; + } + + /** + * @return string + */ + public function getWatchIconImageUrl() + { + return $this->watchIconImageUrl; + } + + /** + * @param string $watchIconImageUrl + * @return self + */ + public function setWatchIconImageUrl($watchIconImageUrl) + { + $this->watchIconImageUrl = $watchIconImageUrl; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/BrandingSettings/Watch.php b/lib/Nekland/YoutubeApi/Transformer/Model/BrandingSettings/Watch.php new file mode 100644 index 0000000..f21fb0b --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/BrandingSettings/Watch.php @@ -0,0 +1,88 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\BrandingSettings; + + +class Watch +{ + /** + * @var string + */ + private $textColor; + + /** + * @var string + */ + private $backgroundColor; + + /** + * @var string + */ + private $featuredPlaylistId; + + /** + * @return string + */ + public function getBackgroundColor() + { + return $this->backgroundColor; + } + + /** + * @param string $backgroundColor + * @return self + */ + public function setBackgroundColor($backgroundColor) + { + $this->backgroundColor = $backgroundColor; + + return $this; + } + + /** + * @return string + */ + public function getFeaturedPlaylistId() + { + return $this->featuredPlaylistId; + } + + /** + * @param string $featuredPlaylistId + * @return self + */ + public function setFeaturedPlaylistId($featuredPlaylistId) + { + $this->featuredPlaylistId = $featuredPlaylistId; + + return $this; + } + + /** + * @return string + */ + public function getTextColor() + { + return $this->textColor; + } + + /** + * @param string $textColor + * @return self + */ + public function setTextColor($textColor) + { + $this->textColor = $textColor; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Channel.php b/lib/Nekland/YoutubeApi/Transformer/Model/Channel.php index b8b3975..7778d1f 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Channel.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Channel.php @@ -24,19 +24,209 @@ class Channel extends Item */ private $contentDetails; + /** + * @var Statistics\ChannelStatistics + */ private $statistics; + /** + * @var Details\TopicDetails + */ private $topicDetails; + /** + * @var Status\ChannelStatus + */ private $status; + /** + * @var BrandingSettings\BrandingSettings + */ private $brandingSettings; - private $position; - - private $items; + /** + * @var InvideoPromotion\InvideoPromotion + */ + private $invideoPromotion; + /** + * @var Details\AuditDetails + */ private $auditDetails; + /** + * @var Details\ContentOwnerDetails + */ private $contentOwnerDetails; + + /** + * @return Details\AuditDetails + */ + public function getAuditDetails() + { + return $this->auditDetails; + } + + /** + * @param Details\AuditDetails $auditDetails + * @return self + */ + public function setAuditDetails(Details\AuditDetails $auditDetails) + { + $this->auditDetails = $auditDetails; + + return $this; + } + + /** + * @return BrandingSettings\BrandingSettings + */ + public function getBrandingSettings() + { + return $this->brandingSettings; + } + + /** + * @param BrandingSettings\BrandingSettings $brandingSettings + * @return self + */ + public function setBrandingSettings(BrandingSettings\BrandingSettings $brandingSettings) + { + $this->brandingSettings = $brandingSettings; + + return $this; + } + + /** + * @return Details\ChannelDetails + */ + public function getContentDetails() + { + return $this->contentDetails; + } + + /** + * @param Details\ChannelDetails $contentDetails + * @return self + */ + public function setContentDetails(Details\ChannelDetails $contentDetails) + { + $this->contentDetails = $contentDetails; + + return $this; + } + + /** + * @return Details\ContentOwnerDetails + */ + public function getContentOwnerDetails() + { + return $this->contentOwnerDetails; + } + + /** + * @param Details\ContentOwnerDetails $contentOwnerDetails + * @return self + */ + public function setContentOwnerDetails(Details\ContentOwnerDetails $contentOwnerDetails) + { + $this->contentOwnerDetails = $contentOwnerDetails; + + return $this; + } + + /** + * @return InvideoPromotion\InvideoPromotion + */ + public function getInvideoPromotion() + { + return $this->invideoPromotion; + } + + /** + * @param InvideoPromotion\InvideoPromotion $invideoPromotion + * @return self + */ + public function setInvideoPromotion(InvideoPromotion\InvideoPromotion $invideoPromotion) + { + $this->invideoPromotion = $invideoPromotion; + + return $this; + } + + /** + * @return Snippet\Snippet + */ + public function getSnippet() + { + return $this->snippet; + } + + /** + * @param Snippet\Snippet $snippet + * @return self + */ + public function setSnippet(Snippet\Snippet $snippet) + { + $this->snippet = $snippet; + + return $this; + } + + /** + * @return Statistics\ChannelStatistics + */ + public function getStatistics() + { + return $this->statistics; + } + + /** + * @param Statistics\ChannelStatistics $statistics + * @return self + */ + public function setStatistics(Statistics\ChannelStatistics $statistics) + { + $this->statistics = $statistics; + + return $this; + } + + /** + * @return Status\ChannelStatus + */ + public function getStatus() + { + return $this->status; + } + + /** + * @param Status\ChannelStatus $status + * @return self + */ + public function setStatus(Status\ChannelStatus $status) + { + $this->status = $status; + + return $this; + } + + /** + * @return Details\TopicDetails + */ + public function getTopicDetails() + { + return $this->topicDetails; + } + + /** + * @param Details\TopicDetails $topicDetails + * @return self + */ + public function setTopicDetails(Details\TopicDetails $topicDetails) + { + $this->topicDetails = $topicDetails; + + return $this; + } } diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/AuditDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/AuditDetails.php new file mode 100644 index 0000000..56970bc --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/AuditDetails.php @@ -0,0 +1,112 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Details; + + +class AuditDetails +{ + /** + * @var bool + */ + private $overallGoodStanding; + + /** + * @var bool + */ + private $communityGuidelinesGoodStanding; + + /** + * @var bool + */ + private $copyrightStrikesGoodStanding; + + /** + * @var bool + */ + private $contentIdClaimsGoodStanding; + + /** + * @return boolean + */ + public function isCommunityGuidelinesGoodStanding() + { + return $this->communityGuidelinesGoodStanding; + } + + /** + * @param boolean $communityGuidelinesGoodStanding + * @return self + */ + public function setCommunityGuidelinesGoodStanding($communityGuidelinesGoodStanding) + { + $this->communityGuidelinesGoodStanding = $communityGuidelinesGoodStanding; + + return $this; + } + + /** + * @return boolean + */ + public function isContentIdClaimsGoodStanding() + { + return $this->contentIdClaimsGoodStanding; + } + + /** + * @param boolean $contentIdClaimsGoodStanding + * @return self + */ + public function setContentIdClaimsGoodStanding($contentIdClaimsGoodStanding) + { + $this->contentIdClaimsGoodStanding = $contentIdClaimsGoodStanding; + + return $this; + } + + /** + * @return boolean + */ + public function isCopyrightStrikesGoodStanding() + { + return $this->copyrightStrikesGoodStanding; + } + + /** + * @param boolean $copyrightStrikesGoodStanding + * @return self + */ + public function setCopyrightStrikesGoodStanding($copyrightStrikesGoodStanding) + { + $this->copyrightStrikesGoodStanding = $copyrightStrikesGoodStanding; + + return $this; + } + + /** + * @return boolean + */ + public function isOverallGoodStanding() + { + return $this->overallGoodStanding; + } + + /** + * @param boolean $overallGoodStanding + * @return self + */ + public function setOverallGoodStanding($overallGoodStanding) + { + $this->overallGoodStanding = $overallGoodStanding; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/ContentOwnerDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/ContentOwnerDetails.php new file mode 100644 index 0000000..5ae6b92 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/ContentOwnerDetails.php @@ -0,0 +1,64 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Details; + + +class ContentOwnerDetails +{ + /** + * @var string + */ + private $contentOwner; + + /** + * @var \DateTime + */ + private $timeLinked; + + /** + * @return string + */ + public function getContentOwner() + { + return $this->contentOwner; + } + + /** + * @param string $contentOwner + * @return self + */ + public function setContentOwner($contentOwner) + { + $this->contentOwner = $contentOwner; + + return $this; + } + + /** + * @return \DateTime + */ + public function getTimeLinked() + { + return $this->timeLinked; + } + + /** + * @param \DateTime $timeLinked + * @return self + */ + public function setTimeLinked(\DateTime $timeLinked) + { + $this->timeLinked = $timeLinked; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/TopicDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/TopicDetails.php index 7b26946..a86c50d 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Details/TopicDetails.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/TopicDetails.php @@ -22,4 +22,42 @@ class TopicDetails * @var string[] */ private $relevantTopicIds; + + /** + * @return \string[] + */ + public function getRelevantTopicIds() + { + return $this->relevantTopicIds; + } + + /** + * @param \string[] $relevantTopicIds + * @return self + */ + public function setRelevantTopicIds($relevantTopicIds) + { + $this->relevantTopicIds = $relevantTopicIds; + + return $this; + } + + /** + * @return \string[] + */ + public function getTopicIds() + { + return $this->topicIds; + } + + /** + * @param \string[] $topicIds + * @return self + */ + public function setTopicIds($topicIds) + { + $this->topicIds = $topicIds; + + return $this; + } } diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/InvideoPromotion.php b/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/InvideoPromotion.php new file mode 100644 index 0000000..14c5ed4 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/InvideoPromotion.php @@ -0,0 +1,128 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\InvideoPromotion; + + +class InvideoPromotion +{ + /** + * @var Timing + */ + private $defaultTiming; + + /** + * @var array + */ + private $position; + + /** + * @var Item[] + */ + private $items; + + /** + * @var boolean + */ + private $useSmartTiming; + + public function __construct() + { + $this->items = []; + } + + /** + * @return Timing + */ + public function getDefaultTiming() + { + return $this->defaultTiming; + } + + /** + * @param Timing $defaultTiming + * @return self + */ + public function setDefaultTiming(Timing $defaultTiming) + { + $this->defaultTiming = $defaultTiming; + + return $this; + } + + /** + * @return Item[] + */ + public function getItems() + { + return $this->items; + } + + /** + * @param Item[] $items + * @return self + */ + public function setItems(array $items) + { + $this->items = $items; + + return $this; + } + + /** + * @param Item $item + * @return self + */ + public function addItem(Item $item) + { + $this->items[] = $item; + + return $this; + } + + /** + * @return array + */ + public function getPosition() + { + return $this->position; + } + + /** + * @param array $position + * @return self + */ + public function setPosition($position) + { + $this->position = $position; + + return $this; + } + + /** + * @return boolean + */ + public function isUseSmartTiming() + { + return $this->useSmartTiming; + } + + /** + * @param boolean $useSmartTiming + * @return self + */ + public function setUseSmartTiming($useSmartTiming) + { + $this->useSmartTiming = $useSmartTiming; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/Item.php b/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/Item.php new file mode 100644 index 0000000..92c9675 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/Item.php @@ -0,0 +1,112 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\InvideoPromotion; + + +class Item +{ + /** + * @var array + */ + private $id; + + /** + * @var Timing + */ + private $timing; + + /** + * @var string + */ + private $customMessage; + + /** + * @var string + */ + private $promotedByContentOwner; + + /** + * @return string + */ + public function getCustomMessage() + { + return $this->customMessage; + } + + /** + * @param string $customMessage + * @return self + */ + public function setCustomMessage($customMessage) + { + $this->customMessage = $customMessage; + + return $this; + } + + /** + * @return array + */ + public function getId() + { + return $this->id; + } + + /** + * @param array $id + * @return self + */ + public function setId(array $id) + { + $this->id = $id; + + return $this; + } + + /** + * @return string + */ + public function getPromotedByContentOwner() + { + return $this->promotedByContentOwner; + } + + /** + * @param string $promotedByContentOwner + * @return self + */ + public function setPromotedByContentOwner($promotedByContentOwner) + { + $this->promotedByContentOwner = $promotedByContentOwner; + + return $this; + } + + /** + * @return Timing + */ + public function getTiming() + { + return $this->timing; + } + + /** + * @param Timing $timing + * @return self + */ + public function setTiming(Timing $timing) + { + $this->timing = $timing; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/Timing.php b/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/Timing.php new file mode 100644 index 0000000..98e7af7 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/Timing.php @@ -0,0 +1,88 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\InvideoPromotion; + + +class Timing +{ + /** + * @var string + */ + private $type; + + /** + * @var int + */ + private $offsetMs; + + /** + * @var int + */ + private $durationMs; + + /** + * @return int + */ + public function getDurationMs() + { + return $this->durationMs; + } + + /** + * @param int $durationMs + * @return self + */ + public function setDurationMs($durationMs) + { + $this->durationMs = $durationMs; + + return $this; + } + + /** + * @return int + */ + public function getOffsetMs() + { + return $this->offsetMs; + } + + /** + * @param int $offsetMs + * @return self + */ + public function setOffsetMs($offsetMs) + { + $this->offsetMs = $offsetMs; + + return $this; + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + * @return self + */ + public function setType($type) + { + $this->type = $type; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Standard/Url.php b/lib/Nekland/YoutubeApi/Transformer/Model/Standard/Url.php new file mode 100644 index 0000000..e169491 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Standard/Url.php @@ -0,0 +1,86 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Standard; + + +class Url +{ + /** + * @var string + */ + private $default; + + /** + * @var array + */ + private $localized; + + /** + * @param string $localization + * @return string + * @throws \InvalidArgumentException + */ + public function getUrl($localization = null) + { + if (!$localization) { + return $this->default; + } + + foreach ($this->localized as $localeUrl) { + if ($localeUrl['language'] === $localization) { + return $localeUrl['value']; + } + } + + throw new \InvalidArgumentException(sprintf( + 'The language "%s" is not known for url "%s"', $localization, $this->default + )); + } + + /** + * @return string + */ + public function getDefault() + { + return $this->default; + } + + /** + * @param string $default + * @return self + */ + public function setDefault($default) + { + $this->default = $default; + + return $this; + } + + /** + * @return array + */ + public function getLocalized() + { + return $this->localized; + } + + /** + * @param array $localized + * @return self + */ + public function setLocalized(array $localized) + { + $this->localized = $localized; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Status/ChannelStatus.php b/lib/Nekland/YoutubeApi/Transformer/Model/Status/ChannelStatus.php new file mode 100644 index 0000000..28f3088 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Status/ChannelStatus.php @@ -0,0 +1,64 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Status; + + +class ChannelStatus extends SimpleStatus +{ + /** + * @var bool + */ + private $isLinked; + + /** + * @var string + */ + private $longUploadsStatus; + + /** + * @return boolean + */ + public function isIsLinked() + { + return $this->isLinked; + } + + /** + * @param boolean $isLinked + * @return self + */ + public function setIsLinked($isLinked) + { + $this->isLinked = $isLinked; + + return $this; + } + + /** + * @return string + */ + public function getLongUploadsStatus() + { + return $this->longUploadsStatus; + } + + /** + * @param string $longUploadsStatus + * @return self + */ + public function setLongUploadsStatus($longUploadsStatus) + { + $this->longUploadsStatus = $longUploadsStatus; + + return $this; + } +} From a64dd0877709f34dbfc2e77fa34838051d3a80af Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sun, 12 Oct 2014 17:24:41 +0200 Subject: [PATCH 14/23] Added ChannelSection model --- .../Transformer/Model/ChannelSection.php | 64 +++++++++ .../Model/Details/ChannelSectionDetails.php | 64 +++++++++ .../Model/Snippet/ChannelSectionSnippet.php | 136 ++++++++++++++++++ .../Transformer/ModelTransformer.php | 4 + 4 files changed, 268 insertions(+) create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/ChannelSection.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Details/ChannelSectionDetails.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Snippet/ChannelSectionSnippet.php diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/ChannelSection.php b/lib/Nekland/YoutubeApi/Transformer/Model/ChannelSection.php new file mode 100644 index 0000000..a781594 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/ChannelSection.php @@ -0,0 +1,64 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + + +class ChannelSection extends Item +{ + /** + * @var Snippet\ChannelSectionSnippet + */ + private $snippet; + + /** + * @var Details\ChannelSectionDetails + */ + private $contentDetails; + + /** + * @return Details\ChannelSectionDetails + */ + public function getContentDetails() + { + return $this->contentDetails; + } + + /** + * @param Details\ChannelSectionDetails $contentDetails + * @return self + */ + public function setContentDetails(Details\ChannelSectionDetails $contentDetails) + { + $this->contentDetails = $contentDetails; + + return $this; + } + + /** + * @return Snippet\ChannelSectionSnippet + */ + public function getSnippet() + { + return $this->snippet; + } + + /** + * @param Snippet\ChannelSectionSnippet $snippet + * @return self + */ + public function setSnippet(Snippet\ChannelSectionSnippet $snippet) + { + $this->snippet = $snippet; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/ChannelSectionDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/ChannelSectionDetails.php new file mode 100644 index 0000000..e65e835 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/ChannelSectionDetails.php @@ -0,0 +1,64 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Details; + + +class ChannelSectionDetails +{ + /** + * @var array + */ + private $playlists; + + /** + * @var array + */ + private $channels; + + /** + * @return array + */ + public function getChannels() + { + return $this->channels; + } + + /** + * @param array $channels + * @return self + */ + public function setChannels(array $channels) + { + $this->channels = $channels; + + return $this; + } + + /** + * @return array + */ + public function getPlaylists() + { + return $this->playlists; + } + + /** + * @param array $playlists + * @return self + */ + public function setPlaylists(array $playlists) + { + $this->playlists = $playlists; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/ChannelSectionSnippet.php b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/ChannelSectionSnippet.php new file mode 100644 index 0000000..70601c2 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/ChannelSectionSnippet.php @@ -0,0 +1,136 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Snippet; + + +class ChannelSectionSnippet extends Snippet +{ + /** + * @var string + */ + private $style; + + /** + * @var string + */ + private $type; + + /** + * @var string + */ + private $channelId; + + /** + * @var string + */ + private $title; + + /** + * @var int + */ + private $position; + + /** + * @return string + */ + public function getChannelId() + { + return $this->channelId; + } + + /** + * @param string $channelId + * @return self + */ + public function setChannelId($channelId) + { + $this->channelId = $channelId; + + return $this; + } + + /** + * @return int + */ + public function getPosition() + { + return $this->position; + } + + /** + * @param int $position + * @return self + */ + public function setPosition($position) + { + $this->position = $position; + + return $this; + } + + /** + * @return string + */ + public function getStyle() + { + return $this->style; + } + + /** + * @param string $style + * @return self + */ + public function setStyle($style) + { + $this->style = $style; + + return $this; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + * @return self + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + * @return self + */ + public function setType($type) + { + $this->type = $type; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php b/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php index ed98982..eee9a24 100644 --- a/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php +++ b/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php @@ -39,6 +39,10 @@ public function transform($data, $type = self::UNKNOWN) return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\Video'); case 'youtube#playlistListResponse': return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\Playlist'); + case 'youtube#channelListResponse': + return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\Channel'); + case 'youtube#channelSectionListResponse': + return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\ChannelSection'); } } } From 788151c37d5ea01fef47e7be792725fb182da4ef Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sun, 12 Oct 2014 17:38:30 +0200 Subject: [PATCH 15/23] Il8n models --- .../Transformer/Model/GuideCategory.php | 40 ++++++++++++ .../Transformer/Model/I18nLanguage.php | 40 ++++++++++++ .../Transformer/Model/I18nRegion.php | 40 ++++++++++++ .../Model/Snippet/ChannelSectionSnippet.php | 50 +-------------- .../Model/Snippet/GuideCategorySnippet.php | 64 +++++++++++++++++++ .../Model/Snippet/I18nLanguageSnippet.php | 64 +++++++++++++++++++ .../Model/Snippet/I18nRegionSnippet.php | 64 +++++++++++++++++++ .../Transformer/ModelTransformer.php | 6 ++ 8 files changed, 319 insertions(+), 49 deletions(-) create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/GuideCategory.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/I18nLanguage.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/I18nRegion.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Snippet/GuideCategorySnippet.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Snippet/I18nLanguageSnippet.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Snippet/I18nRegionSnippet.php diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/GuideCategory.php b/lib/Nekland/YoutubeApi/Transformer/Model/GuideCategory.php new file mode 100644 index 0000000..f6d15de --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/GuideCategory.php @@ -0,0 +1,40 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + + +class GuideCategory extends Item +{ + /** + * @var Snippet\GuideCategorySnippet + */ + private $snippet; + + /** + * @return Snippet\GuideCategorySnippet + */ + public function getSnippet() + { + return $this->snippet; + } + + /** + * @param Snippet\GuideCategorySnippet $snippet + * @return self + */ + public function setSnippet(Snippet\GuideCategorySnippet $snippet) + { + $this->snippet = $snippet; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/I18nLanguage.php b/lib/Nekland/YoutubeApi/Transformer/Model/I18nLanguage.php new file mode 100644 index 0000000..ab32975 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/I18nLanguage.php @@ -0,0 +1,40 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + + +class I18nLanguage extends Item +{ + /** + * @var Snippet\I18nLanguageSnippet + */ + private $snippet; + + /** + * @return Snippet\I18nLanguageSnippet + */ + public function getSnippet() + { + return $this->snippet; + } + + /** + * @param Snippet\I18nLanguageSnippet $snippet + * @return self + */ + public function setSnippet(Snippet\I18nLanguageSnippet $snippet) + { + $this->snippet = $snippet; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/I18nRegion.php b/lib/Nekland/YoutubeApi/Transformer/Model/I18nRegion.php new file mode 100644 index 0000000..b8f40db --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/I18nRegion.php @@ -0,0 +1,40 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + + +class I18nRegion extends Item +{ + /** + * @var Snippet\I18nRegionSnippet + */ + private $snippet; + + /** + * @return Snippet\I18nRegionSnippet + */ + public function getSnippet() + { + return $this->snippet; + } + + /** + * @param Snippet\I18nRegionSnippet $snippet + * @return self + */ + public function setSnippet(Snippet\I18nRegionSnippet $snippet) + { + $this->snippet = $snippet; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/ChannelSectionSnippet.php b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/ChannelSectionSnippet.php index 70601c2..a2cb276 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/ChannelSectionSnippet.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/ChannelSectionSnippet.php @@ -12,7 +12,7 @@ namespace Nekland\YoutubeApi\Transformer\Model\Snippet; -class ChannelSectionSnippet extends Snippet +class ChannelSectionSnippet extends GuideCategorySnippet { /** * @var string @@ -24,40 +24,11 @@ class ChannelSectionSnippet extends Snippet */ private $type; - /** - * @var string - */ - private $channelId; - - /** - * @var string - */ - private $title; - /** * @var int */ private $position; - /** - * @return string - */ - public function getChannelId() - { - return $this->channelId; - } - - /** - * @param string $channelId - * @return self - */ - public function setChannelId($channelId) - { - $this->channelId = $channelId; - - return $this; - } - /** * @return int */ @@ -96,25 +67,6 @@ public function setStyle($style) return $this; } - /** - * @return string - */ - public function getTitle() - { - return $this->title; - } - - /** - * @param string $title - * @return self - */ - public function setTitle($title) - { - $this->title = $title; - - return $this; - } - /** * @return string */ diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/GuideCategorySnippet.php b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/GuideCategorySnippet.php new file mode 100644 index 0000000..31b046e --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/GuideCategorySnippet.php @@ -0,0 +1,64 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Snippet; + + +class GuideCategorySnippet +{ + /** + * @var string + */ + private $channelId; + + /** + * @var string + */ + private $title; + + /** + * @return string + */ + public function getChannelId() + { + return $this->channelId; + } + + /** + * @param string $channelId + * @return self + */ + public function setChannelId($channelId) + { + $this->channelId = $channelId; + + return $this; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + * @return self + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/I18nLanguageSnippet.php b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/I18nLanguageSnippet.php new file mode 100644 index 0000000..157f319 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/I18nLanguageSnippet.php @@ -0,0 +1,64 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Snippet; + + +class I18nLanguageSnippet +{ + /** + * @var string + */ + private $hl; + + /** + * @var string + */ + private $name; + + /** + * @return string + */ + public function getHl() + { + return $this->hl; + } + + /** + * @param string $hl + * @return self + */ + public function setHl($hl) + { + $this->hl = $hl; + + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * @return self + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/I18nRegionSnippet.php b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/I18nRegionSnippet.php new file mode 100644 index 0000000..160d807 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/I18nRegionSnippet.php @@ -0,0 +1,64 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Snippet; + + +class I18nRegionSnippet +{ + /** + * @var string + */ + private $gl; + + /** + * @var string + */ + private $name; + + /** + * @return string + */ + public function getGl() + { + return $this->gl; + } + + /** + * @param string $gl + * @return self + */ + public function setGl($gl) + { + $this->gl = $gl; + + return $this; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + * @return self + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php b/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php index eee9a24..fdedfc6 100644 --- a/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php +++ b/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php @@ -43,6 +43,12 @@ public function transform($data, $type = self::UNKNOWN) return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\Channel'); case 'youtube#channelSectionListResponse': return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\ChannelSection'); + case 'youtube#guideCategoryListResponse': + return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\GuideCategory'); + case 'youtube#i18nLanguageListResponse': + return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\I18nLanguage'); + case 'youtube#i18nRegionListResponse': + return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\I18nRegion'); } } } From a355c03d856adf3cd49feb3e7f21cca1d4eac016 Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sun, 12 Oct 2014 17:55:46 +0200 Subject: [PATCH 16/23] Added PlaylistItem and Search models --- .../Model/Details/PlaylistItemDetails.php | 113 ++++++++++++++++++ .../Transformer/Model/PlaylistItem.php | 88 ++++++++++++++ .../YoutubeApi/Transformer/Model/Search.php | 64 ++++++++++ .../Model/Snippet/PlaylistItemSnippet.php | 88 ++++++++++++++ .../Model/Snippet/SearchSnippet.php | 88 ++++++++++++++ .../Transformer/ModelTransformer.php | 4 + 6 files changed, 445 insertions(+) create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Details/PlaylistItemDetails.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/PlaylistItem.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Search.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Snippet/PlaylistItemSnippet.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Snippet/SearchSnippet.php diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/PlaylistItemDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/PlaylistItemDetails.php new file mode 100644 index 0000000..6a9e69b --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/PlaylistItemDetails.php @@ -0,0 +1,113 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + + +namespace Nekland\YoutubeApi\Transformer\Model\Details; + + +class PlaylistItemDetails +{ + /** + * @var string + */ + private $videoId; + + /** + * @var string + */ + private $startAt; + + /** + * @var string + */ + private $endAt; + + /** + * @var string + */ + private $note; + + /** + * @return string + */ + public function getEndAt() + { + return $this->endAt; + } + + /** + * @param string $endAt + * @return self + */ + public function setEndAt($endAt) + { + $this->endAt = $endAt; + + return $this; + } + + /** + * @return string + */ + public function getNote() + { + return $this->note; + } + + /** + * @param string $note + * @return self + */ + public function setNote($note) + { + $this->note = $note; + + return $this; + } + + /** + * @return string + */ + public function getStartAt() + { + return $this->startAt; + } + + /** + * @param string $startAt + * @return self + */ + public function setStartAt($startAt) + { + $this->startAt = $startAt; + + return $this; + } + + /** + * @return string + */ + public function getVideoId() + { + return $this->videoId; + } + + /** + * @param string $videoId + * @return self + */ + public function setVideoId($videoId) + { + $this->videoId = $videoId; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/PlaylistItem.php b/lib/Nekland/YoutubeApi/Transformer/Model/PlaylistItem.php new file mode 100644 index 0000000..6451d10 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/PlaylistItem.php @@ -0,0 +1,88 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + + +class PlaylistItem extends Item +{ + /** + * @var Snippet\PlaylistItemSnippet + */ + private $snippet; + + /** + * @var Status\SimpleStatus + */ + private $status; + + /** + * @var Details\PlaylistItemDetails + */ + private $contentDetails; + + /** + * @return Details\PlaylistItemDetails + */ + public function getContentDetails() + { + return $this->contentDetails; + } + + /** + * @param Details\PlaylistItemDetails $contentDetails + * @return self + */ + public function setContentDetails(Details\PlaylistItemDetails $contentDetails) + { + $this->contentDetails = $contentDetails; + + return $this; + } + + /** + * @return Snippet\PlaylistItemSnippet + */ + public function getSnippet() + { + return $this->snippet; + } + + /** + * @param Snippet\PlaylistItemSnippet $snippet + * @return self + */ + public function setSnippet(Snippet\PlaylistItemSnippet $snippet) + { + $this->snippet = $snippet; + + return $this; + } + + /** + * @return Status\SimpleStatus + */ + public function getStatus() + { + return $this->status; + } + + /** + * @param Status\SimpleStatus $status + * @return self + */ + public function setStatus(Status\SimpleStatus $status) + { + $this->status = $status; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Search.php b/lib/Nekland/YoutubeApi/Transformer/Model/Search.php new file mode 100644 index 0000000..5e204bc --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Search.php @@ -0,0 +1,64 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + + +class Search extends Item +{ + /** + * @var array + */ + private $id; + + /** + * @var Snippet\SearchSnippet + */ + private $snippet; + + /** + * @return array + */ + public function getId() + { + return $this->id; + } + + /** + * @param array $id + * @return self + */ + public function setId($id) + { + $this->id = $id; + + return $this; + } + + /** + * @return Snippet\SearchSnippet + */ + public function getSnippet() + { + return $this->snippet; + } + + /** + * @param Snippet\SearchSnippet $snippet + * @return self + */ + public function setSnippet($snippet) + { + $this->snippet = $snippet; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/PlaylistItemSnippet.php b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/PlaylistItemSnippet.php new file mode 100644 index 0000000..72cc1c8 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/PlaylistItemSnippet.php @@ -0,0 +1,88 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Snippet; + + +class PlaylistItemSnippet extends PlaylistSnippet +{ + /** + * @var string + */ + private $playlistId; + + /** + * @var int + */ + private $position; + + /** + * @var array + */ + private $resourceId; + + /** + * @return string + */ + public function getPlaylistId() + { + return $this->playlistId; + } + + /** + * @param string $playlistId + * @return self + */ + public function setPlaylistId($playlistId) + { + $this->playlistId = $playlistId; + + return $this; + } + + /** + * @return int + */ + public function getPosition() + { + return $this->position; + } + + /** + * @param int $position + * @return self + */ + public function setPosition($position) + { + $this->position = $position; + + return $this; + } + + /** + * @return array + */ + public function getResourceId() + { + return $this->resourceId; + } + + /** + * @param array $resourceId + * @return self + */ + public function setResourceId(array $resourceId) + { + $this->resourceId = $resourceId; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/SearchSnippet.php b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/SearchSnippet.php new file mode 100644 index 0000000..7a68ef6 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/SearchSnippet.php @@ -0,0 +1,88 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Snippet; + + +class SearchSnippet extends Snippet +{ + /** + * @var string + */ + private $channelId; + + /** + * @var string + */ + private $channelTitle; + + /** + * @var string + */ + private $liveBroadcastContent; + + /** + * @return string + */ + public function getChannelId() + { + return $this->channelId; + } + + /** + * @param string $channelId + * @return self + */ + public function setChannelId($channelId) + { + $this->channelId = $channelId; + + return $this; + } + + /** + * @return string + */ + public function getChannelTitle() + { + return $this->channelTitle; + } + + /** + * @param string $channelTitle + * @return self + */ + public function setChannelTitle($channelTitle) + { + $this->channelTitle = $channelTitle; + + return $this; + } + + /** + * @return string + */ + public function getLiveBroadcastContent() + { + return $this->liveBroadcastContent; + } + + /** + * @param string $liveBroadcastContent + * @return self + */ + public function setLiveBroadcastContent($liveBroadcastContent) + { + $this->liveBroadcastContent = $liveBroadcastContent; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php b/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php index fdedfc6..2de70a1 100644 --- a/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php +++ b/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php @@ -49,6 +49,10 @@ public function transform($data, $type = self::UNKNOWN) return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\I18nLanguage'); case 'youtube#i18nRegionListResponse': return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\I18nRegion'); + case 'youtube#playlistItemListResponse': + return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\PlaylistItem'); + case 'youtube#searchListResponse': + return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\Search'); } } } From 8d34ac734804c9cf839d79c95893b76bf90429eb Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sun, 12 Oct 2014 18:26:42 +0200 Subject: [PATCH 17/23] Added Subscription , VideoCategory model --- .../Model/Details/LiveStreamingDetails.php | 95 +++++++++++++ .../Model/Details/SubscriptionDetails.php | 88 ++++++++++++ .../Model/Details/VideoDetails.php | 133 ++++++++++++++++++ .../Transformer/Model/Snippet/Snippet.php | 7 +- .../Model/Snippet/SubscriberSnippet.php | 124 ++++++++++++++++ .../Model/Snippet/SubscriptionSnippet.php | 88 ++++++++++++ .../Model/Snippet/VideoCategorySnippet.php | 88 ++++++++++++ .../Model/{Details => Standard}/Thumbnail.php | 2 +- .../Transformer/Model/Subscription.php | 88 ++++++++++++ .../Transformer/Model/Thumbnail.php | 89 ++++++++++++ .../Transformer/Model/VideoCategory.php | 17 +++ .../Transformer/ModelTransformer.php | 4 + 12 files changed, 818 insertions(+), 5 deletions(-) create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Details/SubscriptionDetails.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Snippet/SubscriberSnippet.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Snippet/SubscriptionSnippet.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Snippet/VideoCategorySnippet.php rename lib/Nekland/YoutubeApi/Transformer/Model/{Details => Standard}/Thumbnail.php (95%) create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Subscription.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Thumbnail.php create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/VideoCategory.php diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/LiveStreamingDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/LiveStreamingDetails.php index 9155558..cb6c560 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Details/LiveStreamingDetails.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/LiveStreamingDetails.php @@ -37,4 +37,99 @@ class LiveStreamingDetails * @var integer */ private $concurrentViewers; + + /** + * @return \DateTime + */ + public function getActualEndTime() + { + return $this->actualEndTime; + } + + /** + * @param \DateTime $actualEndTime + * @return self + */ + public function setActualEndTime(\DateTime $actualEndTime) + { + $this->actualEndTime = $actualEndTime; + + return $this; + } + + /** + * @return \DateTime + */ + public function getActualStartTime() + { + return $this->actualStartTime; + } + + /** + * @param \DateTime $actualStartTime + * @return self + */ + public function setActualStartTime(\DateTime $actualStartTime) + { + $this->actualStartTime = $actualStartTime; + + return $this; + } + + /** + * @return int + */ + public function getConcurrentViewers() + { + return $this->concurrentViewers; + } + + /** + * @param int $concurrentViewers + * @return self + */ + public function setConcurrentViewers($concurrentViewers) + { + $this->concurrentViewers = $concurrentViewers; + + return $this; + } + + /** + * @return \DateTime + */ + public function getScheduledEndTime() + { + return $this->scheduledEndTime; + } + + /** + * @param \DateTime $scheduledEndTime + * @return self + */ + public function setScheduledEndTime(\DateTime $scheduledEndTime) + { + $this->scheduledEndTime = $scheduledEndTime; + + return $this; + } + + /** + * @return \DateTime + */ + public function getScheduledStartTime() + { + return $this->scheduledStartTime; + } + + /** + * @param \DateTime $scheduledStartTime + * @return self + */ + public function setScheduledStartTime(\DateTime $scheduledStartTime) + { + $this->scheduledStartTime = $scheduledStartTime; + + return $this; + } } diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/SubscriptionDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/SubscriptionDetails.php new file mode 100644 index 0000000..8ffbf58 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/SubscriptionDetails.php @@ -0,0 +1,88 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Details; + + +class SubscriptionDetails +{ + /** + * @var int + */ + private $totalItemCount; + + /** + * @var int + */ + private $newItemCount; + + /** + * @var string + */ + private $activityType; + + /** + * @return string + */ + public function getActivityType() + { + return $this->activityType; + } + + /** + * @param string $activityType + * @return self + */ + public function setActivityType($activityType) + { + $this->activityType = $activityType; + + return $this; + } + + /** + * @return int + */ + public function getNewItemCount() + { + return $this->newItemCount; + } + + /** + * @param int $newItemCount + * @return self + */ + public function setNewItemCount($newItemCount) + { + $this->newItemCount = $newItemCount; + + return $this; + } + + /** + * @return int + */ + public function getTotalItemCount() + { + return $this->totalItemCount; + } + + /** + * @param int $totalItemCount + * @return self + */ + public function setTotalItemCount($totalItemCount) + { + $this->totalItemCount = $totalItemCount; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/VideoDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/VideoDetails.php index 4223ba1..2eb73af 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Details/VideoDetails.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/VideoDetails.php @@ -47,4 +47,137 @@ class VideoDetails * @var string[] */ private $contentRating; + + /** + * @return string + */ + public function getCaption() + { + return $this->caption; + } + + /** + * @param string $caption + * @return self + */ + public function setCaption($caption) + { + $this->caption = $caption; + + return $this; + } + + /** + * @return \string[] + */ + public function getContentRating() + { + return $this->contentRating; + } + + /** + * @param \string[] $contentRating + * @return self + */ + public function setContentRating(array $contentRating) + { + $this->contentRating = $contentRating; + + return $this; + } + + /** + * @return string + */ + public function getDefinition() + { + return $this->definition; + } + + /** + * @param string $definition + * @return self + */ + public function setDefinition($definition) + { + $this->definition = $definition; + + return $this; + } + + /** + * @return string + */ + public function getDimension() + { + return $this->dimension; + } + + /** + * @param string $dimension + * @return self + */ + public function setDimension($dimension) + { + $this->dimension = $dimension; + + return $this; + } + + /** + * @return string + */ + public function getDuration() + { + return $this->duration; + } + + /** + * @param string $duration + * @return self + */ + public function setDuration($duration) + { + $this->duration = $duration; + + return $this; + } + + /** + * @return boolean + */ + public function isLicensedContent() + { + return $this->licensedContent; + } + + /** + * @param boolean $licensedContent + * @return self + */ + public function setLicensedContent($licensedContent) + { + $this->licensedContent = $licensedContent; + + return $this; + } + + /** + * @return \array[] + */ + public function getRegionRestriction() + { + return $this->regionRestriction; + } + + /** + * @param \array[] $regionRestriction + * @return self + */ + public function setRegionRestriction(array $regionRestriction) + { + $this->regionRestriction = $regionRestriction; + + return $this; + } } diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/Snippet.php b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/Snippet.php index c6388d1..73c7af4 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/Snippet.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/Snippet.php @@ -11,8 +11,7 @@ namespace Nekland\YoutubeApi\Transformer\Model\Snippet; - -use Nekland\YoutubeApi\Transformer\Model\Details\Thumbnail; +use Nekland\YoutubeApi\Transformer\Model\Standard\Thumbnail; class Snippet { @@ -56,7 +55,7 @@ public function setTitle($title) } /** - * @return \Nekland\YoutubeApi\Transformer\Model\Details\Thumbnail[] + * @return Thumbnail[] */ public function getThumbnails() { @@ -64,7 +63,7 @@ public function getThumbnails() } /** - * @param \Nekland\YoutubeApi\Transformer\Model\Details\Thumbnail[] $thumbnails + * @param Thumbnail[] $thumbnails * @return self */ public function setThumbnails(array $thumbnails) diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/SubscriberSnippet.php b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/SubscriberSnippet.php new file mode 100644 index 0000000..7f7c59a --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/SubscriberSnippet.php @@ -0,0 +1,124 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Snippet; + +use Nekland\YoutubeApi\Transformer\Model\Standard\Thumbnail; + +class SubscriberSnippet +{ + /** + * @var string + */ + private $title; + + /** + * @var string + */ + private $description; + + /** + * @var string + */ + private $channelId; + + /** + * @var Thumbnail[] + */ + private $thumbnails; + + /** + * @return string + */ + public function getChannelId() + { + return $this->channelId; + } + + /** + * @param string $channelId + * @return self + */ + public function setChannelId($channelId) + { + $this->channelId = $channelId; + + return $this; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param string $description + * @return self + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + * @return self + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * @return \Nekland\YoutubeApi\Transformer\Model\Standard\Thumbnail[] + */ + public function getThumbnails() + { + return $this->thumbnails; + } + + /** + * @param \Nekland\YoutubeApi\Transformer\Model\Standard\Thumbnail[] $thumbnails + * @return self + */ + public function setThumbnails(array $thumbnails) + { + $this->thumbnails = $thumbnails; + + return $this; + } + + /** + * @param Thumbnail $thumbnail + * @return self + */ + public function addThumbnail(Thumbnail $thumbnail) + { + $this->thumbnails[] = $thumbnail; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/SubscriptionSnippet.php b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/SubscriptionSnippet.php new file mode 100644 index 0000000..28a8886 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/SubscriptionSnippet.php @@ -0,0 +1,88 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Snippet; + + +class SubscriptionSnippet extends Snippet +{ + /** + * @var string + */ + private $channelTitle; + + /** + * @var string + */ + private $channelId; + + /** + * @var array + */ + private $resourceId; + + /** + * @return string + */ + public function getChannelId() + { + return $this->channelId; + } + + /** + * @param string $channelId + * @return self + */ + public function setChannelId($channelId) + { + $this->channelId = $channelId; + + return $this; + } + + /** + * @return string + */ + public function getChannelTitle() + { + return $this->channelTitle; + } + + /** + * @param string $channelTitle + * @return self + */ + public function setChannelTitle($channelTitle) + { + $this->channelTitle = $channelTitle; + + return $this; + } + + /** + * @return array + */ + public function getResourceId() + { + return $this->resourceId; + } + + /** + * @param array $resourceId + * @return self + */ + public function setResourceId($resourceId) + { + $this->resourceId = $resourceId; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/VideoCategorySnippet.php b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/VideoCategorySnippet.php new file mode 100644 index 0000000..b3748fc --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Snippet/VideoCategorySnippet.php @@ -0,0 +1,88 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Snippet; + + +class VideoCategorySnippet +{ + /** + * @var string + */ + private $channelId; + + /** + * @var string + */ + private $title; + + /** + * @var bool + */ + private $assignable; + + /** + * @return boolean + */ + public function isAssignable() + { + return $this->assignable; + } + + /** + * @param boolean $assignable + * @return self + */ + public function setAssignable($assignable) + { + $this->assignable = $assignable; + + return $this; + } + + /** + * @return string + */ + public function getChannelId() + { + return $this->channelId; + } + + /** + * @param string $channelId + * @return self + */ + public function setChannelId($channelId) + { + $this->channelId = $channelId; + + return $this; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param string $title + * @return self + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/Thumbnail.php b/lib/Nekland/YoutubeApi/Transformer/Model/Standard/Thumbnail.php similarity index 95% rename from lib/Nekland/YoutubeApi/Transformer/Model/Details/Thumbnail.php rename to lib/Nekland/YoutubeApi/Transformer/Model/Standard/Thumbnail.php index 7017b48..43e88f4 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Details/Thumbnail.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Standard/Thumbnail.php @@ -9,7 +9,7 @@ * on the root directory of this project */ -namespace Nekland\YoutubeApi\Transformer\Model\Details; +namespace Nekland\YoutubeApi\Transformer\Model\Standard; class Thumbnail { diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Subscription.php b/lib/Nekland/YoutubeApi/Transformer/Model/Subscription.php new file mode 100644 index 0000000..12c774a --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Subscription.php @@ -0,0 +1,88 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + + +class Subscription extends Item +{ + /** + * @var Snippet\SubscriptionSnippet + */ + private $snippet; + + /** + * @var Details\SubscriptionDetails + */ + private $contentDetails; + + /** + * @var Snippet\SubscriberSnippet + */ + private $subscriberSnippet; + + /** + * @return Details\SubscriptionDetails + */ + public function getContentDetails() + { + return $this->contentDetails; + } + + /** + * @param Details\SubscriptionDetails $contentDetails + * @return self + */ + public function setContentDetails(Details\SubscriptionDetails $contentDetails) + { + $this->contentDetails = $contentDetails; + + return $this; + } + + /** + * @return Snippet\SubscriptionSnippet + */ + public function getSnippet() + { + return $this->snippet; + } + + /** + * @param Snippet\SubscriptionSnippet $snippet + * @return self + */ + public function setSnippet(Snippet\SubscriptionSnippet $snippet) + { + $this->snippet = $snippet; + + return $this; + } + + /** + * @return Snippet\SubscriberSnippet + */ + public function getSubscriberSnippet() + { + return $this->subscriberSnippet; + } + + /** + * @param Snippet\SubscriberSnippet $subscriberSnippet + * @return self + */ + public function setSubscriberSnippet(Snippet\SubscriberSnippet $subscriberSnippet) + { + $this->subscriberSnippet = $subscriberSnippet; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Thumbnail.php b/lib/Nekland/YoutubeApi/Transformer/Model/Thumbnail.php new file mode 100644 index 0000000..c771dde --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Thumbnail.php @@ -0,0 +1,89 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + +use Nekland\YoutubeApi\Transformer\Model\Standard\Thumbnail as StandardThumbnail; + +class Thumbnail +{ + /** + * @var StandardThumbnail + */ + private $default; + + /** + * @var StandardThumbnail + */ + private $medium; + + /** + * @var StandardThumbnail + */ + private $high; + + /** + * @return StandardThumbnail + */ + public function getDefault() + { + return $this->default; + } + + /** + * @param StandardThumbnail $default + * @return self + */ + public function setDefault(StandardThumbnail $default) + { + $this->default = $default; + + return $this; + } + + /** + * @return StandardThumbnail + */ + public function getHigh() + { + return $this->high; + } + + /** + * @param StandardThumbnail $high + * @return self + */ + public function setHigh(StandardThumbnail $high) + { + $this->high = $high; + + return $this; + } + + /** + * @return StandardThumbnail + */ + public function getMedium() + { + return $this->medium; + } + + /** + * @param StandardThumbnail $medium + * @return self + */ + public function setMedium(StandardThumbnail $medium) + { + $this->medium = $medium; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/VideoCategory.php b/lib/Nekland/YoutubeApi/Transformer/Model/VideoCategory.php new file mode 100644 index 0000000..98bbb77 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/VideoCategory.php @@ -0,0 +1,17 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + +class VideoCategory extends Item +{ + private $snippet; +} diff --git a/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php b/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php index 2de70a1..0077cf8 100644 --- a/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php +++ b/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php @@ -53,6 +53,10 @@ public function transform($data, $type = self::UNKNOWN) return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\PlaylistItem'); case 'youtube#searchListResponse': return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\Search'); + case 'youtube#subscriptionListResponse': + return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\Subscription'); + case 'youtube#videoCategoryListResponse': + return $this->transformList($data, '\Nekland\YoutubeApi\Transformer\Model\VideoCategory'); } } } From 270984f12d861ff82514e785f8063b160d4f2a33 Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sun, 12 Oct 2014 18:31:19 +0200 Subject: [PATCH 18/23] Added Watermark model --- .../InvideoPromotion/InvideoPromotion.php | 11 ++-- .../Model/InvideoPromotion/Item.php | 2 + .../Transformer/Model/Standard/Position.php | 63 +++++++++++++++++++ .../{InvideoPromotion => Standard}/Timing.php | 2 +- .../Transformer/Model/Watermark.php | 41 ++++++++++++ 5 files changed, 114 insertions(+), 5 deletions(-) create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Standard/Position.php rename lib/Nekland/YoutubeApi/Transformer/Model/{InvideoPromotion => Standard}/Timing.php (95%) create mode 100644 lib/Nekland/YoutubeApi/Transformer/Model/Watermark.php diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/InvideoPromotion.php b/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/InvideoPromotion.php index 14c5ed4..55841cd 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/InvideoPromotion.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/InvideoPromotion.php @@ -12,6 +12,9 @@ namespace Nekland\YoutubeApi\Transformer\Model\InvideoPromotion; +use Nekland\YoutubeApi\Transformer\Model\Standard\Position; +use Nekland\YoutubeApi\Transformer\Model\Standard\Timing; + class InvideoPromotion { /** @@ -20,7 +23,7 @@ class InvideoPromotion private $defaultTiming; /** - * @var array + * @var Position */ private $position; @@ -89,7 +92,7 @@ public function addItem(Item $item) } /** - * @return array + * @return Position */ public function getPosition() { @@ -97,10 +100,10 @@ public function getPosition() } /** - * @param array $position + * @param Position $position * @return self */ - public function setPosition($position) + public function setPosition(Position $position) { $this->position = $position; diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/Item.php b/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/Item.php index 92c9675..c76de50 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/Item.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/Item.php @@ -12,6 +12,8 @@ namespace Nekland\YoutubeApi\Transformer\Model\InvideoPromotion; +use Nekland\YoutubeApi\Transformer\Model\Standard\Timing; + class Item { /** diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Standard/Position.php b/lib/Nekland/YoutubeApi/Transformer/Model/Standard/Position.php new file mode 100644 index 0000000..ee8bfa0 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Standard/Position.php @@ -0,0 +1,63 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model\Standard; + + +class Position +{ + /** + * @var string + */ + private $type; + + /** + * @var string + */ + private $cornerPosition; + + /** + * @return string + */ + public function getCornerPosition() + { + return $this->cornerPosition; + } + + /** + * @param string $cornerPosition + * @return self + */ + public function setCornerPosition($cornerPosition) + { + $this->cornerPosition = $cornerPosition; + + return $this; + } + + /** + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * @param string $type + * @return self + */ + public function setType($type) + { + $this->type = $type; + + return $this; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/Timing.php b/lib/Nekland/YoutubeApi/Transformer/Model/Standard/Timing.php similarity index 95% rename from lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/Timing.php rename to lib/Nekland/YoutubeApi/Transformer/Model/Standard/Timing.php index 98e7af7..da62c04 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/InvideoPromotion/Timing.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Standard/Timing.php @@ -9,7 +9,7 @@ * on the root directory of this project */ -namespace Nekland\YoutubeApi\Transformer\Model\InvideoPromotion; +namespace Nekland\YoutubeApi\Transformer\Model\Standard; class Timing diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Watermark.php b/lib/Nekland/YoutubeApi/Transformer/Model/Watermark.php new file mode 100644 index 0000000..28f3a8f --- /dev/null +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Watermark.php @@ -0,0 +1,41 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Transformer\Model; + + +class Watermark +{ + /** + * @var Timing + */ + private $timing; + + /** + * @var Position + */ + private $position; + + /** + * @var string + */ + private $imageUrl; + + /** + * @var int + */ + private $imageBytes; + + /** + * @var string + */ + private $targetChannelId; +} From a28a52d418f8818456d2d830c280007eaf9d8f6a Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sun, 12 Oct 2014 18:35:41 +0200 Subject: [PATCH 19/23] Fixed Video Model --- .../Transformer/Model/Details/FileDetails.php | 199 +++++++++++++++++- .../Model/Details/RecordingDetails.php | 61 +++++- .../YoutubeApi/Transformer/Model/Video.php | 8 +- 3 files changed, 260 insertions(+), 8 deletions(-) diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/FileDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/FileDetails.php index ec414e8..80a428e 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Details/FileDetails.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/FileDetails.php @@ -19,7 +19,7 @@ class FileDetails private $fileName; /** - * @var integer + * @var int */ private $fileSize; @@ -44,12 +44,12 @@ class FileDetails private $audioStreams; /** - * @var integer + * @var int */ private $durationMs; /** - * @var integer + * @var int */ private $bitrateBps; @@ -58,5 +58,198 @@ class FileDetails */ private $recordingLocation; + /** + * @var string + */ private $creationTime; + + /** + * @return array + */ + public function getAudioStreams() + { + return $this->audioStreams; + } + + /** + * @param array $audioStreams + * @return self + */ + public function setAudioStreams(array $audioStreams) + { + $this->audioStreams = $audioStreams; + + return $this; + } + + /** + * @return int + */ + public function getBitrateBps() + { + return $this->bitrateBps; + } + + /** + * @param int $bitrateBps + * @return self + */ + public function setBitrateBps($bitrateBps) + { + $this->bitrateBps = $bitrateBps; + + return $this; + } + + /** + * @return string + */ + public function getContainer() + { + return $this->container; + } + + /** + * @param string $container + * @return self + */ + public function setContainer($container) + { + $this->container = $container; + + return $this; + } + + /** + * @return string + */ + public function getCreationTime() + { + return $this->creationTime; + } + + /** + * @param string $creationTime + * @return self + */ + public function setCreationTime($creationTime) + { + $this->creationTime = $creationTime; + + return $this; + } + + /** + * @return int + */ + public function getDurationMs() + { + return $this->durationMs; + } + + /** + * @param int $durationMs + * @return self + */ + public function setDurationMs($durationMs) + { + $this->durationMs = $durationMs; + + return $this; + } + + /** + * @return string + */ + public function getFileName() + { + return $this->fileName; + } + + /** + * @param string $fileName + * @return self + */ + public function setFileName($fileName) + { + $this->fileName = $fileName; + + return $this; + } + + /** + * @return int + */ + public function getFileSize() + { + return $this->fileSize; + } + + /** + * @param int $fileSize + * @return self + */ + public function setFileSize($fileSize) + { + $this->fileSize = $fileSize; + + return $this; + } + + /** + * @return string + */ + public function getFileType() + { + return $this->fileType; + } + + /** + * @param string $fileType + * @return self + */ + public function setFileType($fileType) + { + $this->fileType = $fileType; + + return $this; + } + + /** + * @return \Nekland\YoutubeApi\Transformer\Model\Standard\Location + */ + public function getRecordingLocation() + { + return $this->recordingLocation; + } + + /** + * @param \Nekland\YoutubeApi\Transformer\Model\Standard\Location $recordingLocation + * @return self + */ + public function setRecordingLocation($recordingLocation) + { + $this->recordingLocation = $recordingLocation; + + return $this; + } + + /** + * @return array + */ + public function getVideoStreams() + { + return $this->videoStreams; + } + + /** + * @param array $videoStreams + * @return self + */ + public function setVideoStreams(array $videoStreams) + { + $this->videoStreams = $videoStreams; + + return $this; + } } diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Details/RecordingDetails.php b/lib/Nekland/YoutubeApi/Transformer/Model/Details/RecordingDetails.php index 57fe050..a7c68ca 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Details/RecordingDetails.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Details/RecordingDetails.php @@ -11,6 +11,8 @@ namespace Nekland\YoutubeApi\Transformer\Model\Details; +use Nekland\YoutubeApi\Transformer\Model\Standard\Location; + class RecordingDetails { /** @@ -19,7 +21,7 @@ class RecordingDetails private $locationDescription; /** - * @var \Nekland\YoutubeApi\Transformer\Model\Standard\Location + * @var Location */ private $location; @@ -27,4 +29,61 @@ class RecordingDetails * @var \DateTime */ private $recordingDate; + + /** + * @return Location + */ + public function getLocation() + { + return $this->location; + } + + /** + * @param Location $location + * @return self + */ + public function setLocation(Location $location) + { + $this->location = $location; + + return $this; + } + + /** + * @return string + */ + public function getLocationDescription() + { + return $this->locationDescription; + } + + /** + * @param string $locationDescription + * @return self + */ + public function setLocationDescription($locationDescription) + { + $this->locationDescription = $locationDescription; + + return $this; + } + + /** + * @return \DateTime + */ + public function getRecordingDate() + { + return $this->recordingDate; + } + + /** + * @param \DateTime $recordingDate + * @return self + */ + public function setRecordingDate(\DateTime $recordingDate) + { + $this->recordingDate = $recordingDate; + + return $this; + } } diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Video.php b/lib/Nekland/YoutubeApi/Transformer/Model/Video.php index 53f2ed9..5c1372d 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Video.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Video.php @@ -121,7 +121,7 @@ public function getLiveStreamingDetails() * @param Details\LiveStreamingDetails $liveStreamingDetails * @return self */ - public function setLiveStreamingDetails($liveStreamingDetails) + public function setLiveStreamingDetails(Details\LiveStreamingDetails $liveStreamingDetails) { $this->liveStreamingDetails = $liveStreamingDetails; @@ -129,7 +129,7 @@ public function setLiveStreamingDetails($liveStreamingDetails) } /** - * @return array + * @return Standard\Player */ public function getPlayer() { @@ -137,10 +137,10 @@ public function getPlayer() } /** - * @param array $player + * @param Standard\Player $player * @return self */ - public function setPlayer(Standard\Player$player) + public function setPlayer(Standard\Player $player) { $this->player = $player; From 6461bc96c7e2ce4011ebe42123ce6b75dc6d93ca Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sun, 12 Oct 2014 18:49:51 +0200 Subject: [PATCH 20/23] Added Channels APIs --- lib/Nekland/YoutubeApi/Api/Activities.php | 2 +- .../YoutubeApi/Api/Behavior/ListTrait.php | 4 -- .../YoutubeApi/Api/ChannelSections.php | 35 ++++++++++++++++ lib/Nekland/YoutubeApi/Api/Channels.php | 41 +++++++++++++++++++ .../Transformer/Model/Collection.php | 6 ++- lib/Nekland/YoutubeApi/Youtube.php | 3 ++ 6 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 lib/Nekland/YoutubeApi/Api/ChannelSections.php create mode 100644 lib/Nekland/YoutubeApi/Api/Channels.php diff --git a/lib/Nekland/YoutubeApi/Api/Activities.php b/lib/Nekland/YoutubeApi/Api/Activities.php index d16e042..35b88c8 100644 --- a/lib/Nekland/YoutubeApi/Api/Activities.php +++ b/lib/Nekland/YoutubeApi/Api/Activities.php @@ -34,6 +34,6 @@ public function getUrl() public function getType() { - return 'playlist'; + return 'activity'; } } diff --git a/lib/Nekland/YoutubeApi/Api/Behavior/ListTrait.php b/lib/Nekland/YoutubeApi/Api/Behavior/ListTrait.php index 9b7ba5d..e9e2fbc 100644 --- a/lib/Nekland/YoutubeApi/Api/Behavior/ListTrait.php +++ b/lib/Nekland/YoutubeApi/Api/Behavior/ListTrait.php @@ -43,10 +43,6 @@ public function getById($id, array $parts = ['snippet'], array $otherParameters { $res = $this->listById($id, $parts, $otherParameters); - if ($res instanceof Collection) { - return $res[0]; - } - return $res['items'][0]; } diff --git a/lib/Nekland/YoutubeApi/Api/ChannelSections.php b/lib/Nekland/YoutubeApi/Api/ChannelSections.php new file mode 100644 index 0000000..8742389 --- /dev/null +++ b/lib/Nekland/YoutubeApi/Api/ChannelSections.php @@ -0,0 +1,35 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Api; + + +use Nekland\BaseApi\Api\AbstractApi; +use Nekland\YoutubeApi\Api\Behavior\ListTrait; + +/** + * Class ChannelSections + * + * Note about the "parts" array: it can take the following values: + * id, contentDetails, snippet. + * + * @see https://developers.google.com/youtube/v3/docs/channelSections/list for more information about paramaters + * @see https://developers.google.com/youtube/v3/docs/channelSections#resource for more information about json format + */ +class ChannelSections extends AbstractApi +{ + use ListTrait; + + public function getUrl() + { + return 'youtube/v3/channelSections'; + } +} diff --git a/lib/Nekland/YoutubeApi/Api/Channels.php b/lib/Nekland/YoutubeApi/Api/Channels.php new file mode 100644 index 0000000..3975bab --- /dev/null +++ b/lib/Nekland/YoutubeApi/Api/Channels.php @@ -0,0 +1,41 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Api; + + +use Nekland\BaseApi\Api\AbstractApi; +use Nekland\YoutubeApi\Api\Behavior\ListTrait; + +/** + * Class Channels + * + * Note about the "parts" array: it can take the following values: + * id, contentDetails, snippet, brandingSettings, auditDetails, + * contentOwnerDetails, invideoPromotion, statistics, status, topicDetails. + * + * @see https://developers.google.com/youtube/v3/docs/channels/list for more information about paramaters + * @see https://developers.google.com/youtube/v3/docs/channels#resource for more information about json format + */ +class Channels extends AbstractApi +{ + use ListTrait; + + public function getUrl() + { + return 'youtube/v3/channels'; + } + + public function getType() + { + return 'channel'; + } +} diff --git a/lib/Nekland/YoutubeApi/Transformer/Model/Collection.php b/lib/Nekland/YoutubeApi/Transformer/Model/Collection.php index d0de958..fd1577a 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Model/Collection.php +++ b/lib/Nekland/YoutubeApi/Transformer/Model/Collection.php @@ -185,7 +185,7 @@ public function getIterator() */ public function offsetExists($offset) { - return isset($this->items[$offset]); + return $offset === 'items' || isset($this->items[$offset]); } /** @@ -200,6 +200,10 @@ public function offsetExists($offset) */ public function offsetGet($offset) { + if ($offset === 'items') { + return $this->items; + } + return $this->items[$offset]; } diff --git a/lib/Nekland/YoutubeApi/Youtube.php b/lib/Nekland/YoutubeApi/Youtube.php index 88eeb45..4ea1bef 100644 --- a/lib/Nekland/YoutubeApi/Youtube.php +++ b/lib/Nekland/YoutubeApi/Youtube.php @@ -21,6 +21,9 @@ /** * @method \Nekland\YoutubeApi\Api\Videos getVideosApi * @method \Nekland\YoutubeApi\Api\Playlists getPlaylistsApi + * @method \Nekland\YoutubeApi\Api\Playlists getActivitiesApi + * @method \Nekland\YoutubeApi\Api\Playlists getChannelsApi + * @method \Nekland\YoutubeApi\Api\Playlists getChannelSectionsApi */ class Youtube extends ApiFactory { From 03e4361f13c8a1e9de9f279a5760d1dc19c67b6a Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sun, 12 Oct 2014 18:51:42 +0200 Subject: [PATCH 21/23] Added GuideCategoryApi --- .../YoutubeApi/Api/GuideCategories.php | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/Nekland/YoutubeApi/Api/GuideCategories.php diff --git a/lib/Nekland/YoutubeApi/Api/GuideCategories.php b/lib/Nekland/YoutubeApi/Api/GuideCategories.php new file mode 100644 index 0000000..92e375a --- /dev/null +++ b/lib/Nekland/YoutubeApi/Api/GuideCategories.php @@ -0,0 +1,35 @@ + + * + * For the full license, take a look to the LICENSE file + * on the root directory of this project + */ + +namespace Nekland\YoutubeApi\Api; + + +use Nekland\BaseApi\Api\AbstractApi; +use Nekland\YoutubeApi\Api\Behavior\ListTrait; + +/** + * Class GuideCategories + * + * Note about the "parts" array: it can take the following values: + * snippet + * + * @see https://developers.google.com/youtube/v3/docs/guideCategories/list for more information about paramaters + * @see https://developers.google.com/youtube/v3/docs/guideCategories#resource for more information about json format + */ +class GuideCategories extends AbstractApi +{ + use ListTrait; + + public function getUrl() + { + return 'youtube/v3/guideCategories'; + } +} From cb484fd35346b4f2ab5fb3ecc695ee43ac55a5e2 Mon Sep 17 00:00:00 2001 From: "Nek (Maxime Veber)" Date: Sun, 26 Oct 2014 21:13:06 +0100 Subject: [PATCH 22/23] Some fixes --- .../Hydrator/HydratorInterface.php | 7 +++++ .../Transformer/ModelTransformer.php | 1 - .../Transformer/ModelTransformerSpec.php | 26 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 spec/Nekland/YoutubeApi/Transformer/ModelTransformerSpec.php diff --git a/lib/Nekland/YoutubeApi/Transformer/Hydrator/HydratorInterface.php b/lib/Nekland/YoutubeApi/Transformer/Hydrator/HydratorInterface.php index 6992aa9..8f7e0d1 100644 --- a/lib/Nekland/YoutubeApi/Transformer/Hydrator/HydratorInterface.php +++ b/lib/Nekland/YoutubeApi/Transformer/Hydrator/HydratorInterface.php @@ -24,4 +24,11 @@ interface HydratorInterface * @return mixed */ public function hydrate($class, $data, array $exclude = []); + + /** + * @param string $class + * @param array $data + * @return \Nekland\YoutubeApi\Transformer\Model\Collection + */ + public function hydrateCollection($class, $data); } diff --git a/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php b/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php index 0077cf8..6c12f4b 100644 --- a/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php +++ b/lib/Nekland/YoutubeApi/Transformer/ModelTransformer.php @@ -11,7 +11,6 @@ namespace Nekland\YoutubeApi\Transformer; - use Nekland\BaseApi\Transformer\TransformerInterface; use Nekland\YoutubeApi\Transformer\Hydrator\Hydrator; use Nekland\YoutubeApi\Transformer\Hydrator\HydratorInterface; diff --git a/spec/Nekland/YoutubeApi/Transformer/ModelTransformerSpec.php b/spec/Nekland/YoutubeApi/Transformer/ModelTransformerSpec.php new file mode 100644 index 0000000..520b5b8 --- /dev/null +++ b/spec/Nekland/YoutubeApi/Transformer/ModelTransformerSpec.php @@ -0,0 +1,26 @@ +beConstructedWith($hydrator); + } + + public function it_can_hydrate_collections(HydratorInterface $hydrator) + { + // Data + $rawData = '{"kind": "youtube#videoListResponse"}'; + $data = json_decode($rawData, true); + + // what should happens + $hydrator->hydrateCollection('\Nekland\YoutubeApi\Transformer\Model\Video', $data)->shouldBeCalled(); + + $this->transform($rawData); + } +} From 074fef890196148aa8eaa5b460cc641f3375f343 Mon Sep 17 00:00:00 2001 From: Maxime Veber Date: Thu, 19 Mar 2015 11:21:09 +0100 Subject: [PATCH 23/23] Update LICENCE --- LICENCE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENCE b/LICENCE index 3d7cf52..0c0a2ba 100644 --- a/LICENCE +++ b/LICENCE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2013 Nekland +Copyright (c) 2013-2015 Nekland Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in