dmitry-ivanov / dark-sky-api
PHP Library for the Dark Sky API.
Installs: 39 327
Dependents: 0
Suggesters: 0
Security: 0
Stars: 70
Watchers: 3
Forks: 6
Open Issues: 0
Requires
- php: >=5.6
- ext-json: *
- guzzlehttp/guzzle: ^6.3|^7.0
- psr/http-message: ^1.0
Requires (Dev)
- illuminate/contracts: ^5.1|^6.0|^7.0|^8.0|^9.0
- illuminate/support: ^5.1|^6.0|^7.0|^8.0|^9.0
- mockery/mockery: ^1.3.2
- phpunit/phpunit: ^5.7.10|^6.0|^7.0|^8.5.22|^9.0
README
Dark Sky API
PHP Library for the Dark Sky API.
Usage
-
Install the package via Composer:
composer require dmitry-ivanov/dark-sky-api
-
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!
-
Publish the config:
php artisan vendor:publish --provider="DmitryIvanov\DarkSkyApi\Adapters\Laravel\DarkSkyApiServiceProvider"
-
Set your secret key in the
.env
file:DARK_SKY_KEY="Your-Secret-Key"
-
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
License
Dark Sky API is open-sourced software licensed under the MIT license.