voku / weather
Weather API Wrapper
0.7.1
2023-07-24 00:06 UTC
Requires
- php: 8.1.*||8.2.*
- psr/http-client-implementation: *
- psr/http-factory-implementation: *
Requires (Dev)
- php-cs-fixer/shim: v3.22.*
- phpstan/phpstan: 1.10.*
- phpunit/phpunit: 9.6.*
- voku/httpful: 3.0.*
- dev-main
- 0.7.1
- 0.7.0
- 0.6.0
- 0.5.2
- 0.5.1
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- dev-renovate/php-8.x
- dev-renovate/phpunit-phpunit-11.x
- dev-renovate/actions-cache-4.x
- dev-renovate/actions-cache-3.x
- dev-renovate/php-cs-fixer-shim-3.x
- dev-renovate/codecov-codecov-action-5.x
- dev-renovate/major-phpstan-packages
- dev-renovate/phpstan-packages
- dev-renovate/shivammathur-setup-php-2.x
- dev-renovate/major-github-artifact-actions
- dev-whitesource/configure
This package is auto-updated.
Last update: 2024-12-21 03:08:41 UTC
README
Weather Data Wrapper
This is a simple wrapper around the "Bright Sky" (https://brightsky.dev/) weather api.
- you can simply replace the weather api by implementing another weather provider class.
DEMO: (https://github.com/voku/weather-demo)
http://weather-demo.suckup.de/
Install via "composer require"
composer require voku/weather
composer require voku/httpful # or another php-http/client-implementation e.g. "php-http/react-adapter" + "nyholm/psr7"
Usage:
use voku\weather\provider\BrightskyHttpProvider; use voku\weather\WeatherQueryDto; require_once __DIR__ . '/vendor/autoload.php'; // example path $latitude = 48.137154; $longitude = 11.576124; $dateTime = new \DateTimeImmutable('2023-01-01 12:00:00'); $weatherQuery = new WeatherQueryDto( $latitude, $longitude, $dateTime ); $weather = (new BrightskyHttpProvider())->getWeatherHistorical($weatherQuery); echo $weather->temperature; // 17.1
Example 1: (temperature with unit)
echo $weather->getTemperatureWithUnit(); // 17.1 °C
Example 2: (wind-speed with unit)
echo $weather->getWindSpeedWithUnit(); // 9 km/h
Unit Test:
- Composer is a prerequisite for running the tests.
composer install
- The tests can be executed by running this command from the root directory:
./vendor/bin/phpunit
AbstractHttpProvider methods
getSources(): WeatherSourceDto[]
Parameters: nothing
Return:
\WeatherSourceDto[]
getWeatherCurrent(voku\weather\WeatherQueryDto $query):
Parameters:
voku\weather\WeatherQueryDto $query
Return:
voku\weather\WeatherDto
getWeatherForecast(voku\weather\WeatherQueryDto $query):
Parameters:
voku\weather\WeatherQueryDto $query
Return:
voku\weather\WeatherDto
getWeatherForecastCollection(voku\weather\WeatherQueryDto $query):
Parameters:
voku\weather\WeatherQueryDto $query
Return:
voku\weather\WeatherCollection
getWeatherHistorical(voku\weather\WeatherQueryDto $query):
Parameters:
voku\weather\WeatherQueryDto $query
Return:
voku\weather\WeatherDto
getWeatherHistoricalCollection(voku\weather\WeatherQueryDto $query):
Parameters:
voku\weather\WeatherQueryDto $query
Return:
voku\weather\WeatherCollection
Thanks
- Thanks to GitHub (Microsoft) for hosting the code and a good infrastructure including Issues-Management, etc.
- Thanks to IntelliJ as they make the best IDEs for PHP and they gave me an open source license for PhpStorm!
- Thanks to StyleCI for the simple but powerful code style check.
- Thanks to PHPStan && Psalm for really great Static analysis tools and for discover bugs in the code!