PHP Wrapper for the Big Huge Labs Thesaurus API.
Via Composer
$ composer require mettle/big-huge-thesaurus-client$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.
$ composer testPlease see CONTRIBUTING for details.
If you discover any security related issues, please email maurizio@mettle.io instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.