Rich2k / laravel-weatherkit

A Laravel library for accessing Apple's WeatherKit API
MIT License
2 stars 2 forks source link

Add weather alert support #8

Open Rich2k opened 1 year ago

Rich2k commented 1 year ago

https://developer.apple.com/documentation/weatherkitrestapi/get_api_v1_weatheralert_language_id

tafn3t commented 1 year ago

I needed this for my project and I integrated it on my own today. It only needs a few lines of code in your WeatherKit.php file.

Modified the $dataSets array protected array $dataSets = ['currentWeather', 'forecastDaily', 'forecastHourly', 'forecastNextHour', 'weatherAlerts'];

Added a new helper public function alerts(): Collection { return $this->getSingleDataSet('weatherAlerts'); }

Added required country to the buildParams array if ($this->country) { $this->params['country'] = $this->country; }

And it works. Apple requires the country code or it won't return the weatherAlerts data.

Nice work Rich2k! I hope this helps

Rich2k commented 1 year ago

@tafn3t thanks, I knew it wasn't much work, just not had the chance to add it yet. I will be soon so if you still need to add it from Composer, etc then I'll update this issue when I've completed it