summaryrefslogtreecommitdiffstats
path: root/model/client4.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-02-13 10:52:50 -0500
committerCorey Hulen <corey@hulen.com>2017-02-13 10:52:50 -0500
commite4effd0c15a188eeec7a11f281e529afd6a54f80 (patch)
tree2c9b0f451366c54e163ac6f4743adf9e1cbd9a26 /model/client4.go
parent260f1111e8988b177550d2621fbf99df178ca57a (diff)
downloadchat-e4effd0c15a188eeec7a11f281e529afd6a54f80.tar.gz
chat-e4effd0c15a188eeec7a11f281e529afd6a54f80.tar.bz2
chat-e4effd0c15a188eeec7a11f281e529afd6a54f80.zip
Implement some post endpoints for APIv4 (#5353)
* Implement POST /posts endpoint for APIv4 * Implement GET /channels/{channel_id}/posts endpoint for APIv4 * Implement GET /posts/{post_id} endpoint for APIv4 * Implement GET /posts/{post_id}/thread endpoint for APIv4 * Skip team get if it's a DM channel in handlePostEvents
Diffstat (limited to 'model/client4.go')
-rw-r--r--model/client4.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/model/client4.go b/model/client4.go
index 15f42dbc2..7afc63359 100644
--- a/model/client4.go
+++ b/model/client4.go
@@ -92,6 +92,14 @@ func (c *Client4) GetChannelMemberRoute(channelId, userId string) string {
return fmt.Sprintf(c.GetChannelMembersRoute(channelId)+"/%v", userId)
}
+func (c *Client4) GetPostsRoute() string {
+ return fmt.Sprintf("/posts")
+}
+
+func (c *Client4) GetPostRoute(postId string) string {
+ return fmt.Sprintf(c.GetPostsRoute()+"/%v", postId)
+}
+
func (c *Client4) DoApiGet(url string, etag string) (*http.Response, *AppError) {
return c.DoApiRequest(http.MethodGet, url, "", etag)
}
@@ -468,4 +476,47 @@ func (c *Client4) GetChannelMembersForUser(userId, teamId, etag string) (*Channe
}
// Post Section
+
+// CreatePost creates a post based on the provided post struct.
+func (c *Client4) CreatePost(post *Post) (*Post, *Response) {
+ if r, err := c.DoApiPost(c.GetPostsRoute(), post.ToJson()); err != nil {
+ return nil, &Response{StatusCode: r.StatusCode, Error: err}
+ } else {
+ defer closeBody(r)
+ return PostFromJson(r.Body), BuildResponse(r)
+ }
+}
+
+// GetPost gets a single post.
+func (c *Client4) GetPost(postId string, etag string) (*Post, *Response) {
+ if r, err := c.DoApiGet(c.GetPostRoute(postId), etag); err != nil {
+ return nil, &Response{StatusCode: r.StatusCode, Error: err}
+ } else {
+ defer closeBody(r)
+ return PostFromJson(r.Body), 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 {
+ return nil, &Response{StatusCode: r.StatusCode, Error: err}
+ } else {
+ defer closeBody(r)
+ return PostListFromJson(r.Body), BuildResponse(r)
+ }
+}
+
+// GetPostsForChannel gets a page of posts with an array for ordering for a channel.
+func (c *Client4) GetPostsForChannel(channelId string, page, perPage int, etag string) (*PostList, *Response) {
+ query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage)
+ if r, err := c.DoApiGet(c.GetChannelRoute(channelId)+"/posts"+query, etag); err != nil {
+ return nil, &Response{StatusCode: r.StatusCode, Error: err}
+ } else {
+ defer closeBody(r)
+ return PostListFromJson(r.Body), BuildResponse(r)
+ }
+}
+
+// Files Section
// to be filled in..