public async Task <List <SpeakerDTO> > GetAllSpeakers() { var speakersResponse = await _HttpClient.SendAsync(SpeakersLink.BuildRequestMessage()); speakersResponse.EnsureSuccessStatusCode(); WebApiContrib.CollectionJson.Collection collection = await SpeakersLink.ParseResponseAsync(speakersResponse); return(SpeakersLink.ParseSpeakers(collection)); }
public static List <SpeakerDTO> ParseSpeakers(this SpeakersLink link, Collection collection) { var speakers = collection.Items.Select(item => new SpeakerDTO { Name = item.Data[0].Value }).ToList(); return(speakers); }
public static SpeakersLink WithHints(this SpeakersLink speakersLink) { speakersLink.AddHint <AllowHint>(h => { h.AddMethod(HttpMethod.Get); h.AddMethod(HttpMethod.Put); h.AddMethod(HttpMethod.Delete); }); speakersLink.AddHint <FormatsHint>(h => h.AddMediaType("application/vnd.collection+json")); return(speakersLink); }
public async static Task <Collection> ParseResponseAsync(this SpeakersLink link, HttpResponseMessage response) { if (response.StatusCode != HttpStatusCode.OK) { return(null); } if (response.Content == null) { return(null); } if (response.Content.Headers.ContentType == null || response.Content.Headers.ContentType.MediaType != "application/vnd.collection+json") { return(null); } var readDocument = await response.Content.ReadAsAsync <ReadDocument>(new[] { new CollectionJsonFormatter() }); return(readDocument.Collection); }