PHP Wrapper for the Big Huge Labs Thesaurus API
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.editorconfig
.gitattributes
.gitignore
.scrutinizer.yml
.styleci.yml
CONTRIBUTING.md
LICENSE.md
README.md
composer.json
phpunit.xml.dist

README.md

BigHugeThesaurusClient

Latest Version on Packagist Software License Total Downloads

PHP Wrapper for the Big Huge Labs Thesaurus API.

Install

Via Composer

$ composer require mettleworks/big-huge-thesaurus-client

Usage

$API_KEY = 'Get an api key @ https://words.bighugelabs.com/api.php';

$client = new Mettleworks\BigHugeThesaurusClient\BigHugeThesaurusClient($API_KEY);
$response = $client->lookup('love');

The response object is an instance of ThesaurusResponse, an object that wraps the original response and adds a few convenience methods. You can optionally pass an argument to each method to indicate if you want only nouns (noun), verbs (verb), adjectives (adjective) or adverbs (adverb) otherwise they will return all results combined. The signature of the methods is the following:

/**
 * Get the synonyms from the response
 */
$response->getSynonyms($type = null): array

/**
 * Get the antonyms from the response
 */
$response->getAntonyms($type = null): array

/**
 * Get the similar terms from the response
 */
$response->getSimilarTerms($type = null): array

/**
 * Get related terms from the response
 */
$response->getRelatedTerms($type = null): array

/**
 * Cast response to array (returns the original response)
 */ 
$response->toArray(): array

/**
 * Cast response to JSON
 */
$response->toJson()

The client throws specific exceptions when an error occurs. Those errors are documented on the Big Huge Thesaurus Api Page.

try {
    $response = $client->lookup('love');
} catch (NotFoundException $ex) {
    // Not Found
} catch (UsageExceededException $ex) {
    // Usage exceeded
} catch (InactiveKeyException $ex) {
    // Key not active
} catch (MissingWordsException $ex) {
    // No words provided
} catch (NotWhitelistedException $ex) {
    // IP address blocked
}

Additionally if an error occurs outside the listed ones, the original Guzzle Exception is thrown.

Testing

$ composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email maurizio@mettle.io instead of using the issue tracker.

Credits

License

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