From 470dc287c67d3d42488013717d740852bf71d611 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Mon, 8 Oct 2018 20:03:22 -0400 Subject: [PATCH] Move update params in Update|DeletePost Moves the ID and token params out of PostParams and into the func's parameters. A currently-unused `collection` parameter is left in for the future, when the backend supports updating and deleting collection posts via slug, not post ID. --- post.go | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/post.go b/post.go index 6c3be58..b023a43 100644 --- a/post.go +++ b/post.go @@ -135,9 +135,19 @@ func (c *Client) CreatePost(sp *PostParams) (*Post, error) { // UpdatePost updates a published post with the given PostParams. See // https://developer.write.as/docs/api/#update-a-post. -func (c *Client) UpdatePost(sp *PostParams) (*Post, error) { +func (c *Client) UpdatePost(id, token string, sp *PostParams) (*Post, error) { + return c.updatePost("", id, token, sp) +} + +func (c *Client) updatePost(collection, identifier, token string, sp *PostParams) (*Post, error) { p := &Post{} - env, err := c.put(fmt.Sprintf("/posts/%s", sp.ID), sp, p) + endpoint := "/posts/" + identifier + /* + if collection != "" { + endpoint = "/collections/" + collection + endpoint + } + */ + env, err := c.put(endpoint, sp, p) if err != nil { return nil, err } @@ -161,10 +171,22 @@ func (c *Client) UpdatePost(sp *PostParams) (*Post, error) { // DeletePost permanently deletes a published post. See // https://developer.write.as/docs/api/#delete-a-post. -func (c *Client) DeletePost(sp *PostParams) error { - env, err := c.delete(fmt.Sprintf("/posts/%s", sp.ID), map[string]string{ - "token": sp.Token, - }) +func (c *Client) DeletePost(id, token string) error { + return c.deletePost("", id, token) +} + +func (c *Client) deletePost(collection, identifier, token string) error { + p := map[string]string{} + endpoint := "/posts/" + identifier + /* + if collection != "" { + endpoint = "/collections/" + collection + endpoint + } else { + p["token"] = token + } + */ + p["token"] = token + env, err := c.delete(endpoint, p) if err != nil { return err }