protected override async Task <bool> ReadDataAsync() { try { _logging.LogInformation("Sending request to read data..."); GitApiRequest apiRequest = new GitApiRequest() { Uri = _appSettings.GitSettings.Uri, Accept = _appSettings.GitSettings.Accept, UserAgent = _appSettings.GitSettings.UserAgent }; _repoList = await _importRepository.GetAsync(apiRequest); _logging.LogInformation("Completed request successfully"); } catch (Exception ex) { _logging.LogError(ex, "An error occurred when getting the reading the data."); return(false); } return(true); }
public async Task <IEnumerable <GitRepoDetails> > GetAsync(GitApiRequest apiRequest) { client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(apiRequest.Accept)); client.DefaultRequestHeaders.Add("User-Agent", apiRequest.UserAgent); var streamTask = await client.GetStreamAsync(apiRequest.Uri); var list = await JsonSerializer.DeserializeAsync <List <GitRepoDetails> >(streamTask); return(list); }
public async Task Test_GitRepositoryAsync_GetAsync() { GitApiRequest apiRequest = new GitApiRequest() { Uri = "https://api.github.com/orgs/dotnet/repos", Accept = "application/vnd.github.v3+json", UserAgent = "Import-Export-Tool" }; IGitRepository repository = new GitRepository(); IEnumerable <GitRepoDetails> list = await repository.GetAsync(apiRequest); Assert.IsNotNull(list); if (list != null) { foreach (GitRepoDetails item in list) { System.Diagnostics.Debug.WriteLine($" {item.Name}\n {item.Description}\n {item.Homepage}\n {item.GitHubHomeUrl}\n {item.LastPush}\n"); } } }