Skip to content

Foursquare API Client providing a Laravel Facade and ServiceProvider

License

Notifications You must be signed in to change notification settings

sgatz/larasquare

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Larasquare

Latest Version on Packagist Software License Total Downloads

Simple and extensible Foursquare API PHP Client with Laravel Facade and ServiceProvider based on Guzzle 6 (and allowing Guzzle 7) Currently it supports only userless endpoint requests.

Install

Via Composer

$ composer require iivannov/larasquare

Usage with Laravel

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);

Standard Usage

$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);

Query filters

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
    ];
}

Methods

** 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);

License

The MIT License (MIT). Please see License File for more information.

About

Foursquare API Client providing a Laravel Facade and ServiceProvider

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%