com.twilio.rest.wireless.v1.SimUpdater Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-thirdparty.twilio
Show all versions of common-thirdparty.twilio
The parent for all OSGi wrapped third party libraries
/**
* This code was generated by
* \ / _ _ _| _ _
* | (_)\/(_)(_|\/| |(/_ v1.0.0
* / /
*/
package com.twilio.rest.wireless.v1;
import com.twilio.base.Updater;
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 SimUpdater extends Updater {
private final String pathSid;
private String uniqueName;
private HttpMethod callbackMethod;
private URI callbackUrl;
private String friendlyName;
private String ratePlan;
private Sim.Status status;
private HttpMethod commandsCallbackMethod;
private URI commandsCallbackUrl;
private HttpMethod smsFallbackMethod;
private URI smsFallbackUrl;
private HttpMethod smsMethod;
private URI smsUrl;
private HttpMethod voiceFallbackMethod;
private URI voiceFallbackUrl;
private HttpMethod voiceMethod;
private URI voiceUrl;
/**
* Construct a new SimUpdater.
*
* @param pathSid A 34 character string that uniquely identifies this resource.
*/
public SimUpdater(final String pathSid) {
this.pathSid = pathSid;
}
/**
* A user-provided string that uniquely identifies this resource as an
* alternative to the `Sid`..
*
* @param uniqueName A user-provided string that uniquely identifies this
* resource as an alternative to the Sid.
* @return this
*/
public SimUpdater setUniqueName(final String uniqueName) {
this.uniqueName = uniqueName;
return this;
}
/**
* The HTTP method Twilio will use when making a request to the callback URL
* (valid options are GET or POST). Defaults to POST..
*
* @param callbackMethod The HTTP method Twilio will use when making a request
* to the callback URL.
* @return this
*/
public SimUpdater setCallbackMethod(final HttpMethod callbackMethod) {
this.callbackMethod = callbackMethod;
return this;
}
/**
* Twilio will make a request to this URL when the Sim has finished updating. In
* the case of a transition from the Sim's `new` status to its `ready` status,
* or from any status to its `deactivated` status, you will receive two
* callbacks. One when the Sim moves to its intermediary status (`ready` or
* `deactivated`), and a second when it transitions to its final status
* (`active` or `canceled`)..
*
* @param callbackUrl Twilio will make a request to this URL when the Sim has
* finished updating.
* @return this
*/
public SimUpdater setCallbackUrl(final URI callbackUrl) {
this.callbackUrl = callbackUrl;
return this;
}
/**
* Twilio will make a request to this URL when the Sim has finished updating. In
* the case of a transition from the Sim's `new` status to its `ready` status,
* or from any status to its `deactivated` status, you will receive two
* callbacks. One when the Sim moves to its intermediary status (`ready` or
* `deactivated`), and a second when it transitions to its final status
* (`active` or `canceled`)..
*
* @param callbackUrl Twilio will make a request to this URL when the Sim has
* finished updating.
* @return this
*/
public SimUpdater setCallbackUrl(final String callbackUrl) {
return setCallbackUrl(Promoter.uriFromString(callbackUrl));
}
/**
* A user-provided string that identifies this resource. Non-unique..
*
* @param friendlyName A user-provided string that identifies this resource.
* @return this
*/
public SimUpdater setFriendlyName(final String friendlyName) {
this.friendlyName = friendlyName;
return this;
}
/**
* The Sid or UniqueName of the
* [RatePlan](https://www.twilio.com/docs/api/wireless/rest-api/rate-plan) that
* this Sim should use. *Note:* the RatePlan of a Sim can only be modified when
* the Sim has a `suspended` or `deactivated` status..
*
* @param ratePlan The Sid or UniqueName of the RatePlan that this Sim should
* use.
* @return this
*/
public SimUpdater setRatePlan(final String ratePlan) {
this.ratePlan = ratePlan;
return this;
}
/**
* A string representing the status of the Sim. Valid options depend on the
* current state of the Sim, but may include `ready`, `active`, `suspended` or
* `deactivated`..
*
* @param status A string representing the status of the Sim.
* @return this
*/
public SimUpdater setStatus(final Sim.Status status) {
this.status = status;
return this;
}
/**
* A string representing the HTTP method to use when making a request to
* `CommandsCallbackUrl`. Can be one of `POST` or `GET`. Defaults to `POST`..
*
* @param commandsCallbackMethod A string representing the HTTP method to use
* when making a request to CommandsCallbackUrl.
* @return this
*/
public SimUpdater setCommandsCallbackMethod(final HttpMethod commandsCallbackMethod) {
this.commandsCallbackMethod = commandsCallbackMethod;
return this;
}
/**
* The URL that will receive a webhook when this Sim originates a
* [Command](https://www.twilio.com/docs/api/wireless/rest-api/command). Your
* server should respond with an HTTP status code in the 200 range; any response
* body will be ignored..
*
* @param commandsCallbackUrl The URL that will receive a webhook when this Sim
* originates a Command.
* @return this
*/
public SimUpdater setCommandsCallbackUrl(final URI commandsCallbackUrl) {
this.commandsCallbackUrl = commandsCallbackUrl;
return this;
}
/**
* The URL that will receive a webhook when this Sim originates a
* [Command](https://www.twilio.com/docs/api/wireless/rest-api/command). Your
* server should respond with an HTTP status code in the 200 range; any response
* body will be ignored..
*
* @param commandsCallbackUrl The URL that will receive a webhook when this Sim
* originates a Command.
* @return this
*/
public SimUpdater setCommandsCallbackUrl(final String commandsCallbackUrl) {
return setCommandsCallbackUrl(Promoter.uriFromString(commandsCallbackUrl));
}
/**
* The HTTP method Twilio will use when requesting the sms_fallback_url. Either
* `GET` or `POST`..
*
* @param smsFallbackMethod The HTTP method Twilio will use when requesting the
* sms_fallback_url.
* @return this
*/
public SimUpdater setSmsFallbackMethod(final HttpMethod smsFallbackMethod) {
this.smsFallbackMethod = smsFallbackMethod;
return this;
}
/**
* The URL that Twilio will request if an error occurs retrieving or executing
* the TwiML requested by `sms_url`..
*
* @param smsFallbackUrl The URL that Twilio will request if an error occurs
* retrieving or executing the TwiML requested by sms_url.
* @return this
*/
public SimUpdater setSmsFallbackUrl(final URI smsFallbackUrl) {
this.smsFallbackUrl = smsFallbackUrl;
return this;
}
/**
* The URL that Twilio will request if an error occurs retrieving or executing
* the TwiML requested by `sms_url`..
*
* @param smsFallbackUrl The URL that Twilio will request if an error occurs
* retrieving or executing the TwiML requested by sms_url.
* @return this
*/
public SimUpdater setSmsFallbackUrl(final String smsFallbackUrl) {
return setSmsFallbackUrl(Promoter.uriFromString(smsFallbackUrl));
}
/**
* The HTTP method Twilio will use when requesting the above Url. Either `GET`
* or `POST`..
*
* @param smsMethod The HTTP method Twilio will use when requesting the above
* Url.
* @return this
*/
public SimUpdater setSmsMethod(final HttpMethod smsMethod) {
this.smsMethod = smsMethod;
return this;
}
/**
* The URL Twilio will request when the SIM-connected device sends an SMS
* message that is not a
* [Command](https://www.twilio.com/docs/api/wireless/rest-api/command)..
*
* @param smsUrl The URL Twilio will request when the SIM-connected device
* sends an SMS message that is not a Command.
* @return this
*/
public SimUpdater setSmsUrl(final URI smsUrl) {
this.smsUrl = smsUrl;
return this;
}
/**
* The URL Twilio will request when the SIM-connected device sends an SMS
* message that is not a
* [Command](https://www.twilio.com/docs/api/wireless/rest-api/command)..
*
* @param smsUrl The URL Twilio will request when the SIM-connected device
* sends an SMS message that is not a Command.
* @return this
*/
public SimUpdater setSmsUrl(final String smsUrl) {
return setSmsUrl(Promoter.uriFromString(smsUrl));
}
/**
* The HTTP method Twilio will use when requesting the voice_fallback_url.
* Either `GET` or `POST`..
*
* @param voiceFallbackMethod The HTTP method Twilio will use when requesting
* the voice_fallback_url.
* @return this
*/
public SimUpdater setVoiceFallbackMethod(final HttpMethod voiceFallbackMethod) {
this.voiceFallbackMethod = voiceFallbackMethod;
return this;
}
/**
* The URL that Twilio will request if an error occurs retrieving or executing
* the TwiML requested by `voice_url`..
*
* @param voiceFallbackUrl The URL that Twilio will request if an error occurs
* retrieving or executing the TwiML requested by
* voice_url.
* @return this
*/
public SimUpdater setVoiceFallbackUrl(final URI voiceFallbackUrl) {
this.voiceFallbackUrl = voiceFallbackUrl;
return this;
}
/**
* The URL that Twilio will request if an error occurs retrieving or executing
* the TwiML requested by `voice_url`..
*
* @param voiceFallbackUrl The URL that Twilio will request if an error occurs
* retrieving or executing the TwiML requested by
* voice_url.
* @return this
*/
public SimUpdater setVoiceFallbackUrl(final String voiceFallbackUrl) {
return setVoiceFallbackUrl(Promoter.uriFromString(voiceFallbackUrl));
}
/**
* The HTTP method Twilio will use when requesting the above Url. Either `GET`
* or `POST`..
*
* @param voiceMethod The HTTP method Twilio will use when requesting the above
* Url.
* @return this
*/
public SimUpdater setVoiceMethod(final HttpMethod voiceMethod) {
this.voiceMethod = voiceMethod;
return this;
}
/**
* The URL Twilio will request when the SIM-connected device makes a call..
*
* @param voiceUrl The URL Twilio will request when the SIM-connected device
* makes a call.
* @return this
*/
public SimUpdater setVoiceUrl(final URI voiceUrl) {
this.voiceUrl = voiceUrl;
return this;
}
/**
* The URL Twilio will request when the SIM-connected device makes a call..
*
* @param voiceUrl The URL Twilio will request when the SIM-connected device
* makes a call.
* @return this
*/
public SimUpdater setVoiceUrl(final String voiceUrl) {
return setVoiceUrl(Promoter.uriFromString(voiceUrl));
}
/**
* Make the request to the Twilio API to perform the update.
*
* @param client TwilioRestClient with which to make the request
* @return Updated Sim
*/
@Override
@SuppressWarnings("checkstyle:linelength")
public Sim update(final TwilioRestClient client) {
Request request = new Request(
HttpMethod.POST,
Domains.WIRELESS.toString(),
"/v1/Sims/" + this.pathSid + "",
client.getRegion()
);
addPostParams(request);
Response response = client.request(request);
if (response == null) {
throw new ApiConnectionException("Sim update 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 Sim.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 (uniqueName != null) {
request.addPostParam("UniqueName", uniqueName);
}
if (callbackMethod != null) {
request.addPostParam("CallbackMethod", callbackMethod.toString());
}
if (callbackUrl != null) {
request.addPostParam("CallbackUrl", callbackUrl.toString());
}
if (friendlyName != null) {
request.addPostParam("FriendlyName", friendlyName);
}
if (ratePlan != null) {
request.addPostParam("RatePlan", ratePlan.toString());
}
if (status != null) {
request.addPostParam("Status", status.toString());
}
if (commandsCallbackMethod != null) {
request.addPostParam("CommandsCallbackMethod", commandsCallbackMethod.toString());
}
if (commandsCallbackUrl != null) {
request.addPostParam("CommandsCallbackUrl", commandsCallbackUrl.toString());
}
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 (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());
}
}
}