001package com.plivo.api.models.base; 002 003import com.fasterxml.jackson.annotation.JsonInclude; 004import com.fasterxml.jackson.annotation.JsonInclude.Include; 005import com.plivo.api.PlivoClient; 006import com.plivo.api.exceptions.PlivoRestException; 007import java.io.IOException; 008import retrofit2.Call; 009import retrofit2.Response; 010 011@JsonInclude(Include.NON_NULL) 012public abstract class Updater<T extends BaseResponse> extends BaseRequest { 013 014 protected String id; 015 016 public Updater(String id) { 017 this.id = id; 018 019 if (id == null) { 020 throw new IllegalArgumentException("id cannot be null"); 021 } 022 } 023 024 /** 025 * Actually update the resource. 026 */ 027 public T update() throws IOException, PlivoRestException { 028 validate(); 029 Response<T> response = obtainCall().execute(); 030 031 handleResponse(response); 032 033 return response.body(); 034 } 035 036 @Override 037 public Updater<T> client(final PlivoClient plivoClient) { 038 this.plivoClient = plivoClient; 039 return this; 040 } 041 042 043 protected abstract Call<T> obtainCall(); 044}