aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar/notificators
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/traccar/notificators')
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorFirebase.java18
-rw-r--r--src/main/java/org/traccar/notificators/NotificatorTraccar.java13
2 files changed, 25 insertions, 6 deletions
diff --git a/src/main/java/org/traccar/notificators/NotificatorFirebase.java b/src/main/java/org/traccar/notificators/NotificatorFirebase.java
index 75d325de2..8a3deee92 100644
--- a/src/main/java/org/traccar/notificators/NotificatorFirebase.java
+++ b/src/main/java/org/traccar/notificators/NotificatorFirebase.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2018 - 2020 Anton Tananaev (anton@traccar.org)
* Copyright 2018 Andrey Kunitsyn (andrey@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,9 +32,8 @@ public class NotificatorFirebase extends Notificator {
private static final Logger LOGGER = LoggerFactory.getLogger(NotificatorFirebase.class);
- private static final String URL = "https://fcm.googleapis.com/fcm/send";
-
- private String key;
+ private final String url;
+ private final String key;
public static class Notification {
@JsonProperty("body")
@@ -49,7 +48,14 @@ public class NotificatorFirebase extends Notificator {
}
public NotificatorFirebase() {
- key = Context.getConfig().getString("notificator.firebase.key");
+ this(
+ "https://fcm.googleapis.com/fcm/send",
+ Context.getConfig().getString("notificator.firebase.key"));
+ }
+
+ protected NotificatorFirebase(String url, String key) {
+ this.url = url;
+ this.key = key;
}
@Override
@@ -64,7 +70,7 @@ public class NotificatorFirebase extends Notificator {
message.tokens = user.getString("notificationTokens").split("[, ]");
message.notification = notification;
- Context.getClient().target(URL).request()
+ Context.getClient().target(url).request()
.header("Authorization", "key=" + key)
.async().post(Entity.json(message), new InvocationCallback<Object>() {
@Override
diff --git a/src/main/java/org/traccar/notificators/NotificatorTraccar.java b/src/main/java/org/traccar/notificators/NotificatorTraccar.java
new file mode 100644
index 000000000..2b75d60e4
--- /dev/null
+++ b/src/main/java/org/traccar/notificators/NotificatorTraccar.java
@@ -0,0 +1,13 @@
+package org.traccar.notificators;
+
+import org.traccar.Context;
+
+public class NotificatorTraccar extends NotificatorFirebase {
+
+ public NotificatorTraccar() {
+ super(
+ "https://www.traccar.org/push/",
+ Context.getConfig().getString("notificator.traccar.key"));
+ }
+
+}