diff options
author | Ruzette Tanyag <ruzette@users.noreply.github.com> | 2017-02-21 07:36:52 -0500 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-02-21 07:36:52 -0500 |
commit | 9646bddd21bf778349d1563e4fde756d4e981dd2 (patch) | |
tree | 13193200a3d7be4c5d9017f20ea8239f14d14d4e /model | |
parent | a14e44b4ec19f7005328aa28d9137d25d30dd4eb (diff) | |
download | chat-9646bddd21bf778349d1563e4fde756d4e981dd2.tar.gz chat-9646bddd21bf778349d1563e4fde756d4e981dd2.tar.bz2 chat-9646bddd21bf778349d1563e4fde756d4e981dd2.zip |
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
Diffstat (limited to 'model')
-rw-r--r-- | model/client4.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/model/client4.go b/model/client4.go index 833050561..6ace37dca 100644 --- a/model/client4.go +++ b/model/client4.go @@ -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. |