Package Data | |
---|---|
Maintainer Username: | iivannov |
Maintainer Contact: | iivannov@gmail.com (Ivan Ivanov) |
Package Create Date: | 2015-10-01 |
Package Last Update: | 2024-06-24 |
Home Page: | http://iivannov.github.io/larasquare |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-11 15:23:35 |
Package Statistics | |
---|---|
Total Downloads: | 5,054 |
Monthly Downloads: | 2 |
Daily Downloads: | 0 |
Total Stars: | 8 |
Total Watchers: | 2 |
Total Forks: | 5 |
Total Open Issues: | 3 |
Simple and extensible Foursquare API PHP Client with Laravel Facade and ServiceProvider based on Guzzle 6 Currently it supports only userless endpoint requests.
Via Composer
$ composer require iivannov/larasquare
To use the Laravel Facade you need to add the ServiceProvider and Facade classes in your config\app.php
'providers' => [
...
Iivannov\Larasquare\Provider\LarasquareServiceProvider::class,
];
'aliases' => [
...
'Larasquare' => Iivannov\Larasquare\Facade\Larasquare::class
];
You need to add your Foursquare client ID and secret in config\services.php
'foursquare' => [
'clientId' => YOUR_FOURSQUARE_CLIENT_ID,
'clientSecret' => YOUR_FOURSQUARE_CLIENT_SECRET
]
After this you can directly use the Laravel Facade
$venues = Larasquare::venues($searchQuery);
$config = [
clientId = YOUR_FOURSQUARE_CLIENT_ID,
clientSecretT = YOUR_FOURSQUARE_CLIENT_SECRET,
apiUrl = FOURSQUARE_API_URL, //optional
version = SUPPORTED_VERSION, //optional, format: YYYYMMDD
];
$foursquare = new Foursquare($config);
$venues = $foursquare->venues($searchQuery);
If you need to generate, filter or transform your search query you can extract all the logic in a separate class that implements the Iivannov\Larasquare\Filter\FilterContract
and then just inject it with setFilter()
method.
$venues = Larasquare::setFilter(new MyFilter())->venues();
Put your filter logic in the parse() method. It will automatically receive the query passed in the search methods. You can overwrite values, generate values from your custom array or whatever you need. The returned array will be sent with the Foursquare request.
/**
* Generate, transform or filter your search query
*
* @param $query
* @return array
*/
public function parse($query = [])
{
return [
'll' => $query['location']['lat'] . ',' . $query['location']['lon'],
'query' => $query['searchTerm'],
'near' => $_GET['nearLocation'],
'radius' => 200
];
}
** Endpoints not covered by this library **
You can use the request
method to query a Foursquare endpoint.
// get venue photos
$response = Larasquare::request("venues/$venueId/photos")
// get details about a tip,
$response = Larasquare::request("tips/$tipId")
** Searching Venues **
//Laravel
$venues = Larasquare::venues($query);
** Get a single venue **
$venues = Larasquare::venue($venueId);
** Other venues methods **
// get suggestion @see https://developer.foursquare.com/docs/venues/suggestcompletion
$venues = Larasquare::suggest($searchQuery);
// get trending @see https://developer.foursquare.com/docs/venues/trending
$venues = Larasquare::trending($searchQuery);
The MIT License (MIT). Please see License File for more information.