PHP Library for the Dark Sky API.
Clone or download
Latest commit e05a498 Jan 10, 2019

README.md

PHP Library for the Dark Sky API

Dark Sky API

Become a Patron

StyleCI Build Status Coverage Status

Latest Stable Version Latest Unstable Version Total Downloads License

The package provides a convenient way to interact with Dark Sky API.

It covers all the API functionality, including object-level access to the response headers, weather alerts and flags.

Installation

Use Composer to install the package:

composer require dmitry-ivanov/dark-sky-api

Basic Usage

Forecast Request

use DmitryIvanov\DarkSkyApi\DarkSkyApi;

$forecast = (new DarkSkyApi('secret-key'))
    ->location(46.482, 30.723)
    ->units('si')
    ->language('ru')
    ->forecast('currently');

echo $forecast->currently()->summary();

Time Machine Requests

use DmitryIvanov\DarkSkyApi\DarkSkyApi;

$timeMachine = (new DarkSkyApi('secret-key'))
    ->location(46.482, 30.723)
    ->units('si')
    ->language('ru')
    ->timeMachine('2018-12-01', ['daily', 'flags']);

echo $timeMachine->daily()->summary();

Multiple requests are sent concurrently:

use DmitryIvanov\DarkSkyApi\DarkSkyApi;

$timeMachine = (new DarkSkyApi('secret-key'))
    ->location(46.482, 30.723)
    ->timeMachine(['2018-12-01', '2018-12-02', '2018-12-03']);

echo $timeMachine['2018-12-02']->daily()->summary();

Laravel Support

If you're using Laravel <5.5, you have to register the service provider and alias by yourself.

The package utilizes Laravel Package Discovery, so you'll get the service provider and alias registered out-of-the-box.

Set your Secret Key in .env file:

DARK_SKY_KEY="Your Secret Key"

You may use the configured facade now:

use DarkSkyApi;

$forecast = DarkSkyApi::location(46.482, 30.723)
    ->units('si')
    ->language('ru')
    ->forecast('currently');

echo $forecast->currently()->summary();

Publish the config file to override request parameters (optionally):

php artisan vendor:publish --provider="DmitryIvanov\DarkSkyApi\Adapters\Laravel\DarkSkyApiServiceProvider"

Further Reading

You can find more information in my article entirely dedicated to this Library.

License

Dark Sky API is open-sourced software licensed under the MIT license.

Support on Patreon