-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Youtube service #77
Youtube service #77
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,12 +27,16 @@ public function indexAction() | |
$blogService = $this->get('amsterdamphp_site.integration.blog'); | ||
$posts = $blogService->getLatestBlogPosts(); | ||
|
||
$youtubeService = $this->get('amsterdamphp_site.integration.youtube'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No feedback on your code, but we should definitely introduce controllers as services for better dependency injection. That would've also been a nice hackathon ticket 😝 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Controllers as services are overrated to be honest. Too much overhead for not enough benefit. |
||
$videos = $youtubeService->getLatestVideos(); | ||
|
||
return [ | ||
'header_photo' => $headerPhoto, | ||
'next_event' => array_shift($nextEvents), | ||
'past_events' => array_splice($pastEvents, 0, 2), | ||
'blog_posts' => $posts, | ||
'sponsors' => $sponsors | ||
'sponsors' => $sponsors, | ||
'videos' => $videos, | ||
]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,30 @@ | ||
parameters: | ||
amsterdamphp_site.integration.youtube_factory.class: AmsterdamPHP\Bundle\SiteBundle\Service\YoutubeFactory | ||
amsterdamphp_site.integration.youtube_client.class: Madcoda\Youtube | ||
|
||
services: | ||
amsterdamphp_site.integration.youtube_factory: | ||
class: %amsterdamphp_site.integration.youtube_factory.class% | ||
arguments: | ||
key: %youtube_key% | ||
|
||
amsterdamphp_site.integration.youtube_client: | ||
class: "%amsterdamphp_site.integration.youtube_client.class%" | ||
factory_service: amsterdamphp_site.integration.youtube_factory | ||
factory_method: getClient | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok i'm fine with this, even if you could drop the factory and just intantiate the client directly as a service, but this gives us a place to set defaults if we ever need them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After talking with you this was my assumption as how you preferred to have it setup. (Heck I took you meetup bundle as example.) If this is fine I'll let it be but if you really prefer instantiating the client directly I'll change it to that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's fine like this 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I/m fine with this way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great! 👍 |
||
|
||
amsterdamphp_site.integration.blog: | ||
class: AmsterdamPHP\Bundle\SiteBundle\Service\BlogService | ||
arguments: | ||
cache: @snc_redis.cache | ||
|
||
amsterdamphp_site.integration.youtube: | ||
class: AmsterdamPHP\Bundle\SiteBundle\Service\YoutubeService | ||
arguments: | ||
cache: @snc_redis.cache | ||
client: @amsterdamphp_site.integration.youtube_client | ||
playlist: %youtube_playlist% | ||
|
||
amsterdamphp_site.email.contact: | ||
class: AmsterdamPHP\Bundle\SiteBundle\Service\ContactService | ||
arguments: | ||
|
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, | ||
)); | ||
} | ||
} |
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; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparantly, animattr tagged a couple of versions in the mean time 😀 https://packagist.org/packages/antimattr/google-bundle, can we use a stable version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ow neat, I'll look into that 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking at the package name it's a different package then what is used for youtube. Maybe it's out of scope for this PR?