Search in sources :

Example 1 with Message

use of com.microsoft.graph.extensions.Message 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)

Example 2 with Message

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

the class MessageSnippets method createMessageObject.

private static Message createMessageObject() {
    // Get a context so we can interrogate Resources & SharedPreferences
    SnippetApp app = SnippetApp.getApp();
    SharedPreferences prefs = SharedPrefsUtil.getSharedPreferences();
    Message message = new Message();
    Recipient recipient = new Recipient();
    recipient.emailAddress = new EmailAddress();
    recipient.emailAddress.address = prefs.getString(SharedPrefsUtil.PREF_USER_ID, "");
    message.toRecipients = Collections.singletonList(recipient);
    message.subject = app.getString(R.string.mail_subject);
    ItemBody itemBody = new ItemBody();
    itemBody.contentType = BodyType.text;
    itemBody.content = app.getString(R.string.mail_body);
    message.body = itemBody;
    return message;
}
Also used : SnippetApp(com.microsoft.graph.snippets.application.SnippetApp) Message(com.microsoft.graph.extensions.Message) ItemBody(com.microsoft.graph.extensions.ItemBody) SharedPreferences(android.content.SharedPreferences) Recipient(com.microsoft.graph.extensions.Recipient) EmailAddress(com.microsoft.graph.extensions.EmailAddress)

Aggregations

Message (com.microsoft.graph.extensions.Message)2 SharedPreferences (android.content.SharedPreferences)1 ICallback (com.microsoft.graph.concurrency.ICallback)1 ClientException (com.microsoft.graph.core.ClientException)1 EmailAddress (com.microsoft.graph.extensions.EmailAddress)1 IMessageCollectionPage (com.microsoft.graph.extensions.IMessageCollectionPage)1 ItemBody (com.microsoft.graph.extensions.ItemBody)1 Recipient (com.microsoft.graph.extensions.Recipient)1 SnippetApp (com.microsoft.graph.snippets.application.SnippetApp)1