-
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 1 commit
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace AmsterdamPHP\Bundle\SiteBundle\Service; | ||
|
||
use Madcoda\Youtube; | ||
use Predis\Client as Cache; | ||
|
||
class YoutubeService | ||
{ | ||
/** | ||
* @var Client | ||
*/ | ||
protected $client; | ||
|
||
/** | ||
* @var Cache | ||
*/ | ||
protected $cache; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $playlist; | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
public function __construct(Cache $cache, $key, $playlist) | ||
{ | ||
$this->client = new Youtube(array( | ||
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. Why would you create an instance of this dependency here and not in the service container? It feels kinda double now. 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. You're right, I'll look into it 👍 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. agreed, use the factory method functionality and you should be in the clear. |
||
'key' => $key, | ||
)); | ||
$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('+5 hours')); | ||
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 the cache can be set to something a bit further away in time. It only happens once a month at most that we post a video, so it doesn't have to be on the website immediately. 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. Agreed, so 24 hours or would you prefer going with a few days? 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. 24 hours would be better, yes 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. Also: make it a class constant for easier tweaking and more context. |
||
} | ||
|
||
$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?