Skip to content

Commit

Permalink
Fixed twitter feed handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Pascal de Vink committed Apr 15, 2012
1 parent 02e51f5 commit d171235
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/Pascal/FeedDisplayerBundle/Service/CacheService.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ protected function __construct()
{ {
$this->memcached = new \Memcached(); $this->memcached = new \Memcached();
$this->memcached->addServer('localhost', 11211); $this->memcached->addServer('localhost', 11211);

// $this->memcached->flush();
} }


public static function getInstance() public static function getInstance()
Expand Down
11 changes: 7 additions & 4 deletions src/Pascal/FeedGathererBundle/Service/TwitterFeedService.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Pascal\FeedGathererBundle\Service; namespace Pascal\FeedGathererBundle\Service;


use \Pascal\FeedGathererBundle\Entity\TwitterUser; use \Pascal\FeedGathererBundle\Entity\TwitterUser;
use \Pascal\FeedGathererBundle\Entity\Feed;


class TwitterFeedService implements FeedService class TwitterFeedService implements FeedService
{ {
Expand Down Expand Up @@ -33,7 +34,7 @@ public function getServiceType()
return 'twitter'; return 'twitter';
} }


public function downloadFeed(\Pascal\FeedGathererBundle\Entity\Feed $feed, \DateTime $lastUpdateTime) public function downloadFeed(Feed $feed, \DateTime $lastUpdateTime)
{ {
$twitter = $this->getTwitter(); $twitter = $this->getTwitter();
$twitterUser = $this->getTwitterUser($feed); $twitterUser = $this->getTwitterUser($feed);
Expand All @@ -49,14 +50,15 @@ public function downloadFeed(\Pascal\FeedGathererBundle\Entity\Feed $feed, \Date
if ($code == 200) if ($code == 200)
{ {
$timeline = json_decode($response['response'], true); $timeline = json_decode($response['response'], true);
$this->processItems($timeline, $twitterUser, $lastUpdateTime); $this->processItems($timeline, $twitterUser, $feed, $lastUpdateTime);
} }
} }


/** /**
* @param \Pascal\FeedGathererBundle\Entity\Feed $feed
* @return \Pascal\FeedGathererBundle\Entity\TwitterUser[] * @return \Pascal\FeedGathererBundle\Entity\TwitterUser[]
*/ */
protected function getTwitterUser(\Pascal\FeedGathererBundle\Entity\Feed $feed) protected function getTwitterUser(Feed $feed)
{ {
$dql = " $dql = "
SELECT t SELECT t
Expand All @@ -81,7 +83,7 @@ protected function getTwitter()
return $twitter; return $twitter;
} }


protected function processItems($items, TwitterUser $twitterUser, \DateTime $lastUpdateTime) protected function processItems($items, TwitterUser $twitterUser, Feed $feed, \DateTime $lastUpdateTime)
{ {
foreach($items as $item) foreach($items as $item)
{ {
Expand All @@ -106,6 +108,7 @@ protected function processItems($items, TwitterUser $twitterUser, \DateTime $las
$feedEntry->setTitle('Link shared by ' . $author); $feedEntry->setTitle('Link shared by ' . $author);
$feedEntry->setUrl($url['expanded_url']); $feedEntry->setUrl($url['expanded_url']);
$feedEntry->setLastUpdateTime($dateTime); $feedEntry->setLastUpdateTime($dateTime);
$feedEntry->setFeed($feed);


$this->entityManager->persist($feedEntry); $this->entityManager->persist($feedEntry);
} }
Expand Down

0 comments on commit d171235

Please sign in to comment.