-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from WyriHaximus/master
Youtube service
- Loading branch information
Showing
7 changed files
with
170 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,5 @@ parameters: | |
meetup_key: | ||
akismet_key: | ||
group_urlname: | ||
youtube_key: | ||
youtube_playlist: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/AmsterdamPHP/Bundle/SiteBundle/Resources/config/services.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/AmsterdamPHP/Bundle/SiteBundle/Service/YoutubeFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace AmsterdamPHP\Bundle\SiteBundle\Service; | ||
|
||
use Madcoda\Youtube; | ||
|
||
class YoutubeFactory | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $key; | ||
|
||
/** | ||
* @param string $key | ||
*/ | ||
public function __construct($key) | ||
{ | ||
$this->key = $key; | ||
} | ||
|
||
/** | ||
* @return Youtube | ||
*/ | ||
public function getClient() | ||
{ | ||
return new Youtube(array( | ||
'key' => $this->key, | ||
)); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/AmsterdamPHP/Bundle/SiteBundle/Service/YoutubeService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace AmsterdamPHP\Bundle\SiteBundle\Service; | ||
|
||
use Madcoda\Youtube; | ||
use Predis\Client as Cache; | ||
|
||
class YoutubeService | ||
{ | ||
const CACHE_TTL = '+24 hours'; | ||
|
||
/** | ||
* @var Youtube | ||
*/ | ||
protected $client; | ||
|
||
/** | ||
* @var Cache | ||
*/ | ||
protected $cache; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $playlist; | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
public function __construct(Cache $cache, Youtube $client, $playlist) | ||
{ | ||
$this->client = $client; | ||
$this->cache = $cache; | ||
$this->playlist = $playlist; | ||
} | ||
|
||
/** | ||
* Returns the latest blog posts | ||
* | ||
* @return mixed | ||
*/ | ||
public function getLatestVideos() | ||
{ | ||
$cacheKey = 'youtube.talks.latest'; | ||
$videoList = $this->cache->get($cacheKey); | ||
|
||
if ($videoList === null){ | ||
$videoList = base64_encode(serialize($this->client->getPlaylistItemsByPlaylistId($this->playlist))); | ||
$this->cache->set($cacheKey, $videoList); | ||
$this->cache->expireat($cacheKey, strtotime(self::CACHE_TTL)); | ||
} | ||
|
||
$videoList = unserialize(base64_decode($videoList)); | ||
|
||
return $videoList; | ||
} | ||
} |