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

com.twilio.rest.proxy.v1.service.Session Maven / Gradle / Ivy

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

package com.twilio.rest.proxy.v1.service;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.MoreObjects;
import com.twilio.base.Resource;
import com.twilio.converter.DateConverter;
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 org.joda.time.DateTime;

import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.Map;
import java.util.Objects;

/**
 * PLEASE NOTE that this class contains beta products that are subject to
 * change. Use them with caution.
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class Session extends Resource {
    private static final long serialVersionUID = 199644364043028L;

    public enum Status {
        OPEN("open"),
        IN_PROGRESS("in-progress"),
        CLOSED("closed"),
        FAILED("failed"),
        UNKNOWN("unknown");

        private final String value;

        private Status(final String value) {
            this.value = value;
        }

        public String toString() {
            return value;
        }

        /**
         * Generate a Status from a string.
         * @param value string value
         * @return generated Status
         */
        @JsonCreator
        public static Status forValue(final String value) {
            return Promoter.enumFromString(value, Status.values());
        }
    }

    public enum Mode {
        MESSAGE_ONLY("message-only"),
        VOICE_ONLY("voice-only"),
        VOICE_AND_MESSAGE("voice-and-message");

        private final String value;

        private Mode(final String value) {
            this.value = value;
        }

        public String toString() {
            return value;
        }

        /**
         * Generate a Mode from a string.
         * @param value string value
         * @return generated Mode
         */
        @JsonCreator
        public static Mode forValue(final String value) {
            return Promoter.enumFromString(value, Mode.values());
        }
    }

    /**
     * Create a SessionFetcher to execute fetch.
     *
     * @param pathServiceSid The SID of the Service to fetch the resource from
     * @param pathSid The unique string that identifies the resource
     * @return SessionFetcher capable of executing the fetch
     */
    public static SessionFetcher fetcher(final String pathServiceSid,
                                         final String pathSid) {
        return new SessionFetcher(pathServiceSid, pathSid);
    }

    /**
     * Create a SessionReader to execute read.
     *
     * @param pathServiceSid The SID of the Service to fetch the resource from
     * @return SessionReader capable of executing the read
     */
    public static SessionReader reader(final String pathServiceSid) {
        return new SessionReader(pathServiceSid);
    }

    /**
     * Create a SessionCreator to execute create.
     *
     * @param pathServiceSid The SID of the parent Service resource
     * @return SessionCreator capable of executing the create
     */
    public static SessionCreator creator(final String pathServiceSid) {
        return new SessionCreator(pathServiceSid);
    }

    /**
     * Create a SessionDeleter to execute delete.
     *
     * @param pathServiceSid The SID of the Service to delete the resource from
     * @param pathSid The unique string that identifies the resource
     * @return SessionDeleter capable of executing the delete
     */
    public static SessionDeleter deleter(final String pathServiceSid,
                                         final String pathSid) {
        return new SessionDeleter(pathServiceSid, pathSid);
    }

    /**
     * Create a SessionUpdater to execute update.
     *
     * @param pathServiceSid The SID of the Service to update the resource from
     * @param pathSid The unique string that identifies the resource
     * @return SessionUpdater capable of executing the update
     */
    public static SessionUpdater updater(final String pathServiceSid,
                                         final String pathSid) {
        return new SessionUpdater(pathServiceSid, pathSid);
    }

    /**
     * Converts a JSON String into a Session object using the provided ObjectMapper.
     *
     * @param json Raw JSON String
     * @param objectMapper Jackson ObjectMapper
     * @return Session object represented by the provided JSON
     */
    public static Session fromJson(final String json, final ObjectMapper objectMapper) {
        // Convert all checked exceptions to Runtime
        try {
            return objectMapper.readValue(json, Session.class);
        } catch (final JsonMappingException | JsonParseException e) {
            throw new ApiException(e.getMessage(), e);
        } catch (final IOException e) {
            throw new ApiConnectionException(e.getMessage(), e);
        }
    }

    /**
     * Converts a JSON InputStream into a Session object using the provided
     * ObjectMapper.
     *
     * @param json Raw JSON InputStream
     * @param objectMapper Jackson ObjectMapper
     * @return Session object represented by the provided JSON
     */
    public static Session fromJson(final InputStream json, final ObjectMapper objectMapper) {
        // Convert all checked exceptions to Runtime
        try {
            return objectMapper.readValue(json, Session.class);
        } catch (final JsonMappingException | JsonParseException e) {
            throw new ApiException(e.getMessage(), e);
        } catch (final IOException e) {
            throw new ApiConnectionException(e.getMessage(), e);
        }
    }

    private final String sid;
    private final String serviceSid;
    private final String accountSid;
    private final DateTime dateStarted;
    private final DateTime dateEnded;
    private final DateTime dateLastInteraction;
    private final DateTime dateExpiry;
    private final String uniqueName;
    private final Session.Status status;
    private final String closedReason;
    private final Integer ttl;
    private final Session.Mode mode;
    private final DateTime dateCreated;
    private final DateTime dateUpdated;
    private final URI url;
    private final Map links;

    @JsonCreator
    private Session(@JsonProperty("sid")
                    final String sid,
                    @JsonProperty("service_sid")
                    final String serviceSid,
                    @JsonProperty("account_sid")
                    final String accountSid,
                    @JsonProperty("date_started")
                    final String dateStarted,
                    @JsonProperty("date_ended")
                    final String dateEnded,
                    @JsonProperty("date_last_interaction")
                    final String dateLastInteraction,
                    @JsonProperty("date_expiry")
                    final String dateExpiry,
                    @JsonProperty("unique_name")
                    final String uniqueName,
                    @JsonProperty("status")
                    final Session.Status status,
                    @JsonProperty("closed_reason")
                    final String closedReason,
                    @JsonProperty("ttl")
                    final Integer ttl,
                    @JsonProperty("mode")
                    final Session.Mode mode,
                    @JsonProperty("date_created")
                    final String dateCreated,
                    @JsonProperty("date_updated")
                    final String dateUpdated,
                    @JsonProperty("url")
                    final URI url,
                    @JsonProperty("links")
                    final Map links) {
        this.sid = sid;
        this.serviceSid = serviceSid;
        this.accountSid = accountSid;
        this.dateStarted = DateConverter.iso8601DateTimeFromString(dateStarted);
        this.dateEnded = DateConverter.iso8601DateTimeFromString(dateEnded);
        this.dateLastInteraction = DateConverter.iso8601DateTimeFromString(dateLastInteraction);
        this.dateExpiry = DateConverter.iso8601DateTimeFromString(dateExpiry);
        this.uniqueName = uniqueName;
        this.status = status;
        this.closedReason = closedReason;
        this.ttl = ttl;
        this.mode = mode;
        this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated);
        this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated);
        this.url = url;
        this.links = links;
    }

    /**
     * Returns The The unique string that identifies the resource.
     *
     * @return The unique string that identifies the resource
     */
    public final String getSid() {
        return this.sid;
    }

    /**
     * Returns The The SID of the resource's parent Service.
     *
     * @return The SID of the resource's parent Service
     */
    public final String getServiceSid() {
        return this.serviceSid;
    }

    /**
     * Returns The The SID of the Account that created the resource.
     *
     * @return The SID of the Account that created the resource
     */
    public final String getAccountSid() {
        return this.accountSid;
    }

    /**
     * Returns The The ISO 8601 date when the Session started.
     *
     * @return The ISO 8601 date when the Session started
     */
    public final DateTime getDateStarted() {
        return this.dateStarted;
    }

    /**
     * Returns The The ISO 8601 date when the Session ended.
     *
     * @return The ISO 8601 date when the Session ended
     */
    public final DateTime getDateEnded() {
        return this.dateEnded;
    }

    /**
     * Returns The The ISO 8601 date when the Session last had an interaction.
     *
     * @return The ISO 8601 date when the Session last had an interaction
     */
    public final DateTime getDateLastInteraction() {
        return this.dateLastInteraction;
    }

    /**
     * Returns The The ISO 8601 date when the Session should expire.
     *
     * @return The ISO 8601 date when the Session should expire
     */
    public final DateTime getDateExpiry() {
        return this.dateExpiry;
    }

    /**
     * Returns The An application-defined string that uniquely identifies the
     * resource.
     *
     * @return An application-defined string that uniquely identifies the resource
     */
    public final String getUniqueName() {
        return this.uniqueName;
    }

    /**
     * Returns The The status of the Session.
     *
     * @return The status of the Session
     */
    public final Session.Status getStatus() {
        return this.status;
    }

    /**
     * Returns The The reason the Session ended.
     *
     * @return The reason the Session ended
     */
    public final String getClosedReason() {
        return this.closedReason;
    }

    /**
     * Returns The When the session will expire.
     *
     * @return When the session will expire
     */
    public final Integer getTtl() {
        return this.ttl;
    }

    /**
     * Returns The The Mode of the Session.
     *
     * @return The Mode of the Session
     */
    public final Session.Mode getMode() {
        return this.mode;
    }

    /**
     * Returns The The ISO 8601 date and time in GMT when the resource was created.
     *
     * @return The ISO 8601 date and time in GMT when the resource was created
     */
    public final DateTime getDateCreated() {
        return this.dateCreated;
    }

    /**
     * Returns The The ISO 8601 date and time in GMT when the resource was last
     * updated.
     *
     * @return The ISO 8601 date and time in GMT when the resource was last updated
     */
    public final DateTime getDateUpdated() {
        return this.dateUpdated;
    }

    /**
     * Returns The The absolute URL of the Session resource.
     *
     * @return The absolute URL of the Session resource
     */
    public final URI getUrl() {
        return this.url;
    }

    /**
     * Returns The The URLs of resources related to the Session.
     *
     * @return The URLs of resources related to the Session
     */
    public final Map getLinks() {
        return this.links;
    }

    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }

        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Session other = (Session) o;

        return Objects.equals(sid, other.sid) &&
               Objects.equals(serviceSid, other.serviceSid) &&
               Objects.equals(accountSid, other.accountSid) &&
               Objects.equals(dateStarted, other.dateStarted) &&
               Objects.equals(dateEnded, other.dateEnded) &&
               Objects.equals(dateLastInteraction, other.dateLastInteraction) &&
               Objects.equals(dateExpiry, other.dateExpiry) &&
               Objects.equals(uniqueName, other.uniqueName) &&
               Objects.equals(status, other.status) &&
               Objects.equals(closedReason, other.closedReason) &&
               Objects.equals(ttl, other.ttl) &&
               Objects.equals(mode, other.mode) &&
               Objects.equals(dateCreated, other.dateCreated) &&
               Objects.equals(dateUpdated, other.dateUpdated) &&
               Objects.equals(url, other.url) &&
               Objects.equals(links, other.links);
    }

    @Override
    public int hashCode() {
        return Objects.hash(sid,
                            serviceSid,
                            accountSid,
                            dateStarted,
                            dateEnded,
                            dateLastInteraction,
                            dateExpiry,
                            uniqueName,
                            status,
                            closedReason,
                            ttl,
                            mode,
                            dateCreated,
                            dateUpdated,
                            url,
                            links);
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                          .add("sid", sid)
                          .add("serviceSid", serviceSid)
                          .add("accountSid", accountSid)
                          .add("dateStarted", dateStarted)
                          .add("dateEnded", dateEnded)
                          .add("dateLastInteraction", dateLastInteraction)
                          .add("dateExpiry", dateExpiry)
                          .add("uniqueName", uniqueName)
                          .add("status", status)
                          .add("closedReason", closedReason)
                          .add("ttl", ttl)
                          .add("mode", mode)
                          .add("dateCreated", dateCreated)
                          .add("dateUpdated", dateUpdated)
                          .add("url", url)
                          .add("links", links)
                          .toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy