aboutsummaryrefslogtreecommitdiff
path: root/juick-notifications/src/main/java/com/juick/components/service/NotificationsTokenService.java
blob: 7b9a88a395a3cfeb981b630a90cf76c74e16d23d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.juick.components.service;

import com.juick.DeviceRegistration;
import com.juick.service.BaseRestService;
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.Service;
import org.springframework.web.client.RestTemplate;

import javax.inject.Inject;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by vitalyster on 15.12.2016.
 */
@Service
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) {
            List<DeviceRegistration> list = devices.stream()
                    .map(d -> new DeviceRegistration(type, d)).collect(Collectors.toList());
            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>() {
                    });
        }
    }
}