A simple async client for Dark Sky API
- PHP >= 7.1
- Get the API key from https://darksky.net/dev
- Install this package in your project:
composer require api-client-darsky/darksky-client
Once installed, you can use the following code to access a api server and get some weather data:
use ApiClients\Client\DarkSkyClient\AsyncClient;
use React\EventLoop\Factory;
use function ApiClients\Foundation\resource_pretty_print;
require dirname(__DIR__) . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
$loop = Factory::create();
$latitude = '37.8267';
$longitude = '-122.4233';
$client = AsyncClient::create($loop, require 'resolve_token.php');
$client->fetch( $latitude, $longitude)
->done(function (ApiClients\Client\DarkSkyClient\Resource\ResponseInterface $response) {
resource_pretty_print($response);
});
$loop->run();
See also the examples.