everypolitician-php
![Software License][ico-license]
![Coverage Status][ico-scrutinizer]
![Total Downloads][ico-downloads], (*1)
A PHP library for easy access to EveryPolitician data. This is essentially a port of everypolitician-python, which is itself a port of everypolitican-ruby., (*2)
Install
Via Composer, (*3)
``` bash
$ composer require andylolz/everypolitician, (*4)
## Usage
Creating an instance of the EveryPolitican class allows you to access information on countries, their legislatures and legislative periods. Each country and legislature has a slug that can be used to reference them via the country and legislature methods:
``` php
use \EveryPolitician\EveryPolitician\EveryPolitician;
$ep = new EveryPolitician();
$australia = $ep->country('Australia');
$senate = $australia->legislature('Senate');
echo (string) $senate; // <Legislature: Senate in Australia>
$uk = $ep->country('UK');
$houseOfCommons = $uk->legislature('Commons');
$americanSamoa = $ep->country('American-Samoa');
$houseOfRepresentatives = $americanSamoa->legislature('House');
foreach ($ep->countries() as $country) {
echo $country->name.' has '.count($country->legislatures()).'legislatures';
}
By default this will get the EveryPolitician data and returns the most recent data. This data is found from the index file, called countries.json
, which links to specific versions of other data files., (*5)
If you want want to point to a different countries.json
file, you can override the default URL using ::fromUrl
:, (*6)
``` php
$ep = EveryPolitician::fromUrl('https://cdn.rawgit.com/everypolitician/everypolitician-data/080cb46/countries.json');, (*7)
The example above is using a specific commit (indicated by the hash `080cb46`). If you want to use a local copy of `countries.json` you can instead create the object using the `::fromFilename` method, e.g.:
``` php
$ep = EveryPolitician::fromFilename('/home/andy/tmp/countries.json');
For more about countries.json
, see this description., (*8)
Remember that EveryPolitician data is frequently updated — see this information about using EveryPolitician data., (*9)
More information on the EveryPolitician site., (*10)
Change log
Please see CHANGELOG for information on what has changed recently., (*11)
Testing
bash
$ composer test
, (*12)
Contributing
Please see CONTRIBUTING and CONDUCT for details., (*13)
Credits
License
The MIT License (MIT). Please see License File for more information., (*14)