com.pubnub.api.endpoints.push.RemoveAllPushChannelsForDevice Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pubnub Show documentation
Show all versions of pubnub Show documentation
PubNub is a cross-platform client-to-client (1:1 and 1:many) push service in the cloud, capable of
broadcasting real-time messages to millions of web and mobile clients simultaneously, in less than a quarter
second!
package com.pubnub.api.endpoints.push;
import com.pubnub.api.PubNub;
import com.pubnub.api.PubNubException;
import com.pubnub.api.builder.PubNubErrorBuilder;
import com.pubnub.api.endpoints.Endpoint;
import com.pubnub.api.enums.PNOperationType;
import com.pubnub.api.enums.PNPushType;
import com.pubnub.api.models.consumer.push.PNPushRemoveAllChannelsResult;
import lombok.Setter;
import lombok.experimental.Accessors;
import retrofit2.Call;
import retrofit2.Response;
import java.util.List;
import java.util.Map;
@Accessors(chain = true, fluent = true)
public class RemoveAllPushChannelsForDevice extends Endpoint, PNPushRemoveAllChannelsResult> {
@Setter
private PNPushType pushType;
@Setter
private String deviceId;
public RemoveAllPushChannelsForDevice(PubNub pubnub) {
super(pubnub);
}
@Override
protected void validateParams() throws PubNubException {
if (this.getPubnub().getConfiguration().getSubscribeKey() == null || this.getPubnub().getConfiguration().getSubscribeKey().isEmpty()) {
throw PubNubException.builder().pubnubError(PubNubErrorBuilder.PNERROBJ_SUBSCRIBE_KEY_MISSING).build();
}
if (pushType == null) {
throw PubNubException.builder().pubnubError(PubNubErrorBuilder.PNERROBJ_PUSH_TYPE_MISSING).build();
}
if (deviceId == null || deviceId.isEmpty()) {
throw PubNubException.builder().pubnubError(PubNubErrorBuilder.PNERROBJ_DEVICE_ID_MISSING).build();
}
}
@Override
protected Call> doWork(Map params) throws PubNubException {
params.put("type", pushType.name().toLowerCase());
PushService service = this.createRetrofit().create(PushService.class);
return service.removeAllChannelsForDevice(this.getPubnub().getConfiguration().getSubscribeKey(), deviceId, params);
}
@Override
protected PNPushRemoveAllChannelsResult createResponse(Response> input) throws PubNubException {
if (input.body() == null) {
throw PubNubException.builder().pubnubError(PubNubErrorBuilder.PNERROBJ_PARSING_ERROR).build();
}
return PNPushRemoveAllChannelsResult.builder().build();
}
protected int getConnectTimeout() {
return this.getPubnub().getConfiguration().getConnectTimeout();
}
protected int getRequestTimeout() {
return this.getPubnub().getConfiguration().getNonSubscribeRequestTimeout();
}
@Override
protected PNOperationType getOperationType() {
return null; // PNOperationType.PNPushNotificationModifiedChannelsOperations;
}
@Override
protected boolean isAuthRequired() {
return true;
}
}