Skip to content

cbrownfieldpp/yelp-php

 
 

Repository files navigation

Yelp PHP Client

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads

A PHP client for authenticating with Yelp using OAuth 1 and consuming the search API.

Install

Via Composer

$ composer require stevenmaguire/yelp-php

Usage

Create client

    $client = new Stevenmaguire\Yelp\Client(array(
        'consumerKey' => 'YOUR COSUMER KEY',
        'consumerSecret' => 'YOUR CONSUMER SECRET',
        'token' => 'YOUR TOKEN',
        'tokenSecret' => 'YOUR TOKEN SECRET',
        'apiHost' => 'api.yelp.com' // Optional, default 'api.yelp.com'
    ));

Search by keyword and location

$results = $client->search(array('term' => 'Sushi', 'location' => 'Chicago, IL'));

Search by phone number

$results = $client->searchByPhone(array('phone' => '867-5309'));

Locate details for a specific business by Yelp business id

$results = $client->getBusiness('union-chicago-3');

You may include action links in your results by passing additional parameters with your request.

$resultsWithActionLinks = $client->getBusiness('union-chicago-3', [
    'actionLinks' => true
]);

Configure defaults

$client->setDefaultLocation('Chicago, IL')  // default location for all searches if location not provided
    ->setDefaultTerm('Sushi')               // default keyword for all searches if term not provided
    ->setSearchLimit(20);                   // number of records to return

Exceptions

If the API request results in an Http error, the client will throw a Stevenmaguire\Yelp\Exception that includes the response body, as a string, from the Yelp API.

$responseBody = $e->getResponseBody(); // string from Http request
$responseBodyObject = json_decode($responseBody);

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

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

About

A php client for consuming Yelp API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%