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