waqidevs / waqi-php-client
PHP wrapper for the AQICN (air quality) APIs
Requires
- php: ^7.2 || ^8.0
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpunit/phpunit: ^9
This package is auto-updated.
Last update: 2024-12-12 11:43:09 UTC
README
PHP client library for the World Air Quality Index (WAQI) APIs. See documentation here. All available API modules are supported - City feed, Geolocalized feed, Search, and Map Queries.
Installation
You can install this package with composer using the command below
composer require waqidevs/waqi-php-client
Get API key
Sign up for an API key here
Making Requests
The primary WAQI\API
class is a factory class that creates objects for each of the API modules, allowing you to make requests to any of them with your desired request parameters. You have to first create an object for it, then access your desired API module via the object. See the code snippets below:
$api = new WAQI\API(WAQI_TOKEN);
For City Feed:
$response = $api->cityFeed() ->setCity("Munich") ->fetch();
For Search:
$response = $api->search() ->setKeyword("Johannesburg") ->fetch();
For Lat/Lng based Geolocalized feed:
$response = $api->geoFeed() ->setCoordinates(37.7749, -122.4194) ->fetch();
For IP based Geolocalized feed:
$response = $api->ipFeed() ->setIP("MY_IP") ->fetch();
For Map Queries:
$response = $api->mapStation() ->setMapBounds(40.712, -74.006, 34.052, -118.243) ->fetch();