diff options
Diffstat (limited to 'juick-notifications/src/main/java/com/juick/components/service')
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 000000000..d4bc369cb --- /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 000000000..c34f322b2 --- /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 000000000..2a578386d --- /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); +} |