Implement posts endpoints for APIv4 (#5480)

* Implement delete post endpoint for apiv4

* Implement POST search post endpoint for APIv4

* removed delete post quotes

* rearrange formatting
Этот коммит содержится в:
Ruzette Tanyag
2017-02-21 07:36:52 -05:00
коммит произвёл Joram Wilander
родитель a14e44b4ec
Коммит 9646bddd21
5 изменённых файлов: 356 добавлений и 0 удалений

Просмотреть файл

@@ -10,6 +10,7 @@ import (
"io/ioutil"
"mime/multipart"
"net/http"
"strconv"
"strings"
)
@@ -684,6 +685,16 @@ func (c *Client4) GetPost(postId string, etag string) (*Post, *Response) {
}
}
// DeletePost deletes a post from the provided post id string.
func (c *Client4) DeletePost(postId string) (bool, *Response) {
if r, err := c.DoApiDelete(c.GetPostRoute(postId)); err != nil {
return false, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
return CheckStatusOK(r), BuildResponse(r)
}
}
// GetPostThread gets a post with all the other posts in the same thread.
func (c *Client4) GetPostThread(postId string, etag string) (*PostList, *Response) {
if r, err := c.DoApiGet(c.GetPostRoute(postId)+"/thread", etag); err != nil {
@@ -705,6 +716,17 @@ func (c *Client4) GetPostsForChannel(channelId string, page, perPage int, etag s
}
}
// SearchPosts returns any posts with matching terms string.
func (c *Client4) SearchPosts(teamId string, terms string, isOrSearch bool) (*PostList, *Response) {
requestBody := map[string]string{"terms": terms, "is_or_search": strconv.FormatBool(isOrSearch)}
if r, err := c.DoApiPost(c.GetTeamRoute(teamId)+"/posts/search", MapToJson(requestBody)); err != nil {
return nil, &Response{StatusCode: r.StatusCode, Error: err}
} else {
defer closeBody(r)
return PostListFromJson(r.Body), BuildResponse(r)
}
}
// File Section
// UploadFile will upload a file to a channel, to be later attached to a post.