MCPcopy Create free account
hub / github.com/CesiumGS/cesium-native / me

Method me

CesiumITwinClient/src/Connection.cpp:188–238  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186}
187
188CesiumAsync::Future<CesiumUtility::Result<UserProfile>> Connection::me() {
189 return this->ensureValidToken().thenInWorkerThread(
190 [asyncSystem = this->_asyncSystem,
191 pAssetAccessor =
192 this->_pAssetAccessor](const Result<std::string>& tokenResult) {
193 if (!tokenResult.value) {
194 return asyncSystem.createResolvedFuture<Result<UserProfile>>(
195 tokenResult.errors);
196 }
197
198 const std::vector<CesiumAsync::IAssetAccessor::THeader> headers{
199 {"Authorization", *tokenResult.value},
200 {"Accept", "application/vnd.bentley.itwin-platform.v1+json"},
201 {"Prefer", "return=representation"}};
202
203 return pAssetAccessor->get(asyncSystem, ME_URL, headers)
204 .thenImmediately([](std::shared_ptr<IAssetRequest>&& request) {
205 Result<rapidjson::Document> docResult =
206 handleJsonResponse(request, "listing iModels");
207 if (!docResult.value) {
208 return Result<UserProfile>(docResult.errors);
209 }
210
211 const auto& userMember = docResult.value->FindMember("user");
212 if (userMember == docResult.value->MemberEnd() ||
213 !userMember->value.IsObject()) {
214 return Result<UserProfile>(
215 ErrorList::error("Missing `user` property in response."));
216 }
217
218 return Result<UserProfile>(UserProfile{
219 JsonHelpers::getStringOrDefault(userMember->value, "id", ""),
220 JsonHelpers::getStringOrDefault(
221 userMember->value,
222 "displayName",
223 ""),
224 JsonHelpers::getStringOrDefault(
225 userMember->value,
226 "givenName",
227 ""),
228 JsonHelpers::getStringOrDefault(
229 userMember->value,
230 "surname",
231 ""),
232 JsonHelpers::getStringOrDefault(
233 userMember->value,
234 "email",
235 "")});
236 });
237 });
238}
239
240namespace {
241const std::string LIST_ITWINS_URL = "https://api.bentley.com/itwins/";

Callers 1

TestConnection.cppFile · 0.45

Calls 6

ensureValidTokenMethod · 0.95
handleJsonResponseFunction · 0.85
getStringOrDefaultFunction · 0.85
thenInWorkerThreadMethod · 0.45
thenImmediatelyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected