public static async Task <ComicModel> LoadComic(int comicNumber = 0) { string url = ""; if (comicNumber > 0) { url = $"https://xkcd.com/{comicNumber}/info.0.json"; } else { url = "https://xkcd.com/info.0.json"; } using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(url)) { if (response.IsSuccessStatusCode) { ComicModel comic = await response.Content.ReadAsAsync <ComicModel>(); return(comic); } else { throw new Exception(response.ReasonPhrase); } } }
public async Task <ComicModel> LoadComicImage(int comicNumber = 0) { var url = comicNumber == 0 ? $"{comicBaseUrl}/info.0.json" : $"{comicBaseUrl}/{comicNumber}/info.0.json"; using (HttpResponseMessage response = await ApiHelper.HttpClient.GetAsync(url)) { if (response.IsSuccessStatusCode) { ComicModel comic = await response.Content.ReadAsAsync <ComicModel>(); return(comic); } throw new Exception(response.ReasonPhrase); } }