/**
* This code was generated by
* \ / _ _ _| _ _
* | (_)\/(_)(_|\/| |(/_ v1.0.0
* / /
*/
package com.twilio.rest.api.v2010.account.incomingphonenumber;
import com.twilio.base.Creator;
import com.twilio.converter.Promoter;
import com.twilio.exception.ApiConnectionException;
import com.twilio.exception.ApiException;
import com.twilio.exception.RestException;
import com.twilio.http.HttpMethod;
import com.twilio.http.Request;
import com.twilio.http.Response;
import com.twilio.http.TwilioRestClient;
import com.twilio.rest.Domains;
import java.net.URI;
public class TollFreeCreator extends Creator<TollFree> {
private String pathAccountSid;
private final com.twilio.type.PhoneNumber phoneNumber;
private String apiVersion;
private String friendlyName;
private String smsApplicationSid;
private HttpMethod smsFallbackMethod;
private URI smsFallbackUrl;
private HttpMethod smsMethod;
private URI smsUrl;
private URI statusCallback;
private HttpMethod statusCallbackMethod;
private String voiceApplicationSid;
private Boolean voiceCallerIdLookup;
private HttpMethod voiceFallbackMethod;
private URI voiceFallbackUrl;
private HttpMethod voiceMethod;
private URI voiceUrl;
/**
* Construct a new TollFreeCreator.
*
* @param phoneNumber The phone_number
*/
public TollFreeCreator(final com.twilio.type.PhoneNumber phoneNumber) {
this.phoneNumber = phoneNumber;
}
/**
* Construct a new TollFreeCreator.
*
* @param pathAccountSid The account_sid
* @param phoneNumber The phone_number
*/
public TollFreeCreator(final String pathAccountSid,
final com.twilio.type.PhoneNumber phoneNumber) {
this.pathAccountSid = pathAccountSid;
this.phoneNumber = phoneNumber;
}
/**
* The api_version.
*
* @param apiVersion The api_version
* @return this
*/
public TollFreeCreator setApiVersion(final String apiVersion) {
this.apiVersion = apiVersion;
return this;
}
/**
* The friendly_name.
*
* @param friendlyName The friendly_name
* @return this
*/
public TollFreeCreator setFriendlyName(final String friendlyName) {
this.friendlyName = friendlyName;
return this;
}
/**
* The sms_application_sid.
*
* @param smsApplicationSid The sms_application_sid
* @return this
*/
public TollFreeCreator setSmsApplicationSid(final String smsApplicationSid) {
this.smsApplicationSid = smsApplicationSid;
return this;
}
/**
* The sms_fallback_method.
*
* @param smsFallbackMethod The sms_fallback_method
* @return this
*/
public TollFreeCreator setSmsFallbackMethod(final HttpMethod smsFallbackMethod) {
this.smsFallbackMethod = smsFallbackMethod;
return this;
}
/**
* The sms_fallback_url.
*
* @param smsFallbackUrl The sms_fallback_url
* @return this
*/
public TollFreeCreator setSmsFallbackUrl(final URI smsFallbackUrl) {
this.smsFallbackUrl = smsFallbackUrl;
return this;
}
/**
* The sms_fallback_url.
*
* @param smsFallbackUrl The sms_fallback_url
* @return this
*/
public TollFreeCreator setSmsFallbackUrl(final String smsFallbackUrl) {
return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl));
}
/**
* The sms_method.
*
* @param smsMethod The sms_method
* @return this
*/
public TollFreeCreator setSmsMethod(final HttpMethod smsMethod) {
this.smsMethod = smsMethod;
return this;
}
/**
* The sms_url.
*
* @param smsUrl The sms_url
* @return this
*/
public TollFreeCreator setSmsUrl(final URI smsUrl) {
this.smsUrl = smsUrl;
return this;
}
/**
* The sms_url.
*
* @param smsUrl The sms_url
* @return this
*/
public TollFreeCreator setSmsUrl(final String smsUrl) {
return setSmsUrl(Promoter.uriFromString(smsUrl));
}
/**
* The status_callback.
*
* @param statusCallback The status_callback
* @return this
*/
public TollFreeCreator setStatusCallback(final URI statusCallback) {
this.statusCallback = statusCallback;
return this;
}
/**
* The status_callback.
*
* @param statusCallback The status_callback
* @return this
*/
public TollFreeCreator setStatusCallback(final String statusCallback) {
return setStatusCallback(Promoter.uriFromString(statusCallback));
}
/**
* The status_callback_method.
*
* @param statusCallbackMethod The status_callback_method
* @return this
*/
public TollFreeCreator setStatusCallbackMethod(final HttpMethod statusCallbackMethod) {
this.statusCallbackMethod = statusCallbackMethod;
return this;
}
/**
* The voice_application_sid.
*
* @param voiceApplicationSid The voice_application_sid
* @return this
*/
public TollFreeCreator setVoiceApplicationSid(final String voiceApplicationSid) {
this.voiceApplicationSid = voiceApplicationSid;
return this;
}
/**
* The voice_caller_id_lookup.
*
* @param voiceCallerIdLookup The voice_caller_id_lookup
* @return this
*/
public TollFreeCreator setVoiceCallerIdLookup(final Boolean voiceCallerIdLookup) {
this.voiceCallerIdLookup = voiceCallerIdLookup;
return this;
}
/**
* The voice_fallback_method.
*
* @param voiceFallbackMethod The voice_fallback_method
* @return this
*/
public TollFreeCreator setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod) {
this.voiceFallbackMethod = voiceFallbackMethod;
return this;
}
/**
* The voice_fallback_url.
*
* @param voiceFallbackUrl The voice_fallback_url
* @return this
*/
public TollFreeCreator setVoiceFallbackUrl(final URI voiceFallbackUrl) {
this.voiceFallbackUrl = voiceFallbackUrl;
return this;
}
/**
* The voice_fallback_url.
*
* @param voiceFallbackUrl The voice_fallback_url
* @return this
*/
public TollFreeCreator setVoiceFallbackUrl(final String voiceFallbackUrl) {
return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl));
}
/**
* The voice_method.
*
* @param voiceMethod The voice_method
* @return this
*/
public TollFreeCreator setVoiceMethod(final HttpMethod voiceMethod) {
this.voiceMethod = voiceMethod;
return this;
}
/**
* The voice_url.
*
* @param voiceUrl The voice_url
* @return this
*/
public TollFreeCreator setVoiceUrl(final URI voiceUrl) {
this.voiceUrl = voiceUrl;
return this;
}
/**
* The voice_url.
*
* @param voiceUrl The voice_url
* @return this
*/
public TollFreeCreator setVoiceUrl(final String voiceUrl) {
return setVoiceUrl(Promoter.uriFromString(voiceUrl));
}
/**
* Make the request to the Twilio API to perform the create.
*
* @param client TwilioRestClient with which to make the request
* @return Created TollFree
*/
@Override
@SuppressWarnings("checkstyle:linelength")
public TollFree create(final TwilioRestClient client) {
this.pathAccountSid = this.pathAccountSid == null ? client.getAccountSid() : this.pathAccountSid;
Request request = new Request(
HttpMethod.POST,
Domains.API.toString(),
"/2010-04-01/Accounts/" + this.pathAccountSid + "/IncomingPhoneNumbers/TollFree.json",
client.getRegion()
);
addPostParams(request);
Response response = client.request(request);
if (response == null) {
throw new ApiConnectionException("TollFree creation failed: Unable to connect to server");
} else if (!TwilioRestClient.SUCCESS.apply(response.getStatusCode())) {
RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper());
if (restException == null) {
throw new ApiException("Server Error, no content");
}
throw new ApiException(
restException.getMessage(),
restException.getCode(),
restException.getMoreInfo(),
restException.getStatus(),
null
);
}
return TollFree.fromJson(response.getStream(), client.getObjectMapper());
}
/**
* Add the requested post parameters to the Request.
*
* @param request Request to add post params to
*/
private void addPostParams(final Request request) {
if (phoneNumber != null) {
request.addPostParam("PhoneNumber", phoneNumber.toString());
}
if (apiVersion != null) {
request.addPostParam("ApiVersion", apiVersion);
}
if (friendlyName != null) {
request.addPostParam("FriendlyName", friendlyName);
}
if (smsApplicationSid != null) {
request.addPostParam("SmsApplicationSid", smsApplicationSid);
}
if (smsFallbackMethod != null) {
request.addPostParam("SmsFallbackMethod", smsFallbackMethod.toString());
}
if (smsFallbackUrl != null) {
request.addPostParam("SmsFallbackUrl", smsFallbackUrl.toString());
}
if (smsMethod != null) {
request.addPostParam("SmsMethod", smsMethod.toString());
}
if (smsUrl != null) {
request.addPostParam("SmsUrl", smsUrl.toString());
}
if (statusCallback != null) {
request.addPostParam("StatusCallback", statusCallback.toString());
}
if (statusCallbackMethod != null) {
request.addPostParam("StatusCallbackMethod", statusCallbackMethod.toString());
}
if (voiceApplicationSid != null) {
request.addPostParam("VoiceApplicationSid", voiceApplicationSid);
}
if (voiceCallerIdLookup != null) {
request.addPostParam("VoiceCallerIdLookup", voiceCallerIdLookup.toString());
}
if (voiceFallbackMethod != null) {
request.addPostParam("VoiceFallbackMethod", voiceFallbackMethod.toString());
}
if (voiceFallbackUrl != null) {
request.addPostParam("VoiceFallbackUrl", voiceFallbackUrl.toString());
}
if (voiceMethod != null) {
request.addPostParam("VoiceMethod", voiceMethod.toString());
}
if (voiceUrl != null) {
request.addPostParam("VoiceUrl", voiceUrl.toString());
}
}
}