Welcome to the Ifbyphone Developers zone. This forum provides a place for the community of advanced Ifbyphone users and developers to share ideas, exchange code, and ask questions.  

Additional Resources

Ifbyphone Company Blog - Ifbyphone Twitter Page - Ifbyphone Company Web Site - Ifbyphone Partners Page
Ifbyphone's CEO's (Irv Shapiro's) Personal Blog - Irv Shapiro Twitter Page

It has been brought to our attention that the NEW MEMBER link does not always display in IE7. If you do not see the new member link in the login box on the right, please try another browser. (Firefox works fine.) In addition please note that Phonemashup accounts are completely separate from Ifbyphone accounts.

If you need help fast, call 877 295 5100 to reach the Ifbyphone "Success Team".   (Support is option 2.)

Members Login
Username 
 
Password 
    Remember Me  
Chatbox
Please log in to join the chat!
Post Info TOPIC: Yelp Mashup to find local Bars


Veteran Member

Status: Offline
Posts: 58
Date: Feb 27, 2009
Yelp Mashup to find local Bars
  
 


My colleague, Phil, wrote a neat little mashup with Yelp - the business review site.  His took a business' phone number as input and then came back and told you the average review as well as the number of reviews.  So when he was walking around, he could look at a place's phone number and quickly find out if it was any good.  I thought this was cool, but wanted to create something for a different situation.

What if I was in an unfamiliar location?  Wouldn't it be cool if I could find a couple places near by where I could relax and have a drink and watch the game?  So I created this slightly complex mashup that takes input of a Zip code, and will come back with a list of 3 nearby bars.  If you want, it'll even connect you to them right away in case you need directions. 

How:

IfByPhone: I needed 2 different Survos.  The first just gathers the Zip code and posts it to my web page.  The second takes back all the information I gathered and repeats it back to the caller.  It will read off the 3 bars, tell you their phone number and then offer you the ability to transfer to it if you'd like.

Yelp: Yelp provides a way for you to input a latitude and longitude and get search results based on a search term (in our case, 'bars').   It accepts calls via HTTP and responds in JSON. (link)

Yahoo: Provides a free API that accepts a Zip and reponds with a latitude and longitude.  (link)

Code:

// this is a standard cleaning routine.  It strips characters that our Survo's don't like automagically.

include("ibpcleanforvoice.include.php");

// CAPTURE THE BUSINESS PHONE NUMBER SENT FROM IFBYPHONE
$zip = $_REQUEST['zip'];

// this is the ID of the Survo that will accept the results from the Yelp call
$valid_business_survo = "XXXX";

$key = "YAHOOAPIKEY";
$url = "http://local.yahooapis.com/MapsService/V1/geocode?zip=$zip&appid=$key";
$text = file_get_contents($url);

$obj = simplexml_load_string($text);

$record = $obj->Result[0];
$lat = $obj->Result->Latitude;
$long = $obj->Result->Longitude;

-- The above code translates the Zip from the input to a lat & long --


$term = 'bars';
$key = "YELPAPIKEY";
$newurl = "http://api.yelp.com/business_review_search?term=$term&lat=$lat&long=$long&radius=10&num_biz_requested=3&ywsid=$key";

$text = file_get_contents($newurl);

$obj = json_decode($text);

-- This code gets the results from Yelp and puts them into $obj.  In order to control the call using IfByPhone, I need to create an XML stream that includes the next step (the Valid Business Survo ID), and what parameters I am going to need. Below I am constructing that XML response --

$xml_return = "
<action>
<app>survo</app>
<parameters>
<id>$valid_business_survo</id>
<user_parameters>
";
for ($x = 0; $x < sizeof($obj-> {'businesses'}); $x++) {
$bus = $obj->{'businesses'}[$x];
$xml_return = $xml_return . "
<name$x>" . cleanforvoice($bus->{'name'}) . "</name$x>
<city$x>" . cleanforvoice($bus->{'city'}) . "</city$x>
<rating$x>" . $bus->{'avg_rating'} . "</rating$x>
<review_count$x>" . $bus->{'review_count'} . "</review_count$x>
<phonenum$x>" . $bus->{phone} . "</phonenum$x>
";

}

//echo $xml_return;
$xml_return = $xml_return . "
</user_parameters>
</parameters>
</action>";

echo $xml_return;

-- The XML is created and I echo the results.  IfByPhone then routes the call to the Survo I have already set up, and uses Text To Speech to read that data to the caller.  --




__________________
Page 1 of 1  sorted by
 
Quick Reply

Please log in to post quick replies.

Post to Facebook Post to Digg Post to Del.icio.us

This is an open and public forum so Ifbyphone is unable to ensure that all code and suggestions posted to this forum are correct. Please use all code posted here at your own risk. Ifbyphone assumes no liability for code, recommendations and suggestions posted to this forum.

Users and developers will find hundreds of useful posts at the Ifbyphone company blog.