Consuming Services with Zend Framework

Just when Zend couldn’t get any better, it already is!!

Today we’re farting about with RSS feeds and Twitter feeds! It’s remarkably simple! Lets get cracking:

In your controller:

    //look for Ron Paul news and twitter (Americans please vote this guy!!!)
    $q = 'Ron%20Paul';
    $this->view->q = $q;

    //get twitter feeds
    $twitter = new Zend_Service_Twitter_Search();
    $this->view->tweets = $twitter->search($q,array('lang' => 'en', 'rpp' => 8, 'show_user' => true));

    // get Google News Atom feed
    $this->view->feeds = array();
    $gnewsFeed = "$q&output=atom";
    $this->view->feeds = Zend_Feed_Reader::import($gnewsFeed);

Thats it!!! In your view:

  $count = 0;  
  foreach ($this->feeds as $entry)
  <p class="post">
    <span class="text"><a href="<?php echo $entry->getLink(); ?>"> <?php echo $entry->getTitle(); ?></a></span>
    <span class="time"><?php echo $entry->getDateModified(); ?></span>

And for the tweets:

<?php foreach ($this->tweets['results'] as $tweet) {?>
<p class="tweet"> <span class="image">
<img src="<?php echo $tweet['profile_image_url']; ?>" /> </span>
<span class="user">
<?php echo $tweet['from_user'] . ': '; ?>
<span class="text">
<?php echo $tweet['text']; ?> </span>
<span class="time">
<?php echo $tweet['created_at']; ?>
<?php } ?>

Ok, I mean come on, how much easier does this stuff get?!?!?!? Rock on, amigos!