yesterday we got a new mashape, called fourwalla.
This application is composed by three different mashapes:
1. the first is the Google Maps interface. It is composed by a single visual shape, that generates the HTML code needed to load an embeddable google map. It is the same application used in our first published mashape, flynomad. What is cool about that, is just the simplicity on how this developer has imported the Gmaps app inside fourwalla; less than a minute and without coding; copy and paste a little string of MIML and it's done.
2. the second is the Gowalla interface. It is written in PHP and uses curl and json to interact with gowalla's API.
3. the last is Foursquare interface. It is written in PHP too (we are still working on Ruby support). It's different from Gowalla's mashape because we had to use some regexps to parse the HTML code of foursqure website. The reason is that we wanted to have the same information extracted from both services. So it uses curl, json and regexp.
OK, but this is our developers blog, so I would like to share with you the PHP code that loads the list of spots around the coordinates provided (loaded via javascript from the google map)
function getNearestSpots($param) {
"&lng=".$param->get_longitude()."&radius=50";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array('User-Agent: Mashape/01',
'X-Gowalla-API-Key: <key>,
'Accept: application/json',
'mashape:<pwd>'
));
$response = curl_exec($ch);
$obj = json_decode($response);
$result = array();
foreach($obj->{'spots'} as $spot) {
$res = new getNearestSpotsResult();
$res->set_latitude($spot->{'lat'});
$res->set_longitude($spot->{'lng'});
$res->set_name($spot->{'name'});
$res->set_image($spot->{'image_url'});
$res->set_id( substr($spot->{'url'}, 7));
$result[] = $res;
}
return $result;
}
Isn't it nice? :)
It was developed and tested using vim and php, than it was uploaded on Mashape.com .. and now it works!
Mike