1
1
# Tzeva Adom API
2
- Async Java API that listens to ` Pikud Ha'oref ` and notifies registered listeners as soon as a Tzeva Adom happens.
2
+ Async Java API that listens to ` Pikud Ha'oref ` and notifies registered listeners as soon as a Tzeva Adom happens.\
3
+ Integrating it in projects(games, etc) used by many israelis, ** increases** the chances of saving lives.
3
4
4
5
## How to use
5
- Let's create a notifier that stops a game when it's Tzeva Adom :
6
+ Let's create a notifier that is responsible of stopping your addicting game :
6
7
``` java
7
8
Game game = ... ;
8
9
9
10
TzevaAdomNotifier notifier = new TzevaAdomNotifier .Builder ()
10
- .every(Duration . ofSeconds(3 ))
11
11
.onFailedRequest(exception - > LOGGER . error(" Failed to request the last alert from Pikud Ha'oref" , exception))
12
12
.onTzevaAdom(alert - >
13
13
{
14
14
game. stop();
15
- game. sendMessage(" There is a Tzeva Adom in: " + alert. getCity ());
15
+ game. sendMessage(" There is a Tzeva Adom in: " + alert. getRegion ());
16
16
})
17
17
.build();
18
18
19
19
notifier. listen(); // async
20
20
```
21
-
22
- By saving the notifier object, you can gather information while your program is running.\
23
- Here is an example:
21
+ \
22
+ By saving the notifier object, you can gather information while your program is running:
24
23
``` java
25
- notifier. listen();
24
+ notifier. listen(); // async - anything else is sync
26
25
27
26
// sleep for a day
28
27
TimeUnit . DAYS. sleep(1 );
29
28
30
- Set<Alert > history = notifier. getHistory();
31
-
32
- LOGGER . info(" There were {} alerts in the last 24 hours:" , history. size());
33
-
34
- for (Alert alert : history)
29
+ // print all the alerts from the last day
30
+ for (Alert alert : notifier. getHistory())
35
31
{
36
- LOGGER . info (" Alert in {} at {}" , alert. getCity(), alert. getDate());
32
+ LOGGER . warn (" Alert at {} was in {}" , alert. getCity(), alert. getDate());
37
33
}
34
+
35
+ // check a specific city's alerts
36
+ List<Alert > telAvivAlerts = notifier. getHistory(). ofRegion(" תל אביב" );
38
37
```
39
38
40
39
## How to import
@@ -50,15 +49,21 @@ Maven Repository:
50
49
<dependency >
51
50
<groupId >com.github.DavidTheExplorer</groupId >
52
51
<artifactId >Tzeva-Adom-API</artifactId >
53
- <version >1.4 .0</version >
52
+ <version >1.5 .0</version >
54
53
</dependency >
55
54
```
56
55
57
56
58
- ## Customization
59
- Relevant if the endpoint of Pikud Ha'oref was changed or your alerts come from somewhere else.\
60
- \
61
- Either implement ` AlertSource ` or extend ` JSONAlertSource ` for JSON APIs, and then create your notifier like this:
62
- ``` java
63
- new TzevaAdomNotifier .Builder ()
64
- .requestFrom(new YourAlertSource ())
57
+ ## Builder Options
58
+ Everything in the library is customizable.
59
+ - If the endpoint of Pikud Ha'oref was changed or your alerts come from somewhere else:\
60
+ Implement ` AlertSource ` and then create your notifier like this:
61
+ ``` java
62
+ new TzevaAdomNotifier .Builder ()
63
+ .requestFrom(new YourAlertSource ())
64
+ ```
65
+ - If you want to lower the frequency of the Tzeva Adom checks, create your notifier like this:
66
+ ``` java
67
+ new TzevaAdomNotifier .Builder ()
68
+ .requestEvery(Duration . ofSeconds(3 ))
69
+ ```
0 commit comments