eladnava / pikud-haoref-api

A Node.js wrapper library for Pikud Haoref's unofficial rocket alert API.
Apache License 2.0
71 stars 11 forks source link

Format for the response #14

Closed shirser121 closed 2 years ago

shirser121 commented 2 years ago

Hi, I just want to start using this API, and I need to know what format I get when the alert return, is that JSON, or text

eladnava commented 2 years ago

Hi @shirser121, The response is a JSON array of strings, where each string is a city name:

["תל אביב - מזרח", "חיפה - כרמל ועיר תחתית", "עין גדי"]

Let me know if you have any additional questions.

shirser121 commented 2 years ago

Hi @shirser121, The response is a JSON array of strings, where each string is a city name:

["תל אביב - מזרח", "חיפה - כרמל ועיר תחתית", "עין גדי"]

Let me know if you have any additional questions.

Maybe we should add time for every alert. And I think its important to add the format to the documents

eladnava commented 2 years ago

Hi @shirser121, At the moment, pikud-haoref-api provides a wrapper around the Home Front Command's alerts.json API, taking care of things like strange encodings and BOMs.

To listen for rocket alerts, you must poll the API by repeatedly calling pikudHaoref.getActiveRocketAlertCities(), which will usually return an empty JSON array, until there is an active code red alert. As soon as the response changes from an empty JSON array to an array with city names, you can save the current time (new Date().getTime()).

Finally, the format is currently documented in the Usage section of the README as a comment above pikudHaoref.getActiveRocketAlertCities():

 // Example response: ["תל אביב - מזרח", "חיפה - כרמל ועיר תחתית", "עין גדי"]