Note: This datasource is not yet compatible with the v2 API, feel free to update it if you need this functionality!
This datasource acts as a basic wrapper for the Foursquare API that allows you to interact with the API from Cake as you would with any model.
- Place foursquare_source.php in your app/models/datasources folder
- Add the credentials to database.php
- Add your datasource and call some methods
Simply check out or download this repository to your app folder and make sure everything is in the right place.
Your database configuration would look something like this:
<?php
class DATABASE_CONFIG {
/* these would be your existing DB credentials */
var $default = array(
//...
);
/* and here we have your Foursquare credentials */
var $foursquare = array(
'datasource' => 'foursquare',
'email' => 'your_foursquare_email_adress',
'password' => 'your_foursquare_password',
);
}
?>
An example where you make your Foursquare data available right into a controller would look something like this:
<?php
class FoursquareController extends AppController {
/* we don't want annoying warnings about missing tables */
var $uses = array();
function index(){
/* We initialize the new datasource like so */
$this->Foursquare = ConnectionManager::getDataSource('foursquare');
/* And then we call any of the available methods, the venues method in this case */
$result = $this->Foursquare->venues('51.914835', '4.473985', null, 10); // params: lat, long, name, limit
debug($result); // returns an array with 10 venues near the Boijmans van Beuningen Museum in Rotterdam, the Netherlands
}
}
?>