This repository has been archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
MeSnippets.java
200 lines (184 loc) · 9.31 KB
/
MeSnippets.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*
* Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license.
* See LICENSE in the project root for license information.
*/
package com.microsoft.graph.snippets.snippet;
import com.google.gson.JsonObject;
import com.microsoft.graph.concurrency.ICallback;
import com.microsoft.graph.core.ClientException;
import com.microsoft.graph.models.extensions.DirectoryObject;
import com.microsoft.graph.models.extensions.ProfilePhoto;
import com.microsoft.graph.models.extensions.User;
import com.microsoft.graph.options.Option;
import com.microsoft.graph.options.QueryOption;
import com.microsoft.graph.requests.extensions.IDirectoryObjectCollectionWithReferencesPage;
import java.util.LinkedList;
import java.util.List;
import static com.microsoft.graph.snippets.R.array.get_me;
import static com.microsoft.graph.snippets.R.array.get_me_direct_reports;
import static com.microsoft.graph.snippets.R.array.get_me_group_membership;
import static com.microsoft.graph.snippets.R.array.get_me_manager;
import static com.microsoft.graph.snippets.R.array.get_me_photo;
import static com.microsoft.graph.snippets.R.array.get_me_responsibilities;
public abstract class MeSnippets<Result> extends AbstractSnippet<Result> {
/**
* Snippet constructor
*
* @param descriptionArray The String array for the specified snippet
*/
public MeSnippets(Integer descriptionArray) {
super(SnippetCategory.meSnippetCategory, descriptionArray);
}
static MeSnippets[] getMeSnippets() {
return new MeSnippets[]{
// Marker element
new MeSnippets(null) {
@Override
public void request(ICallback callback) {
// Not implemented
}
},
// Snippets
/* Get information about signed in user
* HTTP GET https://graph.microsoft.com/{version}/me
* @see https://graph.microsoft.io/docs/api-reference/v1.0/api/user_get
*/
new MeSnippets<JsonObject>(get_me) {
@Override
public void request(final ICallback<JsonObject> callback) {
mGraphServiceClient
.me()
.buildRequest()
.get(new ICallback<User>() {
@Override
public void success(User user) {
callback.success(user.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
},
/* Get responsibilities of signed in user
* HTTP GET https://graph.microsoft.com/{version}/me?$select=AboutMe,Responsibilities,Tags
* @see https://graph.microsoft.io/docs/api-reference/v1.0/resources/user
*/
new MeSnippets<JsonObject>(get_me_responsibilities) {
@Override
public void request(final ICallback<JsonObject> callback) {
final List<Option> options = new LinkedList<>();
options.add(new QueryOption("$select", "AboutMe,Responsibilities,Tags"));
mGraphServiceClient
.me()
.buildRequest(options)
.get(new ICallback<User>() {
@Override
public void success(User user) {
callback.success(user.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
},
/* Get the user's manager
* HTTP GET https://graph.microsoft.com/{version}/me/manager
* @see https://graph.microsoft.io/docs/api-reference/v1.0/resources/user
*/
new MeSnippets<JsonObject>(get_me_manager) {
@Override
public void request(final ICallback<JsonObject> callback) {
mGraphServiceClient
.me()
.manager()
.buildRequest()
.get(new ICallback<DirectoryObject>() {
@Override
public void success(DirectoryObject directoryObject) {
callback.success(directoryObject.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
},
/* Get the user's direct reports
* HTTP GET https://graph.microsoft.com/{version}/me/directReports
* @see https://graph.microsoft.io/docs/api-reference/v1.0/resources/user
*/
new MeSnippets<JsonObject>(get_me_direct_reports) {
@Override
public void request(final ICallback<JsonObject> callback) {
mGraphServiceClient
.me()
.directReports()
.buildRequest()
.get(new ICallback<IDirectoryObjectCollectionWithReferencesPage>() {
@Override
public void success(IDirectoryObjectCollectionWithReferencesPage iDirectoryObjectCollectionWithReferencesPage) {
callback.success(iDirectoryObjectCollectionWithReferencesPage.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
},
/* Get the group membership of the user
* HTTP GET https://graph.microsoft.com/{version}/me/memberOf
* @see https://graph.microsoft.io/docs/api-reference/v1.0/resources/user
*/
new MeSnippets<JsonObject>(get_me_group_membership) {
@Override
public void request(final ICallback<JsonObject> callback) {
mGraphServiceClient
.me()
.memberOf()
.buildRequest()
.get(new ICallback<IDirectoryObjectCollectionWithReferencesPage>() {
@Override
public void success(IDirectoryObjectCollectionWithReferencesPage iDirectoryObjectCollectionWithReferencesPage) {
callback.success(iDirectoryObjectCollectionWithReferencesPage.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
},
/* Get the photo of the user
* HTTP GET https://graph.microsoft.com/{version}/me/userPhoto
* @see https://graph.microsoft.io/docs/api-reference/v1.0/resources/user
*/
new MeSnippets<JsonObject>(get_me_photo) {
@Override
public void request(final ICallback<JsonObject> callback) {
mGraphServiceClient
.me()
.photo()
.buildRequest()
.get(new ICallback<ProfilePhoto>() {
@Override
public void success(ProfilePhoto profilePhoto) {
callback.success(profilePhoto.getRawObject());
}
@Override
public void failure(ClientException ex) {
callback.failure(ex);
}
});
}
}
};
}
@Override
public abstract void request(ICallback<Result> callback);
}