Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

dmitry-ivanov/dark-sky-api

Repository files navigation

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