001package com.plivo.api.models.base; 002 003import com.plivo.api.PlivoClient; 004import com.plivo.api.exceptions.PlivoValidationException; 005import com.plivo.api.exceptions.PlivoRestException; 006import java.io.IOException; 007import okhttp3.ResponseBody; 008import retrofit2.Call; 009import retrofit2.Response; 010 011/** 012 * Deletes an instance of a resource. 013 * 014 * @param <T> The type of the resource. 015 */ 016public abstract class MessagingDeleter<T extends BaseResource> extends BaseRequest { 017 018 protected String id; 019 protected String secondaryId; 020 021 public MessagingDeleter(String id) { 022 this.id = id; 023 024 if (id == null) { 025 throw new IllegalArgumentException("id cannot be null"); 026 } 027 } 028 029 public MessagingDeleter(String id, String secondaryId) { 030 if (id == null || secondaryId == null) { 031 throw new IllegalArgumentException("id/secondaryId cannot be null"); 032 } 033 this.id = id; 034 this.secondaryId = secondaryId; 035 } 036 037 /** 038 * Actually delete the resource. 039 */ 040 public T delete() throws IOException, PlivoRestException, PlivoValidationException { 041 validate(); 042 Response<T> response = obtainCall().execute(); 043 044 handleResponse(response); 045 046 return response.body(); 047 } 048 @Override 049 public MessagingDeleter<T> client(final PlivoClient plivoClient) { 050 this.plivoClient = plivoClient; 051 return this; 052 } 053 054 055 protected abstract Call<T> obtainCall() throws PlivoValidationException; 056}