From 5981f36d5f75f4a96e387f7f9e850afeaaeed5ee Mon Sep 17 00:00:00 2001 From: nlathia Date: Sun, 11 Aug 2024 14:39:16 +0100 Subject: [PATCH] Add article topic upsert --- article.go | 8 +++---- article_topic_upsert.go | 51 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 article_topic_upsert.go diff --git a/article.go b/article.go index 59206a6..21feea5 100644 --- a/article.go +++ b/article.go @@ -23,10 +23,10 @@ const ( type PublicationStatus string const ( - // StatusDraft means that the article is being written or + // PublicationStatusDraft means that the article is being written or // edited and is not published. - StatusDraft PublicationStatus = "draft" + PublicationStatusDraft PublicationStatus = "draft" - // StatusPublished means that the article is published. - StatusPublished PublicationStatus = "published" + // PublicationStatusPublished means that the article is published. + PublicationStatusPublished PublicationStatus = "published" ) diff --git a/article_topic_upsert.go b/article_topic_upsert.go new file mode 100644 index 0000000..d2a2a8b --- /dev/null +++ b/article_topic_upsert.go @@ -0,0 +1,51 @@ +package client + +import ( + "context" + "encoding/json" + "net/http" + "time" +) + +type UpsertArticleTopicParams struct { + // ID is the identifier that the company uses for this topic + ID string `json:"id"` + + // ParentID is the identifier for this topic's parent topic (if any). + ParentID string `json:"parent_id"` + + // Name is the topic's name. + Name string `json:"title"` + + // Description is an topic's tagline. It may be empty. + Description string `json:"description"` + + // Visibility describes who can see this topic, ranging from the + // whole world (public) through to employees only (internal). + Visibility Visibility `json:"visibility"` + + // Status describes whether this article is published or not. + Status PublicationStatus `json:"status"` + + // Data optionally gives additional meta-data about the topic. + Data json.RawMessage `json:"data"` + + // Created is when the topic was first created. + Created time.Time `json:"created"` + + // Updated is when the topic was last changed. + Updated time.Time `json:"updated"` +} + +func (c *Client) UpsertArticleTopic(ctx context.Context, p *UpsertArticleTopicParams) error { + rsp, err := c.makeRequest(ctx, http.MethodPost, "topics", p) + if err != nil { + return err + } + defer rsp.Body.Close() + + if err := responseError(rsp); err != nil { + return err + } + return nil +}