public async Task <bool> PostForumAsync(Models.Forum forum) { var uri = new Uri(string.Format(Constants.RestUrl, "forums")); var body = ForumParser.PostForumBuilder(forum); Debug.WriteLine("[Forum API] - preparing to build content"); var content = new StringContent(body.ToString(), Encoding.UTF8, "application/json"); var contentString = await content.ReadAsStringAsync(); Debug.WriteLine("[Forum API] - content built: " + contentString); try { var response = await _client.PostAsync(uri, content); if (response.IsSuccessStatusCode) { var responseContent = await response.Content.ReadAsStringAsync(); Debug.WriteLine("[Forum API] - Post result: " + responseContent); return(true); } else { var failedContent = await response.Content.ReadAsStringAsync(); Debug.WriteLine("[Forum API] - Post response unsuccessful " + failedContent); return(false); } } catch (Exception ex) { Debug.WriteLine("[Forum API exception]:" + ex.Message); return(false); } }
public async Task <List <Models.Forum> > GetForumsAsync() { var uri = new Uri(string.Format(Constants.RestUrl, "forums")); try { var response = await _client.GetAsync(uri); List <Models.Forum> forums = new List <Models.Forum>(); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); Debug.WriteLine("[Forum API] - Forums: " + content); forums = ForumParser.GetForumsParser(content); } return(forums); } catch (TaskCanceledException) { throw; } catch (Exception ex) { Debug.WriteLine("[Forum API exception]:" + ex.Message); return(null); } }
public async Task <Models.Forum> GetForumAsync(string id) { Debug.WriteLine("Inside getForumAsync"); var uri = new Uri(string.Format(Constants.RestUrl, "forums/" + id)); try { var response = await _client.GetAsync(uri); Debug.WriteLine("[Forum API] got response"); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); Debug.WriteLine("[Forum API]: " + content); return(ForumParser.GetForumParser(content, id)); } return(null); } catch (Exception ex) { Debug.WriteLine("[Forum API exception]:" + ex.Message); return(null); } }