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

com.twilio.rest.messaging.v1.session.Message Maven / Gradle / Ivy

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

package com.twilio.rest.messaging.v1.session;

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.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 preview products that are subject to
 * change. Use them with caution. If you currently do not have developer preview
 * access, please contact [email protected].
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class Message extends Resource {
    private static final long serialVersionUID = 267169563214895L;

    /**
     * Create a MessageFetcher to execute fetch.
     *
     * @param pathSessionSid The unique id of the Session for this message.
     * @param pathSid A 34 character string that uniquely identifies this resource.
     * @return MessageFetcher capable of executing the fetch
     */
    public static MessageFetcher fetcher(final String pathSessionSid,
                                         final String pathSid) {
        return new MessageFetcher(pathSessionSid, pathSid);
    }

    /**
     * Create a MessageCreator to execute create.
     *
     * @param pathSessionSid The unique id of the Session for this message.
     * @return MessageCreator capable of executing the create
     */
    public static MessageCreator creator(final String pathSessionSid) {
        return new MessageCreator(pathSessionSid);
    }

    /**
     * Create a MessageUpdater to execute update.
     *
     * @param pathSessionSid The unique id of the Session for this message.
     * @param pathSid A 34 character string that uniquely identifies this resource.
     * @return MessageUpdater capable of executing the update
     */
    public static MessageUpdater updater(final String pathSessionSid,
                                         final String pathSid) {
        return new MessageUpdater(pathSessionSid, pathSid);
    }

    /**
     * Create a MessageReader to execute read.
     *
     * @param pathSessionSid The unique id of the Session for this message.
     * @return MessageReader capable of executing the read
     */
    public static MessageReader reader(final String pathSessionSid) {
        return new MessageReader(pathSessionSid);
    }

    /**
     * Create a MessageDeleter to execute delete.
     *
     * @param pathSessionSid The unique id of the Session for this message.
     * @param pathSid A 34 character string that uniquely identifies this resource.
     * @return MessageDeleter capable of executing the delete
     */
    public static MessageDeleter deleter(final String pathSessionSid,
                                         final String pathSid) {
        return new MessageDeleter(pathSessionSid, pathSid);
    }

    /**
     * Converts a JSON String into a Message object using the provided ObjectMapper.
     *
     * @param json Raw JSON String
     * @param objectMapper Jackson ObjectMapper
     * @return Message object represented by the provided JSON
     */
    public static Message fromJson(final String json, final ObjectMapper objectMapper) {
        // Convert all checked exceptions to Runtime
        try {
            return objectMapper.readValue(json, Message.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 Message object using the provided
     * ObjectMapper.
     *
     * @param json Raw JSON InputStream
     * @param objectMapper Jackson ObjectMapper
     * @return Message object represented by the provided JSON
     */
    public static Message fromJson(final InputStream json, final ObjectMapper objectMapper) {
        // Convert all checked exceptions to Runtime
        try {
            return objectMapper.readValue(json, Message.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 accountSid;
    private final String serviceSid;
    private final String messagingServiceSid;
    private final String sessionSid;
    private final String sid;
    private final Integer index;
    private final String author;
    private final String body;
    private final String attributes;
    private final DateTime dateCreated;
    private final DateTime dateUpdated;
    private final URI url;

    @JsonCreator
    private Message(@JsonProperty("account_sid")
                    final String accountSid,
                    @JsonProperty("service_sid")
                    final String serviceSid,
                    @JsonProperty("messaging_service_sid")
                    final String messagingServiceSid,
                    @JsonProperty("session_sid")
                    final String sessionSid,
                    @JsonProperty("sid")
                    final String sid,
                    @JsonProperty("index")
                    final Integer index,
                    @JsonProperty("author")
                    final String author,
                    @JsonProperty("body")
                    final String body,
                    @JsonProperty("attributes")
                    final String attributes,
                    @JsonProperty("date_created")
                    final String dateCreated,
                    @JsonProperty("date_updated")
                    final String dateUpdated,
                    @JsonProperty("url")
                    final URI url) {
        this.accountSid = accountSid;
        this.serviceSid = serviceSid;
        this.messagingServiceSid = messagingServiceSid;
        this.sessionSid = sessionSid;
        this.sid = sid;
        this.index = index;
        this.author = author;
        this.body = body;
        this.attributes = attributes;
        this.dateCreated = DateConverter.iso8601DateTimeFromString(dateCreated);
        this.dateUpdated = DateConverter.iso8601DateTimeFromString(dateUpdated);
        this.url = url;
    }

    /**
     * Returns The The unique id of the Account responsible for this message..
     *
     * @return The unique id of the Account responsible for this message.
     */
    public final String getAccountSid() {
        return this.accountSid;
    }

    /**
     * Returns The The unique id of the Chat Service this message belongs to..
     *
     * @return The unique id of the Chat Service this message belongs to.
     */
    public final String getServiceSid() {
        return this.serviceSid;
    }

    /**
     * Returns The The unique id of the SMS Service this message belongs to..
     *
     * @return The unique id of the SMS Service this message belongs to.
     */
    public final String getMessagingServiceSid() {
        return this.messagingServiceSid;
    }

    /**
     * Returns The The unique id of the Session for this message..
     *
     * @return The unique id of the Session for this message.
     */
    public final String getSessionSid() {
        return this.sessionSid;
    }

    /**
     * Returns The A 34 character string that uniquely identifies this resource..
     *
     * @return A 34 character string that uniquely identifies this resource.
     */
    public final String getSid() {
        return this.sid;
    }

    /**
     * Returns The The index of the message within the Session.
     *
     * @return The index of the message within the Session
     */
    public final Integer getIndex() {
        return this.index;
    }

    /**
     * Returns The The identity or the address of the device of the message's
     * author..
     *
     * @return The identity or the address of the device of the message's author.
     */
    public final String getAuthor() {
        return this.author;
    }

    /**
     * Returns The The contents of the message..
     *
     * @return The contents of the message.
     */
    public final String getBody() {
        return this.body;
    }

    /**
     * Returns The A string metadata field you can use to store any data you wish..
     *
     * @return A string metadata field you can use to store any data you wish.
     */
    public final String getAttributes() {
        return this.attributes;
    }

    /**
     * Returns The The date that this resource was created..
     *
     * @return The date that this resource was created.
     */
    public final DateTime getDateCreated() {
        return this.dateCreated;
    }

    /**
     * Returns The The date that this resource was last updated..
     *
     * @return The date that this resource was last updated.
     */
    public final DateTime getDateUpdated() {
        return this.dateUpdated;
    }

    /**
     * Returns The An absolute URL for this message..
     *
     * @return An absolute URL for this message.
     */
    public final URI getUrl() {
        return this.url;
    }

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

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

        Message other = (Message) o;

        return Objects.equals(accountSid, other.accountSid) &&
               Objects.equals(serviceSid, other.serviceSid) &&
               Objects.equals(messagingServiceSid, other.messagingServiceSid) &&
               Objects.equals(sessionSid, other.sessionSid) &&
               Objects.equals(sid, other.sid) &&
               Objects.equals(index, other.index) &&
               Objects.equals(author, other.author) &&
               Objects.equals(body, other.body) &&
               Objects.equals(attributes, other.attributes) &&
               Objects.equals(dateCreated, other.dateCreated) &&
               Objects.equals(dateUpdated, other.dateUpdated) &&
               Objects.equals(url, other.url);
    }

    @Override
    public int hashCode() {
        return Objects.hash(accountSid,
                            serviceSid,
                            messagingServiceSid,
                            sessionSid,
                            sid,
                            index,
                            author,
                            body,
                            attributes,
                            dateCreated,
                            dateUpdated,
                            url);
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                          .add("accountSid", accountSid)
                          .add("serviceSid", serviceSid)
                          .add("messagingServiceSid", messagingServiceSid)
                          .add("sessionSid", sessionSid)
                          .add("sid", sid)
                          .add("index", index)
                          .add("author", author)
                          .add("body", body)
                          .add("attributes", attributes)
                          .add("dateCreated", dateCreated)
                          .add("dateUpdated", dateUpdated)
                          .add("url", url)
                          .toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy