Exemplo n.º 1
0
 public async Task <RocketChatUserDto> GetUserByEmailAsync(GetRocketChatUserByEmailInputDto input)
 {
     return(await UserCache.GetOrAddAsync(
                CalculateUserKey(input.Email),
                () => GetUserByEmailFromApiAsync(input)
                ));
 }
Exemplo n.º 2
0
        async Task <RocketChatUserDto> GetUserByEmailFromApiAsync(GetRocketChatUserByEmailInputDto input)
        {
            // To query data on the rocket chat API, we have to use the mongo-db query operators
            // See https://stackoverflow.com/questions/10700921/case-insensitive-search-with-in
            const string queryTemplate = "query={\"emails\":{\"$elemMatch\": {\"address\" : {\"$regex\":\"{0}\", \"$options\": \"i\"}}}}";

            using (var client = HttpClientFactory.CreateClient("RocketChat"))
            {
                await Authenticator.AuthenticateAsync(client);

                var queryParameter = string.Format(queryTemplate, input.Email);
                var response       = await client.GetFromJsonAsync <UserListResponse>($"api/v1/users.list?{queryParameter}");

                return(response.Users.FirstOrDefault());
            }
        }