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 Deleter<T extends BaseResource> extends BaseRequest<T> { 017 018 protected String id; 019 protected String secondaryId; 020 021 public Deleter(String id) { 022 this.id = id; 023 024 if (id == null) { 025 throw new IllegalArgumentException("id cannot be null"); 026 } 027 } 028 029 public Deleter(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 void delete() throws IOException, PlivoRestException, PlivoValidationException { 041 validate(); 042 Response<ResponseBody> response = obtainCall().execute(); 043 044 handleResponse(response); 045 } 046 047 @Override 048 public Deleter<T> client(final PlivoClient plivoClient) { 049 this.plivoClient = plivoClient; 050 return this; 051 } 052 053 054 protected abstract Call<ResponseBody> obtainCall() throws PlivoValidationException; 055}