dmitry-ivanov/dark-sky-api

PHP Library for the Dark Sky API.

1.2.0 2020-03-19 17:46 UTC

This package is auto-updated.

Last update: 2020-06-30 19:29:33 UTC


README

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

PHP Library for the Dark Sky API.

Dark Sky API - Demo

Usage

  1. Install the package via Composer:

    composer require dmitry-ivanov/dark-sky-api
  2. Use the DmitryIvanov\DarkSkyApi\DarkSkyApi class:

    use DmitryIvanov\DarkSkyApi\DarkSkyApi;
    
    $forecast = (new DarkSkyApi('secret-key'))
        ->location(46.482, 30.723)
        ->forecast('daily');
    
    echo $forecast->daily()->summary();

Time Machine Requests

Sometimes it might be useful to get weather for the specified date:

$timeMachine = (new DarkSkyApi('secret-key'))
    ->location(46.482, 30.723)
    ->timeMachine('2020-01-01', 'daily');

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

You can also get weather for multiple dates:

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

echo $timeMachine['2020-01-02']->daily()->summary();

Usage in Laravel

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

  1. Publish the config:

    php artisan vendor:publish --provider="DmitryIvanov\DarkSkyApi\Adapters\Laravel\DarkSkyApiServiceProvider"
  2. Set your secret key in the .env file:

    DARK_SKY_KEY="Your-Secret-Key"
    
  3. Use the DarkSkyApi facade:

    use DarkSkyApi;
    
    $forecast = DarkSkyApi::location(46.482, 30.723)
        ->forecast('daily');
    
    echo $forecast->daily()->summary();

Learn more

You can find more information in my article.

License

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

Support on Patreon