public async Task <WikiMediaMetaDataDto> GetWikiContentAsync(string title) { HttpClient httpClient = new HttpClient(); HttpResponseMessage response = await httpClient.GetAsync($"{WIKIMEDIA_GET_CONTENT_ENDPOINT}&titles={title}"); WikiMediaMetaDataDto wikiMediaDto = await response.Content.ReadAsAsync <WikiMediaMetaDataDto>(); long pageId; try { pageId = wikiMediaDto.Query.Pages.Values.First().PageId; } catch (NullReferenceException) { throw new WikiArticleNotFoundException(); } if (pageId == 0 || string.IsNullOrEmpty(wikiMediaDto.Query.Pages.Values.First().Extract) || response.StatusCode != HttpStatusCode.OK) { throw new WikiArticleNotFoundException(); } return(wikiMediaDto); }
public async Task <DateTime> GetWikiLatestDateAsync(string title) { HttpClient httpClient = new HttpClient(); HttpResponseMessage response = await httpClient.GetAsync($"{WIKIMEDIA_GET_LATEST_DATE_ENDPOINT}&titles={title}"); WikiMediaMetaDataDto wikiMediaDateDto = await response.Content.ReadAsAsync <WikiMediaMetaDataDto>(); if (wikiMediaDateDto.Query.Pages.First().Value.Revisions == null) { throw new WikiArticleNotFoundException(); } return(wikiMediaDateDto.Query.Pages.First().Value.Revisions.First().Timestamp); }
public async Task <string> GetWikiThumbnailAsync(string title) { HttpClient httpClient = new HttpClient(); HttpResponseMessage response = await httpClient.GetAsync($"{WIKIMEDIA_GET_THUMBNAIL_ENDPOINT}&titles={title}"); WikiMediaMetaDataDto wikiMediaThumbnailDto = await response.Content.ReadAsAsync <WikiMediaMetaDataDto>(); if (wikiMediaThumbnailDto.Query.Pages.First().Value.Thumbnail == null) { throw new WikiArticleThumbnailNotFoundException(); } else if (response.StatusCode != HttpStatusCode.OK) { throw new WikiArticleNotFoundException(); } return(wikiMediaThumbnailDto.Query.Pages.First().Value.Thumbnail.Source); }