Esempio n. 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);
            }
        }
Esempio n. 2
0
        public async Task <User> GetUser(int?userId = null)
        {
            var uri = UriFactory.CreateEndpointUri(userId == null ? "users/current" : $"users/id={userId}");
            HttpResponseMessage response;

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

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

                return(JsonConvert.DeserializeObject <User>(content));
            }
            else
            {
                throw new RestException(response.StatusCode, response.Content.ReadAsStringAsync().Result);
            }
        }
Esempio n. 3
0
        public async Task <Models.Task> GetTask(int taskId)
        {
            var uri = UriFactory.CreateEndpointUri($"tasks/show/id={taskId}");

            HttpResponseMessage response;

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


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

                var task = JsonConvert.DeserializeObject <Models.Task>(content);

                return(task);
            }
            else
            {
                throw new RestException(response.StatusCode, response.Content.ReadAsStringAsync().Result);
            }
        }
Esempio n. 4
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);
            }
        }
Esempio n. 5
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);
            }
        }
Esempio n. 6
0
        public async Task <List <User> > GetUsersAssignedToBoard(int boardId)
        {
            var uri = UriFactory.CreateEndpointUri($"boards/show/id={boardId}/users");
            HttpResponseMessage response;

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

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

                return(JsonConvert.DeserializeObject <List <User> >(content));
            }
            else
            {
                throw new RestException(response.StatusCode, response.Content.ReadAsStringAsync().Result);
            }
        }
Esempio n. 7
0
        public async Task <List <Board> > GetLoggedUserBoards()
        {
            var uri = UriFactory.CreateEndpointUri("boards/show");
            HttpResponseMessage response;

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

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

                var list = JsonConvert.DeserializeObject <List <Board> >(content);

                return(list);
            }
            else
            {
                throw new RestException(response.StatusCode, response.Content.ReadAsStringAsync().Result);
            }
        }
Esempio n. 8
0
        public async Task <List <User> > GetUserListByLogin(string pattern)
        {
            var uri = UriFactory.CreateEndpointUri($"users/all/query={pattern}");
            HttpResponseMessage response;

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

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

                var list = JsonConvert.DeserializeObject <List <User> >(content);

                return(list);
            }
            else
            {
                throw new RestException(response.StatusCode, response.Content.ReadAsStringAsync().Result);
            }
        }
Esempio n. 9
0
        public async Task DeleteTask(int taskId)
        {
            var uri = UriFactory.CreateEndpointUri($"tasks/delete/id={taskId}");
            HttpResponseMessage response;

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

            if (!response.IsSuccessStatusCode)
            {
                throw new RestException(response.StatusCode, response.Content.ReadAsStringAsync().Result);
            }
        }
Esempio n. 10
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);
            }
        }
Esempio n. 11
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);
            }
        }
Esempio n. 12
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);
            }
        }
Esempio n. 13
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);
            }
        }