public async Task <List <SessionDTO> > GetAllSessions() { //SessionsLink.SetDay(1); var sessionsResponse = await _HttpClient.SendAsync(SessionsLink.BuildRequestMessage()); sessionsResponse.EnsureSuccessStatusCode(); var collection = await SessionsLink.ParseResponseAsync(sessionsResponse); return(SessionsLink.ParseSessions(collection)); }
public async Task <List <SessionDTO> > GetSessionsBySpeaker(int speakerid) { var sessionsResponse = await _HttpClient.SendAsync(SessionLink.BuildRequestMessage(new Dictionary <string, object> { { "speakerid", speakerid } })); sessionsResponse.EnsureSuccessStatusCode(); var collection = await SessionsLink.ParseResponseAsync(sessionsResponse); return(SessionsLink.ParseSessions(collection)); }
public async static Task <Collection> ParseResponseAsync(this SessionsLink 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); }
public static List <SessionDTO> ParseSessions(this SessionsLink link, Collection collection) { var sessions = collection.Items.Select(item => { var session = new SessionDTO(); foreach (var data in item.Data) { switch (data.Name) { case "Title": session.Title = data.Value; break; case "SpeakerName": session.SpeakerName = data.Value; break; } } return(session); } ).ToList(); return(sessions); }
public static SessionsLink WithHints(this SessionsLink link) { link.AddHint <AllowHint>(h => h.AddMethod(HttpMethod.Get)); link.AddHint <FormatsHint>(h => h.AddMediaType("application/vnd.collection+json")); return(link); }