aboutsummaryrefslogtreecommitdiff
path: root/juick-notifications/src/main/java/com/juick/components/service
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2016-12-15 10:34:18 +0300
committerGravatar Vitaly Takmazov2016-12-16 10:52:35 +0300
commitc83e39441243b7db8293f1c161ee203faaf360ef (patch)
treeaa9ce18953e6f0fd69deeb47b69f1d0de8e2fe55 /juick-notifications/src/main/java/com/juick/components/service
parent9ac4c8209b9699e78d0d5cd0753e2fe8edbec559 (diff)
juick-notifications: RestService and GCM cleanup
Diffstat (limited to 'juick-notifications/src/main/java/com/juick/components/service')
-rw-r--r--juick-notifications/src/main/java/com/juick/components/service/BaseRestService.java18
-rw-r--r--juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java39
-rw-r--r--juick-notifications/src/main/java/com/juick/components/service/TokenService.java10
3 files changed, 67 insertions, 0 deletions
diff --git a/juick-notifications/src/main/java/com/juick/components/service/BaseRestService.java b/juick-notifications/src/main/java/com/juick/components/service/BaseRestService.java
new file mode 100644
index 00000000..d4bc369c
--- /dev/null
+++ b/juick-notifications/src/main/java/com/juick/components/service/BaseRestService.java
@@ -0,0 +1,18 @@
+package com.juick.components.service;
+
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * Created by vitalyster on 15.12.2016.
+ */
+public abstract class BaseRestService {
+ private RestTemplate rest;
+
+ public BaseRestService(RestTemplate rest) {
+ this.rest = rest;
+ }
+
+ public RestTemplate getRest() {
+ return rest;
+ }
+}
diff --git a/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java b/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java
new file mode 100644
index 00000000..c34f322b
--- /dev/null
+++ b/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java
@@ -0,0 +1,39 @@
+package com.juick.components.service;
+
+import com.juick.TokensList;
+import org.springframework.core.ParameterizedTypeReference;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.MediaType;
+import org.springframework.stereotype.Repository;
+import org.springframework.web.client.RestTemplate;
+
+import javax.inject.Inject;
+import java.util.List;
+
+/**
+ * Created by vitalyster on 15.12.2016.
+ */
+@Repository
+public class NotificationsTokenService extends BaseRestService implements TokenService {
+
+ @Inject
+ public NotificationsTokenService(RestTemplate rest) {
+ super(rest);
+ }
+
+ @Override
+ public void deleteTokens(String type, List<String> devices) {
+ if (devices.size() > 0) {
+ TokensList list = new TokensList();
+ list.setType(type);
+ list.setTokens(devices);
+ HttpHeaders headers = new HttpHeaders();
+ headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
+ getRest().exchange("http://api.juick.com/notifications",
+ HttpMethod.DELETE, new HttpEntity<>(list, headers), new ParameterizedTypeReference<Void>() {
+ });
+ }
+ }
+}
diff --git a/juick-notifications/src/main/java/com/juick/components/service/TokenService.java b/juick-notifications/src/main/java/com/juick/components/service/TokenService.java
new file mode 100644
index 00000000..2a578386
--- /dev/null
+++ b/juick-notifications/src/main/java/com/juick/components/service/TokenService.java
@@ -0,0 +1,10 @@
+package com.juick.components.service;
+
+import java.util.List;
+
+/**
+ * Created by vitalyster on 15.12.2016.
+ */
+public interface TokenService {
+ void deleteTokens(String type, List<String> list);
+}