All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.twilio.rest.supersim.v1.FleetCreator Maven / Gradle / Ivy

There is a newer version: 10.1.5
Show newest version
/**
 * This code was generated by
 * \ / _    _  _|   _  _
 *  | (_)\/(_)(_|\/| |(/_  v1.0.0
 *       /       /
 */

package com.twilio.rest.supersim.v1;

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;

/**
 * PLEASE NOTE that this class contains preview products that are subject to
 * change. Use them with caution. If you currently do not have developer preview
 * access, please contact [email protected].
 */
public class FleetCreator extends Creator {
    private final String networkAccessProfile;
    private String uniqueName;
    private Boolean dataEnabled;
    private Integer dataLimit;
    private Boolean commandsEnabled;
    private URI commandsUrl;
    private HttpMethod commandsMethod;

    /**
     * Construct a new FleetCreator.
     *
     * @param networkAccessProfile The SID or unique name of the Network Access
     *                             Profile of the Fleet
     */
    public FleetCreator(final String networkAccessProfile) {
        this.networkAccessProfile = networkAccessProfile;
    }

    /**
     * An application-defined string that uniquely identifies the resource. It can
     * be used in place of the resource's `sid` in the URL to address the resource..
     *
     * @param uniqueName An application-defined string that uniquely identifies the
     *                   resource
     * @return this
     */
    public FleetCreator setUniqueName(final String uniqueName) {
        this.uniqueName = uniqueName;
        return this;
    }

    /**
     * Defines whether SIMs in the Fleet are capable of using 2G/3G/4G/LTE/CAT-M
     * data connectivity. Defaults to `true`..
     *
     * @param dataEnabled Defines whether SIMs in the Fleet are capable of using
     *                    data connectivity
     * @return this
     */
    public FleetCreator setDataEnabled(final Boolean dataEnabled) {
        this.dataEnabled = dataEnabled;
        return this;
    }

    /**
     * The total data usage (download and upload combined) in Megabytes that each
     * Sim resource assigned to the Fleet resource can consume during a billing
     * period (normally one month). Value must be between 1MB (1) and 2TB
     * (2,000,000). Defaults to 1GB (1,000)..
     *
     * @param dataLimit The total data usage (download and upload combined) in
     *                  Megabytes that each Sim resource assigned to the Fleet
     *                  resource can consume
     * @return this
     */
    public FleetCreator setDataLimit(final Integer dataLimit) {
        this.dataLimit = dataLimit;
        return this;
    }

    /**
     * Defines whether SIMs in the Fleet are capable of sending and receiving
     * machine-to-machine SMS via Commands. Defaults to `true`..
     *
     * @param commandsEnabled Defines whether SIMs in the Fleet are capable of
     *                        sending and receiving machine-to-machine SMS via
     *                        Commands
     * @return this
     */
    public FleetCreator setCommandsEnabled(final Boolean commandsEnabled) {
        this.commandsEnabled = commandsEnabled;
        return this;
    }

    /**
     * The URL that will receive a webhook when a SIM in the Fleet originates a
     * machine-to-machine SMS via Commands. Your server should respond with an HTTP
     * status code in the 200 range; any response body will be ignored..
     *
     * @param commandsUrl The URL that will receive a webhook when a SIM in the
     *                    Fleet originates a machine-to-machine SMS via Commands
     * @return this
     */
    public FleetCreator setCommandsUrl(final URI commandsUrl) {
        this.commandsUrl = commandsUrl;
        return this;
    }

    /**
     * The URL that will receive a webhook when a SIM in the Fleet originates a
     * machine-to-machine SMS via Commands. Your server should respond with an HTTP
     * status code in the 200 range; any response body will be ignored..
     *
     * @param commandsUrl The URL that will receive a webhook when a SIM in the
     *                    Fleet originates a machine-to-machine SMS via Commands
     * @return this
     */
    public FleetCreator setCommandsUrl(final String commandsUrl) {
        return setCommandsUrl(Promoter.uriFromString(commandsUrl));
    }

    /**
     * A string representing the HTTP method to use when making a request to
     * `commands_url`. Can be one of `POST` or `GET`. Defaults to `POST`..
     *
     * @param commandsMethod A string representing the HTTP method to use when
     *                       making a request to `commands_url`
     * @return this
     */
    public FleetCreator setCommandsMethod(final HttpMethod commandsMethod) {
        this.commandsMethod = commandsMethod;
        return this;
    }

    /**
     * Make the request to the Twilio API to perform the create.
     *
     * @param client TwilioRestClient with which to make the request
     * @return Created Fleet
     */
    @Override
    @SuppressWarnings("checkstyle:linelength")
    public Fleet create(final TwilioRestClient client) {
        Request request = new Request(
            HttpMethod.POST,
            Domains.SUPERSIM.toString(),
            "/v1/Fleets"
        );

        addPostParams(request);
        Response response = client.request(request);

        if (response == null) {
            throw new ApiConnectionException("Fleet creation failed: Unable to connect to server");
        } else if (!TwilioRestClient.SUCCESS.test(response.getStatusCode())) {
            RestException restException = RestException.fromJson(response.getStream(), client.getObjectMapper());
            if (restException == null) {
                throw new ApiException("Server Error, no content");
            }
            throw new ApiException(restException);
        }

        return Fleet.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 (networkAccessProfile != null) {
            request.addPostParam("NetworkAccessProfile", networkAccessProfile.toString());
        }

        if (uniqueName != null) {
            request.addPostParam("UniqueName", uniqueName);
        }

        if (dataEnabled != null) {
            request.addPostParam("DataEnabled", dataEnabled.toString());
        }

        if (dataLimit != null) {
            request.addPostParam("DataLimit", dataLimit.toString());
        }

        if (commandsEnabled != null) {
            request.addPostParam("CommandsEnabled", commandsEnabled.toString());
        }

        if (commandsUrl != null) {
            request.addPostParam("CommandsUrl", commandsUrl.toString());
        }

        if (commandsMethod != null) {
            request.addPostParam("CommandsMethod", commandsMethod.toString());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy