Search in sources :

Example 1 with IMessageCollectionPage

use of com.microsoft.graph.extensions.IMessageCollectionPage in project android-java-snippets-sample by microsoftgraph.

the class MessageSnippets method getMessageSnippets.

static MessageSnippets[] getMessageSnippets() {
    return new MessageSnippets[] { // Marker element
    new MessageSnippets(null) {

        @Override
        public void request(ICallback callback) {
        // Not implemented
        }
    }, /* Get messages from mailbox for signed in user
                 * HTTP GET https://graph.microsoft.com/{version}/me/messages
                 * @see https://graph.microsoft.io/docs/api-reference/v1.0/api/user_list_messages
                 */
    new MessageSnippets<JsonObject>(get_user_messages) {

        @Override
        public void request(final ICallback<JsonObject> callback) {
            mGraphServiceClient.getMe().getMessages().buildRequest().get(new ICallback<IMessageCollectionPage>() {

                @Override
                public void success(IMessageCollectionPage iMessageCollectionPage) {
                    callback.success(iMessageCollectionPage.getRawObject());
                }

                @Override
                public void failure(ClientException ex) {
                    callback.failure(ex);
                }
            });
        }
    }, /* Sends an email message on behalf of the signed in user
                 * HTTP POST https://graph.microsoft.com/{version}/me/messages/sendMail
                 * @see https://graph.microsoft.io/docs/api-reference/v1.0/api/user_post_messages
                 */
    new MessageSnippets<JsonObject>(send_an_email_message) {

        @Override
        public void request(final ICallback<JsonObject> callback) {
            Message message = createMessageObject();
            mGraphServiceClient.getMe().getSendMail(message, true).buildRequest().post(new ICallback<Void>() {

                @Override
                public void success(Void aVoid) {
                    callback.success(null);
                }

                @Override
                public void failure(ClientException ex) {
                    callback.failure(ex);
                }
            });
        }
    } };
}
Also used : ICallback(com.microsoft.graph.concurrency.ICallback) Message(com.microsoft.graph.extensions.Message) IMessageCollectionPage(com.microsoft.graph.extensions.IMessageCollectionPage) ClientException(com.microsoft.graph.core.ClientException)

Aggregations

ICallback (com.microsoft.graph.concurrency.ICallback)1 ClientException (com.microsoft.graph.core.ClientException)1 IMessageCollectionPage (com.microsoft.graph.extensions.IMessageCollectionPage)1 Message (com.microsoft.graph.extensions.Message)1