Knp\Bundle\KnpBundlesBundle\Twitterer\TrendingBundleTwitterer::tweet PHP Method

tweet() public method

public tweet ( ) : boolean | Bundle
return boolean | Knp\Bundle\KnpBundlesBundle\Entity\Bundle
    public function tweet()
    {
        /* @var $trendingBundle Bundle*/
        if (!($trendingBundle = $this->em->getRepository('KnpBundlesBundle:Bundle')->findLatestTrend($this->twitterParams['idle_period']))) {
            throw new TrendingBundleNotFoundException();
        }
        $timestamp = time();
        $parameters = array('oauth_consumer_key' => $this->twitterParams['oauth_client_id'], 'oauth_timestamp' => $timestamp, 'oauth_nonce' => md5(microtime() . mt_rand()), 'oauth_version' => '1.0', 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_token' => $this->twitterParams['oauth_token']);
        $parameters['oauth_signature'] = OAuthUtils::signRequest('POST', $this->twitterApiUrl, $parameters, $this->twitterParams['oauth_client_secret'], $this->twitterParams['oauth_token_secret']);
        $response = $this->httpRequest($this->twitterApiUrl, $this->prepareMessage($trendingBundle), $parameters, array(), 'POST');
        if ($response->isSuccessful()) {
            $trendingBundle->setLastTweetedAt(new \DateTime());
            $this->em->persist($trendingBundle);
            $activity = new Activity();
            $activity->setType(Activity::ACTIVITY_TYPE_TWEETED);
            $activity->setCreatedAt(new \DateTime());
            $activity->setBundle($trendingBundle);
            $this->em->persist($activity);
            $this->em->flush();
            return $trendingBundle;
        }
        return false;
    }