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.
- Requires PHP 5.6+.
- Stand-alone PHP package.
- Ready-to-use in Laravel application.
- Each request utilizes HTTP compression.
- Time Machine Requests are sent concurrently.
Use Composer to install the package:
composer require dmitry-ivanov/dark-sky-api
use DmitryIvanov\DarkSkyApi\DarkSkyApi;
$forecast = (new DarkSkyApi('secret-key'))
->location(46.482, 30.723)
->units('si')
->language('ru')
->forecast('currently');
echo $forecast->currently()->summary();
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();
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"
You can find more information in my article entirely dedicated to this Library.
Dark Sky API is open-sourced software licensed under the MIT license.