Example #1
0
        public async Task <Models.Task> EditTask(Models.Task task)
        {
            var uri   = UriFactory.CreateEndpointUri("tasks/update");
            var param = JsonContentFactory.CreateContent(task);
            HttpResponseMessage response;

            try
            {
                response = await Client.PutAsync(uri, param);
            }
            catch (Exception ex)
            {
                throw new ServerResponseException(ex.Message);
            }

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <Models.Task>(content));
            }
            else
            {
                throw new RestException(response.StatusCode, response.Content.ReadAsStringAsync().Result);
            }
        }
Example #2
0
        public async Task <Column> AddNewColumn(Column column)
        {
            var uri   = UriFactory.CreateEndpointUri("columns/add");
            var param = JsonContentFactory.CreateContent(column);
            HttpResponseMessage response;

            try
            {
                response = await Client.PostAsync(uri, param);
            }
            catch (Exception ex)
            {
                throw new ServerResponseException(ex.Message);
            }

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                return(JsonConvert.DeserializeObject <Column>(content));
            }
            else
            {
                throw new RestException(response.StatusCode, response.Content.ReadAsStringAsync().Result);
            }
        }
Example #3
0
        public async Task LogIn(User user)
        {
            var uri   = UriFactory.CreateEndpointUri("users/login");
            var param = JsonContentFactory.CreateContent(user);
            HttpResponseMessage response;

            try
            {
                response = await Client.PostAsync(uri, param);
            }
            catch (Exception ex)
            {
                throw new ServerResponseException(ex.Message);
            }

            if (response.IsSuccessStatusCode)
            {
                var authData        = $"{user.Login}:{user.Password}";
                var authHeaderValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(authData));

                Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", authHeaderValue);
                Client.MaxResponseContentBufferSize        = 256000;
            }
            else
            {
                throw new RestException(response.StatusCode, response.Content.ReadAsStringAsync().Result);
            }
        }
Example #4
0
        public async Task Register(User user)
        {
            var uri   = UriFactory.CreateEndpointUri("users/register");
            var param = JsonContentFactory.CreateContent(user);
            HttpResponseMessage response;

            try
            {
                response = await Client.PostAsync(uri, param);
            }
            catch (Exception ex)
            {
                throw new ServerResponseException(ex.Message);
            }

            if (!response.IsSuccessStatusCode)
            {
                throw new RestException(response.StatusCode, response.Content.ReadAsStringAsync().Result);
            }
        }
Example #5
0
        public async Task DeleteColumn(int columnId)
        {
            var uri   = UriFactory.CreateEndpointUri($"columns/delete/id={columnId}");
            var param = JsonContentFactory.CreateContent(columnId);
            HttpResponseMessage response;

            try
            {
                response = await Client.PostAsync(uri, param);
            }
            catch (Exception ex)
            {
                throw new ServerResponseException(ex.Message);
            }

            if (!response.IsSuccessStatusCode)
            {
                throw new RestException(response.StatusCode, response.Content.ReadAsStringAsync().Result);
            }
        }
Example #6
0
        public async Task UploadImage(Stream stream)
        {
            var uri   = UriFactory.CreateEndpointUri("images/upload/base64");
            var param = JsonContentFactory.CreateContent(new XamarinImage(stream));
            HttpResponseMessage response;

            try
            {
                response = await Client.PostAsync(uri, param);
            }
            catch (Exception ex)
            {
                throw new ServerResponseException(ex.Message);
            }

            if (!response.IsSuccessStatusCode)
            {
                throw new RestException(response.StatusCode, response.Content.ReadAsStringAsync().Result);
            }
        }
Example #7
0
        public async Task MoveTask(int taskId, int destinationColumn, int destinationPosition)
        {
            var uri   = UriFactory.CreateEndpointUri($"tasks/move/id={taskId}/target_column_id={destinationColumn}/position={destinationPosition}");
            var param = JsonContentFactory.CreateContent(null);

            HttpResponseMessage response;

            try
            {
                response = await Client.PostAsync(uri, param);
            }
            catch (Exception ex)
            {
                throw new ServerResponseException(ex.Message);
            }

            if (!response.IsSuccessStatusCode)
            {
                throw new RestException(response.StatusCode, response.Content.ReadAsStringAsync().Result);
            }
        }