use of com.microsoft.graph.concurrency.ICallback in project android-java-snippets-sample by microsoftgraph.
the class EventsSnippets method getEventsSnippets.
static EventsSnippets[] getEventsSnippets() {
return new EventsSnippets[] { // Marker element
new EventsSnippets(null) {
@Override
public void request(ICallback callback) {
// No implementation
}
}, /*
* Get all events for the signed in user.
* GET https://graph.microsoft.com/{version}/me/events
* @see https://graph.microsoft.io/docs/api-reference/v1.0/api/user_list_events
*/
new EventsSnippets<JsonObject>(get_user_events) {
@Override
public void request(final ICallback<JsonObject> callback) {
mGraphServiceClient.getMe().getEvents().buildRequest().get(new ICallback<IEventCollectionPage>() {
@Override
public void success(IEventCollectionPage iEventCollectionPage) {
callback.success(iEventCollectionPage.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
}, /*
* Adds an event to the signed-in user\'s calendar.
* POST https://graph.microsoft.com/{version}/me/events
* @see https://graph.microsoft.io/docs/api-reference/v1.0/api/user_post_events
*/
new EventsSnippets<JsonObject>(create_event) {
@Override
public void request(final ICallback<JsonObject> callback) {
Event event = createEventObject();
mGraphServiceClient.getMe().getEvents().buildRequest().post(event, new ICallback<Event>() {
@Override
public void success(Event event) {
callback.success(event.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
}, /*
* Update an event
* PATCH https://graph.microsoft.com/{version}/me/events/{Event.Id}
* @see https://graph.microsoft.io/docs/api-reference/v1.0/api/event_update
*/
new EventsSnippets<JsonObject>(update_event) {
@Override
public void request(final ICallback<JsonObject> callback) {
Event event = createEventObject();
mGraphServiceClient.getMe().getEvents().buildRequest().post(event, new ICallback<Event>() {
@Override
public void success(Event event) {
// Update the event object
event.subject = "Updated event";
mGraphServiceClient.getMe().getEvents().byId(event.id).buildRequest().patch(event, new ICallback<Event>() {
@Override
public void success(Event event) {
callback.success(event.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
}, /*
* Delete an event
* DELETE https://graph.microsoft.com/{version}/me/events/{Event.Id}
* @see https://graph.microsoft.io/docs/api-reference/v1.0/api/event_delete
*/
new EventsSnippets<JsonObject>(delete_event) {
@Override
public void request(final ICallback<JsonObject> callback) {
Event event = createEventObject();
mGraphServiceClient.getMe().getEvents().buildRequest().post(event, new ICallback<Event>() {
@Override
public void success(Event event) {
// Update the event object
event.subject = "Updated event";
mGraphServiceClient.getMe().getEvents().byId(event.id).buildRequest().delete(new ICallback<Void>() {
@Override
public void success(Void aVoid) {
callback.success(null);
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
} };
}
use of com.microsoft.graph.concurrency.ICallback in project android-java-snippets-sample by microsoftgraph.
the class GroupsSnippets method getGroupsSnippets.
static GroupsSnippets[] getGroupsSnippets() {
return new GroupsSnippets[] { // Marker element
new GroupsSnippets(null) {
@Override
public void request(ICallback callback) {
// Not implemented
}
}, /*
* Get a group by id
* GET https://graph.microsoft.com/{version}/myOrganization/groups/{Group.objectId}
* @see https://graph.microsoft.io/docs/api-reference/v1.0/api/group_get
*/
new GroupsSnippets<JsonObject>(get_a_group) {
@Override
public void request(final ICallback<JsonObject> callback) {
// create a group then query it
Group group = createGroupObject();
mGraphServiceClient.getGroups().buildRequest().post(group, new ICallback<Group>() {
@Override
public void success(Group group) {
mGraphServiceClient.getGroups().byId(group.id).buildRequest().get(new ICallback<Group>() {
@Override
public void success(Group group) {
callback.success(group.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
}, /* Get all of the members of a newly created organization group
* GET https://graph.microsoft.com/{version}/myOrganization/groups/{Group.objectId}/members
* @see https://graph.microsoft.io/docs/api-reference/v1.0/api/group_list_members
*/
new GroupsSnippets<JsonObject>(get_group_members) {
@Override
public void request(final ICallback<JsonObject> callback) {
// create a group then ask for its members
Group group = createGroupObject();
mGraphServiceClient.getGroups().buildRequest().post(group, new ICallback<Group>() {
@Override
public void success(Group group) {
mGraphServiceClient.getGroups().byId(group.id).getMembers().buildRequest().get(new ICallback<IDirectoryObjectCollectionWithReferencesPage>() {
@Override
public void success(IDirectoryObjectCollectionWithReferencesPage iDirectoryObjectCollectionWithReferencesPage) {
callback.success(iDirectoryObjectCollectionWithReferencesPage.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
}, /* Get all of a group's owners
* GET https://graph.microsoft.com/{version}/myOrganization/groups/{Group.objectId}/owners
* @see https://graph.microsoft.io/docs/api-reference/v1.0/api/group_list_owners
*/
new GroupsSnippets<JsonObject>(get_group_owners) {
@Override
public void request(final ICallback<JsonObject> callback) {
// create a group and then request its owner
Group group = createGroupObject();
mGraphServiceClient.getGroups().buildRequest().post(group, new ICallback<Group>() {
@Override
public void success(Group group) {
mGraphServiceClient.getGroups().byId(group.id).getOwners().buildRequest().get(new ICallback<IDirectoryObjectCollectionWithReferencesPage>() {
@Override
public void success(IDirectoryObjectCollectionWithReferencesPage iDirectoryObjectCollectionWithReferencesPage) {
callback.success(iDirectoryObjectCollectionWithReferencesPage.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
}, /* List all organization groups
* GET https://graph.microsoft.com/v1.0/groups
* @see https://graph.microsoft.io/docs/api-reference/v1.0/api/group_list
*/
new GroupsSnippets<JsonObject>(get_all_groups) {
@Override
public void request(final ICallback<JsonObject> callback) {
mGraphServiceClient.getGroups().buildRequest().get(new ICallback<IGroupCollectionPage>() {
@Override
public void success(IGroupCollectionPage iGroupCollectionPage) {
callback.success(iGroupCollectionPage.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
}, /* Create a new group with a random name
* POST https://graph.microsoft.com/{version}/myOrganization/groups
* @see https://graph.microsoft.io/docs/api-reference/v1.0/resources/group
*/
new GroupsSnippets<JsonObject>(insert_a_group) {
@Override
public void request(final ICallback<JsonObject> callback) {
// create a new group
Group group = createGroupObject();
mGraphServiceClient.getGroups().buildRequest().post(group, new ICallback<Group>() {
@Override
public void success(Group group) {
callback.success(group.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
}, /* Delete a group
* DELETE https://graph.microsoft.com/{version}/myOrganization/groups/{Group.objectId}
* @see https://graph.microsoft.io/docs/api-reference/v1.0/api/group_delete
*/
new GroupsSnippets<JsonObject>(delete_a_group) {
@Override
public void request(final ICallback<JsonObject> callback) {
// Create a group that we will delete
// create a group and then request its owner
Group group = createGroupObject();
mGraphServiceClient.getGroups().buildRequest().post(group, new ICallback<Group>() {
@Override
public void success(Group group) {
mGraphServiceClient.getGroups().byId(group.id).buildRequest().delete(new ICallback<Void>() {
@Override
public void success(Void aVoid) {
callback.success(null);
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
} };
}
use of com.microsoft.graph.concurrency.ICallback 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);
}
});
}
} };
}
use of com.microsoft.graph.concurrency.ICallback in project msgraph-sdk-java by microsoftgraph.
the class BaseRequestTests method testSendWithCallback.
@Test
public void testSendWithCallback() {
final AtomicBoolean success = new AtomicBoolean(false);
final AtomicBoolean failure = new AtomicBoolean(false);
ICallback<Object> callback = new ICallback<Object>() {
@Override
public void success(Object o) {
success.set(true);
callbackJsonObject = (JsonObject) o;
}
@Override
public void failure(ClientException ex) {
failure.set(true);
}
};
request.send(HttpMethod.GET, callback, null);
assertTrue(success.get());
assertFalse(failure.get());
assertNotNull(callbackJsonObject);
assertEquals("zzz", callbackJsonObject.get("id").getAsString());
}
use of com.microsoft.graph.concurrency.ICallback in project msgraph-sdk-java by microsoftgraph.
the class GraphServiceClientTest method testOverrideOfHttpSerializer.
@Test
public void testOverrideOfHttpSerializer() {
IHttpProvider hp = new IHttpProvider() {
@Override
public ISerializer getSerializer() {
return null;
}
@Override
public <Result, BodyType> void send(IHttpRequest request, ICallback<Result> callback, Class<Result> resultClass, BodyType serializable) {
// do nothing
}
@Override
public <Result, BodyType> Result send(IHttpRequest request, Class<Result> resultClass, BodyType serializable) throws ClientException {
return null;
}
@Override
public <Result, BodyType, DeserializeType> Result send(IHttpRequest request, Class<Result> resultClass, BodyType serializable, IStatefulResponseHandler<Result, DeserializeType> handler) throws ClientException {
return null;
}
};
IGraphServiceClient client = //
GraphServiceClient.builder().authenticationProvider(//
auth).httpProvider(//
hp).buildClient();
assertEquals(hp, client.getHttpProvider());
assertEquals(auth, client.getAuthenticationProvider());
assertNotNull(client.getSerializer());
assertNotNull(client.getLogger());
assertNotNull(client.getExecutors());
}
Aggregations