PHP Library for the Dark Sky API.
Switch branches/tags
Nothing to show
Clone or download

README.md

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.


Refactoring now...


Table of contents

Usage

  1. Install the package via Composer:

    composer require illuminated/dark-sky
  2. Set the key in the .env file:

    DARK_SKY_KEY=[Your Secret Key]
    
  3. Use DarkSky class:

    use DarkSky;
    
    $forecast = DarkSky::at($latitude, $longitude)->forecast();

    Check the Dark Sky API for more information about the response format.

Forecast

Get the weather forecast:

$forecast = DarkSky::at($latitude, $longitude)->forecast();

Specify desired data blocks to reduce the response size:

$forecast = DarkSky::at($latitude, $longitude)->forecast('daily');
$forecast = DarkSky::at($latitude, $longitude)->forecast(['daily', 'hourly']);

Time Machine

Get the weather conditions for a particular date:

$weather = DarkSky::at($latitude, $longitude)->timeMachine('1986-05-11');

Or get the weather conditions for several dates via concurrent requests:

$weather = DarkSky::at($latitude, $longitude)->timeMachine(['1986-05-11', '1987-05-11']);

Specify desired data blocks to reduce the response size:

$weather = DarkSky::at($latitude, $longitude)->timeMachine('1986-05-11', 'daily');
$weather = DarkSky::at($latitude, $longitude)->timeMachine('1986-05-11', ['daily', 'hourly']);

Customization

Language

Change the language of response properties:

$forecast = DarkSky::at($latitude, $longitude)->lang('ru')->forecast();
$weather  = DarkSky::at($latitude, $longitude)->lang('ru')->timeMachine('1986-05-11');

Units

Change the units of response weather conditions:

$forecast = DarkSky::at($latitude, $longitude)->units('si')->forecast();
$weather  = DarkSky::at($latitude, $longitude)->units('si')->timeMachine('1986-05-11');

Extend

Extend hour-by-hour forecast to the next 168 hours, instead of the next 48:

$forecast = DarkSky::at($latitude, $longitude)->extend()->forecast();

Advanced

Configuration

You can publish config to override default language, units, etc:

php artisan vendor:publish --provider="Illuminated\DarkSky\ServiceProvider"

Caching, caching, caching!

Each time you get the weather - you do the real API calls!

Use caching to improve your application speed and reduce API load:

$forecast = Cache::remember($key, $minutes, function () {
    return DarkSky::at($latitude, $longitude)->forecast();
});

License

The MIT License. Please see License File for more information.

Support on Patreon