iivannov / larasquare by iivannov

Simple and extensible Foursquare API PHP Client with Laravel Support based on Guzzle 6
5,040
8
2
Package Data
Maintainer Username: iivannov
Maintainer Contact: iivannov@gmail.com (Ivan Ivanov)
Package Create Date: 2015-10-01
Package Last Update: 2022-02-02
Home Page: http://iivannov.github.io/larasquare
Language: PHP
License: MIT
Last Refreshed: 2024-03-24 03:14:42
Package Statistics
Total Downloads: 5,040
Monthly Downloads: 3
Daily Downloads: 0
Total Stars: 8
Total Watchers: 2
Total Forks: 5
Total Open Issues: 3

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 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.