OpenWeatherMap-API-CSharp icon indicating copy to clipboard operation
OpenWeatherMap-API-CSharp copied to clipboard

Add Daily Forecast

Open darkcloud784 opened this issue 2 years ago • 2 comments

Add the daily forecast endpoint.

http://api.openweathermap.org/data/2.5/forecast?appid={key}&q={query}

Currently only the weather endpoint is supported.

http://api.openweathermap.org/data/2.5/weather?appid={_apiKey}&q={queryString}

Alterantively you could just allow the implementor to decide which endpoint to use

private Uri GenerateRequestUrl(string queryString) => new Uri($"http://api.openweathermap.org/data/2.5/{endpoint}/{query});

darkcloud784 avatar Mar 14 '22 16:03 darkcloud784

I would like to work on this, once my current PR has been merged/closed. Just adding the endpoint string into the url wouldn't work because the daily forecast returns an array (I think).

Instead, I would suggest adding entirely new functions for the different endpoints, using a naming scheme like QueryAsync{EndpointType}, where EndpointType would for example be Daily, resulting in the name QueryAsyncDaily. This would also retain support for legacy codebases by leaving QueryAsync and Query alone.

Optionally, QueryAsyncCurrent could be added to improve code readability for anyone using the library. This would either use the same code as QueryAsync, or directly call QueryAsync. To encourage using the new naming scheme, QueryAsync could be marked as deprecated.

drenkmann avatar Feb 10 '23 15:02 drenkmann

So after working on this all day, I have realized that the daily endpoint requires a paid subscription (which I don't have), so I'm afraid that someone who does own a paid API key will have to work on this. Alternatively, it would be possible to integrate the new Open Weather Map API V3, but that would require almost the entire library to be rewritten.

drenkmann avatar Feb 13 '23 19:02 drenkmann