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/** 012 * Creates an instance of a resource. 013 * 014 * @param <CreateResponse> The type of the response. 015 */ 016@JsonInclude(Include.NON_NULL) 017public abstract class Creator<CreateResponse extends BaseResponse> extends BaseRequest { 018 019 /** 020 * Actually create an instance of the resource. 021 */ 022 public CreateResponse create() throws IOException, PlivoRestException { 023 validate(); 024 Response<CreateResponse> response = obtainCall().execute(); 025 026 handleResponse(response); 027 028 return response.body(); 029 } 030 031 @Override 032 public Creator<CreateResponse> client(final PlivoClient plivoClient) { 033 this.plivoClient = plivoClient; 034 return this; 035 } 036 037 038 protected abstract Call<CreateResponse> obtainCall(); 039}