api-client-darsky/darksky-client

Dark sky simple api client

dev-master 2018-09-07 12:39 UTC

This package is auto-updated.

Last update: 2020-10-13 18:51:16 UTC


README

A simple async client for Dark Sky API

Server Requirements

  • PHP >= 7.1

Install

  • Get the API key from https://darksky.net/dev
  • Install this package in your project:
    composer require api-client-darsky/darksky-client

Quickstart example

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.