coderhs / ruby_open_weather_map

A ruby wrapper for open weather map
MIT License
79 stars 52 forks source link

Raise error when exceeding city IDs limit of 20 #36

Closed JesseEmond closed 7 years ago

JesseEmond commented 7 years ago

As can be seen on the documentation for the 'several cities' call, there is now a limit on the list of city IDs requested at once :

The limit of locations is 20. NOTE: A single ID counts as a one API call! So, the above example is treated as a 3 API calls.

I encountered this error recently as it was working properly with 24 cities before (I guess they changed their behavior) and the API failed to find the list parameter in :

{"cod"=>"400", "message"=>"id list must be in range from 1 to 20"}

This PR should make the limitation more obvious to anyone else that encounters it.

I toyed with the idea of magically calling the openweather API in batches of 20 cities, but I think that would hide the fact that "A single ID counts as one API call", which is important to take into account. I also would have preferred to raise that error based on a specific return cod instead of hardcoding the 20 limit, but 400 is a bit too generic here... Having the constant in the API at least makes it easier for a user of this library to batch the calls.