-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UpsertArticle to the go-client (#14)
- Loading branch information
Showing
2 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package client | ||
|
||
// Visibility describes who can view the given item (e.g. help article) | ||
type Visibility string | ||
|
||
const ( | ||
// VisibilityPublic means that the item is available to the general | ||
// public. For example, it is published on a public website. | ||
VisibilityPublic Visibility = "public" | ||
|
||
// VisibilityUsers means that the item is only available to the | ||
// company's customers. For example, it is only accessible via an | ||
// app after sign-up. | ||
VisibilityUsers Visibility = "users" | ||
|
||
// VisibilityInternal means that the item is only available to | ||
// the company's employees. For example, it is a procedure or SOP | ||
// that customers do not have access to. | ||
VisibilityInternal Visibility = "internal" | ||
) | ||
|
||
// PublicationStatus describes the status of a help article. | ||
type PublicationStatus string | ||
|
||
const ( | ||
// StatusDraft means that the article is being written or | ||
// edited and is not published. | ||
StatusDraft PublicationStatus = "draft" | ||
|
||
// StatusPublished means that the article is published. | ||
StatusPublished PublicationStatus = "published" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
type UpsertArticleParams struct { | ||
// AuthorID optionally identifies the (current) author of the article | ||
AuthorID string `json:"author_id"` | ||
|
||
// ID is the identifier that the company uses for this article | ||
ID string `json:"id"` | ||
|
||
// Title is the article's title. It may be empty. | ||
Title string `json:"title"` | ||
|
||
// Description is an article's tagline. It may be empty. | ||
Description string `json:"description"` | ||
|
||
// Body is the main contents of an article. It may be empty. | ||
Body string `json:"body"` | ||
|
||
// Visibility describes who can access this article, ranging from the | ||
// whole world (public) through to employees only (internal). | ||
Visibility Visibility `json:"visibility"` | ||
|
||
// TopicExternalID optionally identifies the topic that this | ||
// article is associated with. If given, you must have created | ||
// the topic first | ||
TopicID string `json:"topic_id"` | ||
|
||
// Status describes whether this article is published or not. | ||
Status PublicationStatus `json:"status"` | ||
|
||
// Data optionally gives additional meta-data about the article. | ||
Data json.RawMessage `json:"data"` | ||
|
||
// Created is when the article was first authored. | ||
Created time.Time `json:"created"` | ||
|
||
// Updated is when the article was last changed. | ||
Updated time.Time `json:"updated"` | ||
} | ||
|
||
// UpsertArticle inserts or updates a help article | ||
func (c *Client) UpsertArticle(ctx context.Context, p *UpsertArticleParams) error { | ||
rsp, err := c.makeRequest(ctx, http.MethodPost, "articles", p) | ||
if err != nil { | ||
return err | ||
} | ||
defer rsp.Body.Close() | ||
|
||
if err := responseError(rsp); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |