Beispiel #1
0
        public async Task <UserAndMetaData> GetUserAsync(string username, GetUserOptions options)
        {
            var uri = GetUsersUri(options.DomainName, username);

            Logger.LogInformation($"Attempting to get user with username {username} - {uri}");

            try
            {
                // check user exists before trying to read content
                var result = await _client.GetAsync(uri, options.CancellationToken).ConfigureAwait(false);

                if (result.StatusCode == HttpStatusCode.NotFound)
                {
                    throw new UserNotFoundException(username);
                }

                result.EnsureSuccessStatusCode();

                // get user from result
                var json = JObject.Parse(await result.Content.ReadAsStringAsync().ConfigureAwait(false));
                return(UserAndMetaData.FromJson(json));
            }
            catch (Exception exception)
            {
                Logger.LogError(exception, $"Error trying to get user with username {username} - {uri}");
                throw;
            }
        }
Beispiel #2
0
        public static Task <UserAndMetaData> GetUserAsync(this IUserManager userManager, string username, Action <GetUserOptions> configureOptions)
        {
            var options = new GetUserOptions();

            configureOptions(options);

            return(userManager.GetUserAsync(username, options));
        }