コード例 #1
0
        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();
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        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));
        }