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 retrofit2.Call; 008import retrofit2.Response; 009 010import java.io.IOException; 011 012@JsonInclude(Include.NON_NULL) 013public abstract class Submitter<T extends BaseResponse> extends BaseRequest { 014 015 protected String id; 016 017 public Submitter(String id) { 018 this.id = id; 019 020 if (id == null) { 021 throw new IllegalArgumentException("id cannot be null"); 022 } 023 } 024 025 /** 026 * Actually update the resource. 027 */ 028 public T submit() throws IOException, PlivoRestException { 029 validate(); 030 Response<T> response = obtainCall().execute(); 031 handleResponse(response); 032 return response.body(); 033 } 034 035 @Override 036 public Submitter<T> client(final PlivoClient plivoClient) { 037 this.plivoClient = plivoClient; 038 return this; 039 } 040 041 042 protected abstract Call<T> obtainCall(); 043}