001package com.plivo.api.models.call;
002
003import com.plivo.api.exceptions.PlivoRestException;
004import com.plivo.api.models.base.VoiceUpdater;
005import com.plivo.api.exceptions.PlivoValidationException;
006import com.plivo.api.util.Utils;
007import java.io.IOException;
008import retrofit2.Call;
009
010public class CallUpdater extends VoiceUpdater<CallUpdateResponse> {
011
012  LegSpecifier legs;
013  String alegUrl;
014  String alegMethod;
015  String blegUrl;
016  String blegMethod;
017
018  public CallUpdater(String id) {
019    super(id);
020  }
021
022  public LegSpecifier legs() {
023    return this.legs;
024  }
025
026  public String alegUrl() {
027    return this.alegUrl;
028  }
029
030  public String alegMethod() {
031    return this.alegMethod;
032  }
033
034  public String blegUrl() {
035    return this.blegUrl;
036  }
037
038  public String blegMethod() {
039    return this.blegMethod;
040  }
041
042  /**
043   * @param legs Which leg to transfer.
044   */
045  public CallUpdater legs(final LegSpecifier legs) {
046    this.legs = legs;
047    return this;
048  }
049
050  /**
051   * @param alegUrl URL to transfer for aleg, if legs is aleg or both, then aleg_url has to be
052   * specified.
053   */
054  public CallUpdater alegUrl(final String alegUrl) {
055    this.alegUrl = alegUrl;
056    return this;
057  }
058
059  /**
060   * @param alegMethod HTTP method to invoke aleg_url. Defaults to POST.
061   */
062  public CallUpdater alegMethod(final String alegMethod) {
063    this.alegMethod = alegMethod;
064    return this;
065  }
066
067  /**
068   * @param blegUrl URL to transfer for bridged leg, if legs is bleg or both, then bleg_url has to
069   * be specified.
070   */
071  public CallUpdater blegUrl(final String blegUrl) {
072    this.blegUrl = blegUrl;
073    return this;
074  }
075
076  /**
077   * @param blegMethod HTTP method to invoke bleg_url. Defaults to POST.
078   */
079  public CallUpdater blegMethod(final String blegMethod) {
080    this.blegMethod = blegMethod;
081    return this;
082  }
083
084  @Override
085  protected void validate() {
086    super.validate();
087
088    if (!Utils.anyNotNull(alegMethod, alegUrl, blegMethod, blegUrl, legs)) {
089      throw new IllegalStateException("at least one param should be non null");
090    }
091  }
092
093  @Override
094  protected Call<CallUpdateResponse> obtainCall() {
095    return client().getVoiceApiService().callUpdate(client().getAuthId(), id, this);
096  }
097
098  @Override
099  protected Call<CallUpdateResponse> obtainFallback1Call() {
100    return client().getVoiceFallback1Service().callUpdate(client().getAuthId(), id, this);
101  }
102
103  @Override
104  protected Call<CallUpdateResponse> obtainFallback2Call() {
105    return client().getVoiceFallback2Service().callUpdate(client().getAuthId(), id, this);
106  }
107
108  public CallUpdateResponse transfer() throws IOException, PlivoRestException, PlivoValidationException {
109    return update();
110  }
111}