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