Ejemplo n.º 1
0
        public async Task <GitHubUserModel> GetUserAndRepos(string userName)
        {
            string          url      = string.Format("users/{0}/repos", userName);
            GitHubUserModel userData = null;

            try
            {
                userData = await FindUser(userName);

                if (userData != null)
                {
                    List <GitHubUserRepoModel> repos = await FindRepos(url);

                    if (repos.Any())
                    {
                        repos = repos
                                .OrderByDescending(x => x.Stargazers_Count)
                                .Take(5)
                                .ToList();

                        userData.Repos = repos;
                    }
                }
            }
            catch (Exception ex)
            {
                Elmah.ErrorLog
                .GetDefault(HttpContext.Current)
                .Log(new Elmah.Error(ex));
            }

            return(userData);
        }
Ejemplo n.º 2
0
        private async Task <GitHubUserModel> FindUser(string userName)
        {
            string url = string.Format("users/{0}", userName);

            var response = _httpClientOperations.CallApi(_apiBaseUrl, url);

            if (response.IsSuccessStatusCode)
            {
                GitHubUserModel result = await response.Content.ReadAsAsync <GitHubUserModel>();

                if (result != null && result.Id != null && !string.IsNullOrEmpty(result.Location) && !string.IsNullOrEmpty(result.Name))
                {
                    return(result);
                }
            }

            return(null);
        }