dmitry-ivanov/dark-sky-api

This package is abandoned and no longer maintained. No replacement package was suggested.

PHP Library for the Dark Sky API.

1.4.0 2022-03-12 15:01 UTC

This package is auto-updated.

Last update: 2024-03-13 15:55:56 UTC


README

PHP Library for the Dark Sky API

Dark Sky API

Buy me a coffee

StyleCI Build Status Coverage Status

Packagist Version Packagist Stars Packagist Downloads Packagist 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.

Sponsors

Laravel Idea
Material Theme UI Plugin

License

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

Support on Patreon  Buy me a coffee