11# Tzeva Adom API
2- Simple Java API that listens to ` Pikud Haoref's API ` and notifies registered listeners once a Tzeva Adom takes place .
2+ Async Java API that listens to ` Pikud Ha'oref API ` and notifies registered listeners as soon as a Tzeva Adom happens .
33
44
55## How to use
6- Let's create a notifier object that logs a message when it's Tzeva Adom:
6+ Let's create a notifier that logs a message when it's Tzeva Adom:
77``` java
88TzevaAdomNotifier
99 .requestFromPikudHaoref()
1010 .every(Duration . ofSeconds(3 )) // amount of delay between requests
11- .onFailedRequest(exception - > LOGGER . error(" Failed to send a request to Pikud Ha'oref... " , exception))
11+ .onFailedRequest(exception - > LOGGER . error(" Failed to request the last alert from Pikud Ha'oref" , exception))
1212 .onTzevaAdom(alert - > LOGGER . info(" Tzeva Adom at: " + alert. getCity()))
13- .listen();
13+ .listen(); // async
1414```
1515
16- You can save the notifier object in order to add functionality or get data from it, by calling ` build() ` instead of ` listen() ` :
16+ You can save the notifier object by calling ` build() ` instead of ` listen() ` , in order to add functionality or get data from it :
1717``` java
1818TzevaAdomNotifier notifier = TzevaAdomNotifier
1919 // builder pattern goes here
@@ -22,14 +22,17 @@ TzevaAdomNotifier notifier = TzevaAdomNotifier
2222notifier. listen();
2323```
2424
25- Adding Listeners anytime:
25+ Add more listeners anytime:
2626``` java
2727notifier. addListener(alert - > ... );
2828```
2929
30- Retrieving the Tzeva Adom Alerts encountered while running:
30+ Retrieve the Tzeva Adom alerts encountered while running:
3131``` java
32+ // run the notifier async and sleep for a day
33+ notifier. run();
3234TimeUnit . DAYS. sleep(1 );
35+
3336LOGGER . info(" There were {} alerts in the last 24 hours:" , notifier. getHistory(). size());
3437
3538// Pro Tip: TzevaAdomNotifier implements Iterable!
0 commit comments