public async Task DeleteSessionForId(User user, int id) { string deleteSession = BASE_URL + "/session/delete?id=" + id; var uri = new Uri(deleteSession); var client = new HttpClient(); client.DefaultRequestHeaders.Authorization = BasicAuthenticationHelper.CreateBasicHeader(user.Name, user.Password); var response = await client.GetAsync(uri); response.EnsureSuccessStatusCode(); }
public async Task <Dictionary <string, double> > GetAveragesForSession(User user, int id) { string averageSession = BASE_URL + "/session/average?id=" + id; var uri = new Uri(averageSession); var client = new HttpClient(); client.DefaultRequestHeaders.Authorization = BasicAuthenticationHelper.CreateBasicHeader(user.Name, user.Password); var response = await client.GetAsync(uri); response.EnsureSuccessStatusCode(); var result = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <Dictionary <string, double> >(result)); }
public async Task <Session> GetSessionById(User user, int id) { string sessionsId = BASE_URL + "/session?id=" + id; var uri = new Uri(sessionsId); var client = new HttpClient(); client.DefaultRequestHeaders.Authorization = BasicAuthenticationHelper.CreateBasicHeader(user.Name, user.Password); var response = await client.GetAsync(uri); response.EnsureSuccessStatusCode(); var result = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <Session>(result)); }
public async Task <User> GetUserByName(string name) { string allSessions = BASE_URL + "/user?username=" + name; var uri = new Uri(allSessions); var client = new HttpClient(); var user = User.DefaultUser; client.DefaultRequestHeaders.Authorization = BasicAuthenticationHelper.CreateBasicHeader(user.Name, user.Password); var response = await client.GetAsync(uri); response.EnsureSuccessStatusCode(); var result = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <User>(result)); }
public async Task <List <Humidity> > GetHumiditiesForSession(Session session) { string humdities = BASE_URL + "/humidity?id=" + session.Id; //var uri = new Uri(startSession); var client = new HttpClient(); var defaultUser = session.User; client.DefaultRequestHeaders.Authorization = BasicAuthenticationHelper.CreateBasicHeader(defaultUser.Name, defaultUser.Password); var response = await client.GetAsync(humdities); response.EnsureSuccessStatusCode(); var result = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <List <Humidity> >(result)); }
public async Task <Session> StopSession(Session session) { string stopSession = BASE_URL + "/session/stop"; //var uri = new Uri(stopSession); var client = new HttpClient(); var defaultUser = session.User; client.DefaultRequestHeaders.Authorization = BasicAuthenticationHelper.CreateBasicHeader(defaultUser.Name, defaultUser.Password); string sessionObject = JsonConvert.SerializeObject(session); StringContent content = new StringContent(sessionObject.ToString(), Encoding.UTF8, "application/json"); var response = await client.PutAsync(stopSession, content); response.EnsureSuccessStatusCode(); var result = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <Session>(result)); }
public async Task <User> PostUser(User user) { string allSessions = BASE_URL + "/user"; var uri = new Uri(allSessions); var client = new HttpClient(); var defaultUser = User.DefaultUser; client.DefaultRequestHeaders.Authorization = BasicAuthenticationHelper.CreateBasicHeader(defaultUser.Name, defaultUser.Password); string userObject = JsonConvert.SerializeObject(user); StringContent content = new StringContent(userObject.ToString(), Encoding.UTF8, "application/json"); var response = await client.PostAsync(uri, content); response.EnsureSuccessStatusCode(); var result = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <User>(result)); }
public async Task <Temperature> AddTemperature(Temperature temperature) { string startSession = BASE_URL + "/temperature"; var uri = new Uri(startSession); var client = new HttpClient(); var defaultUser = temperature.Session.User; client.DefaultRequestHeaders.Authorization = BasicAuthenticationHelper.CreateBasicHeader(defaultUser.Name, defaultUser.Password); string temperatureObject = JsonConvert.SerializeObject(temperature); StringContent content = new StringContent(temperature.ToString(), Encoding.UTF8, "application/json"); var response = await client.PostAsync(uri, content); response.EnsureSuccessStatusCode(); var result = await response.Content.ReadAsStringAsync(); var settings = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore }; return(JsonConvert.DeserializeObject <Temperature>(result, settings)); }