awelters / hatebase
Hatebase is a PHP HTTP client library for consuming the Hatebase API
dev-master
2016-10-12 20:22 UTC
Requires
- php: >=5.3.3
- ext-curl: *
This package is not auto-updated.
Last update: 2024-09-28 14:52:28 UTC
README
Simple PHP wrapper for v3.0 of the hatebase.org API
How to use
- Obtain a hatebase API key
- Install composer
- Create a new composer.json file with awelters/hatebase as a dependency (or add to your project's existing composer.json file)
{
"require": {
"awelters/hatebase": "dev-master"
}
}
- Use composer to install the dependencies
- Go ahead and try it out. The following php script can be used as a starting point by simply adding your Hatebase API key
<?php
/**
* Andrew's Hatebase script : Simple script to retrieve results from Hatebase API
*
* @category Awesomeness
* @date 3/03/2014
* @author Andrew Welters <awelters@hugmehugyou.org>
* @license http://opensource.org/licenses/MIT The MIT License
* @link http://www.hatebase.org/connect_api
* @link https://github.com/awelters/hatebase
*/
ini_set('display_errors', 1);
header('Content-type: application/json');
require_once __DIR__ . '/vendor/autoload.php'; // Autoload files using Composer autoload
use Hatebase\HatebaseAPI;
$settings = array(
'key' => '',
'version' => '3' //optional
);
$hatebase = new HatebaseAPI($settings);
//See http://www.hatebase.org/connect_api for filter options
$filters = array('about_nationality' => '1', 'language' => 'eng');
$output = 'json'; //either 'xml' or 'json', 'xml' is faster
$query_type = 'sightings'; //either 'vocabulary' or 'sightings'
try {
$result = $hatebase->performRequest($filters, $output, $query_type);
print_r($result);
}
catch(Exception $e) {
echo 'Error: '.$e;
}