Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Status page endpoints #515

Open
wants to merge 55 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
a77fa40
Add ListStatusPages function
MaggotMouth Feb 12, 2024
d0af0c2
Add ListStatusPageImpacts function
MaggotMouth Feb 12, 2024
e249277
Add GetStatusPageImpact function
MaggotMouth Feb 12, 2024
e7abd70
Add ListStatusPageServices function
MaggotMouth Feb 12, 2024
ed3a7ac
Add ListStatusPageSeverities function
MaggotMouth Feb 12, 2024
400c9fc
Add GetStatusPageSeverity function
MaggotMouth Feb 12, 2024
899c672
Add ListStatusPageStatuses function
MaggotMouth Feb 12, 2024
ef6987e
Add GetStatusPageStatus function
MaggotMouth Feb 12, 2024
46597cc
Add ListStatusPagePosts function
MaggotMouth Feb 12, 2024
5fcea84
Add CreateStatusPagePost function
MaggotMouth Feb 12, 2024
5ec7674
Add GetStatusPagePost function
MaggotMouth Feb 12, 2024
ef1d3a7
Add helper functions to get the objects from response
MaggotMouth Feb 12, 2024
ec7976e
Add UpdateStatusPagePost function
MaggotMouth Feb 12, 2024
de89658
Add DeleteStatusPagePost function
MaggotMouth Feb 12, 2024
c811fff
Add ListStatusPagePostUpdates function
MaggotMouth Feb 12, 2024
fe61be1
Add CreateStatusPagePostUpdate function
MaggotMouth Feb 12, 2024
2e2c92d
Add GetStatusPagePostUpdate function
MaggotMouth Feb 12, 2024
f144281
Add UpdateStatusPagePostUpdate function
MaggotMouth Feb 12, 2024
67214cb
Add DeleteStatusPagePostUpdate function
MaggotMouth Feb 12, 2024
d62a17a
Add GetStatusPagePostPostMortem function
MaggotMouth Feb 12, 2024
4727923
Add CreateStatusPagePostPostMortem function
MaggotMouth Feb 12, 2024
c244469
Add UpdateStatusPagePostPostMortem function
MaggotMouth Feb 12, 2024
65f66ea
Add DeleteStatusPagePostPostMortem function
MaggotMouth Feb 12, 2024
0a393f4
Fix returnables from delete functions
MaggotMouth Feb 12, 2024
44764eb
Add ListStatusPageSubscriptions function
MaggotMouth Feb 12, 2024
324ee3b
Add CreateStatusPageSubscription function
MaggotMouth Feb 12, 2024
e82a827
Add GetStatusPageSubscription function
MaggotMouth Feb 12, 2024
604e2c5
Add DeleteStatusPageSubscription function
MaggotMouth Feb 12, 2024
ffbc981
Test for ListStatusPages
MaggotMouth Feb 12, 2024
691581a
Test for ListStatusPageImpacts
MaggotMouth Feb 12, 2024
1007d06
Test for GetStatusPageImpact
MaggotMouth Feb 12, 2024
90a0914
Test for ListStatusPageServices
MaggotMouth Feb 12, 2024
16081e2
Test for GetStatusPageService
MaggotMouth Feb 12, 2024
bca85e4
Test for ListStatusPageSeverities
MaggotMouth Feb 12, 2024
944be12
Test for GetStatusPageSeverity
MaggotMouth Feb 12, 2024
d491416
Test for ListStatusPageStatuses
MaggotMouth Feb 12, 2024
e82fac2
Test for GetStatusPageStatus
MaggotMouth Feb 12, 2024
1e6f778
Test for ListStatusPagePosts
MaggotMouth Feb 12, 2024
5230016
Test for CreateStatusPagePost
MaggotMouth Feb 12, 2024
32d1664
Test for GetStatusPagePost
MaggotMouth Feb 12, 2024
0cb6ba2
Test for UpdateStatusPagePost
MaggotMouth Feb 12, 2024
5cea63c
Test for DeleteStatusPagePost
MaggotMouth Feb 12, 2024
076cac7
Test for ListStatusPagePostUpdates
MaggotMouth Feb 12, 2024
ff8dd53
Test for CreateStatusPagePostUpdate
MaggotMouth Feb 12, 2024
97ffc2e
Test for GetStatusPagePostUpdate
MaggotMouth Feb 12, 2024
f91c6ac
Test for UpdateStatusPagePostUpdate
MaggotMouth Feb 12, 2024
2598971
Test for DeleteStatusPagePostUpdate
MaggotMouth Feb 12, 2024
e79e8d5
Test for GetStatusPagePostPostmortem
MaggotMouth Feb 12, 2024
eeaa5cd
Test for CreateStatusPagePostPostmortem
MaggotMouth Feb 12, 2024
d9ee488
Test for UpdateStatusPagePostPostmortem
MaggotMouth Feb 12, 2024
8d52894
Test for DeleteStatusPagePostPostmortem
MaggotMouth Feb 12, 2024
5f5fef2
Test for ListStatusPageSubscriptions
MaggotMouth Feb 12, 2024
0296aeb
Test for CreateStatusPageSubscription
MaggotMouth Feb 12, 2024
0508372
Test for GetStatusPageSubscription
MaggotMouth Feb 12, 2024
a2587c6
Test for DeleteStatusPageSubscription
MaggotMouth Feb 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Test for ListStatusPagePosts
  • Loading branch information
MaggotMouth committed Feb 12, 2024
commit 1e6f77835566c058f98e752b4de206b74563ed67
60 changes: 30 additions & 30 deletions status_page.go
Original file line number Diff line number Diff line change
@@ -54,25 +54,25 @@ type StatusPageStatus struct {
}

type StatusPagePost struct {
ID string
Self string
Type string
PostType string
StatusPage StatusPage
LinkedResource LinkedResource
PostMortem PostMortem
Title string
StartsAt string
EndsAt string
Updates []StatusPagePostUpdate
ID string `json:"id,omitempty"`
Self string `json:"self,omitempty"`
Type string `json:"type,omitempty"`
PostType string `json:"post_type,omitempty"`
StatusPage StatusPage `json:"status_page,omitempty"`
LinkedResource LinkedResource `json:"linked_resource,omitempty"`
Postmortem Postmortem `json:"postmortem,omitempty"`
Title string `json:"title,omitempty"`
StartsAt string `json:"starts_at,omitempty"`
EndsAt string `json:"ends_at,omitempty"`
Updates []StatusPagePostUpdate `json:"updates,omitempty"`
}

type LinkedResource struct {
ID string
Self string
}

type PostMortem struct {
type Postmortem struct {
ID string
Self string
NotifySubscribers bool
@@ -132,9 +132,9 @@ type ListStatusPageStatusesOptions struct {
}

type ListStatusPagePostOptions struct {
PostType string `url:"post_type,omitempty"`
ReviewedStatus string `url:"reviewed_status,omitempty"`
Statuses []StatusPageStatus `url:"statuses,omitempty"`
PostType string `url:"post_type,omitempty"`
ReviewedStatus string `url:"reviewed_status,omitempty"`
Status []string `url:"status,omitempty"`
}

type ListStatusPageSubscriptionsOptions struct {
@@ -458,41 +458,41 @@ func (c *Client) DeleteStatusPagePostUpdate(statusPageID string, postID string,
return err
}

// GetStatusPagePostPostMortem gets the specified status page post post-mortem
func (c *Client) GetStatusPagePostPostMortem(statusPageID string, postID string) (*PostMortem, error) {
// GetStatusPagePostPostmortem gets the specified status page post post-mortem
func (c *Client) GetStatusPagePostPostmortem(statusPageID string, postID string) (*Postmortem, error) {
h := map[string]string{
"X-EARLY-ACCESS": "status-pages-early-access",
}
resp, err := c.get(context.Background(), "/status_pages/"+statusPageID+"/posts/"+postID+"/postmortem", h)
return getStatusPagePostPostMortemFromResponse(c, resp, err)
return getStatusPagePostPostmortemFromResponse(c, resp, err)
}

// CreateStatusPagePostPostMortem creates a post-mortem for a Status Page by Status Page ID and Post ID
func (c *Client) CreateStatusPagePostPostMortem(statusPageID string, postID string, p PostMortem) (*PostMortem, error) {
// CreateStatusPagePostPostmortem creates a post-mortem for a Status Page by Status Page ID and Post ID
func (c *Client) CreateStatusPagePostPostmortem(statusPageID string, postID string, p Postmortem) (*Postmortem, error) {
h := map[string]string{
"X-EARLY-ACCESS": "status-pages-early-access",
}
d := map[string]PostMortem{
d := map[string]Postmortem{
"postmortem": p,
}
resp, err := c.post(context.Background(), "/status_pages/"+statusPageID+"/posts/"+postID+"/postmortem", d, h)
return getStatusPagePostPostMortemFromResponse(c, resp, err)
return getStatusPagePostPostmortemFromResponse(c, resp, err)
}

// UpdateStatusPagePostPostMortem updates a post-mortem for a Status Page by Status Page ID and Post ID
func (c *Client) UpdateStatusPagePostPostMortem(statusPageID string, postID string, p PostMortem) (*PostMortem, error) {
// UpdateStatusPagePostPostmortem updates a post-mortem for a Status Page by Status Page ID and Post ID
func (c *Client) UpdateStatusPagePostPostmortem(statusPageID string, postID string, p Postmortem) (*Postmortem, error) {
h := map[string]string{
"X-EARLY-ACCESS": "status-pages-early-access",
}
d := map[string]PostMortem{
d := map[string]Postmortem{
"postmortem": p,
}
resp, err := c.put(context.Background(), "/status_pages/"+statusPageID+"/posts/"+postID+"/postmortem", d, h)
return getStatusPagePostPostMortemFromResponse(c, resp, err)
return getStatusPagePostPostmortemFromResponse(c, resp, err)
}

// DeleteStatusPagePostPostMortem deletes a post-mortem for a Status Page by Status Page ID and Post ID
func (c *Client) DeleteStatusPagePostPostMortem(statusPageID string, postID string) error {
// DeleteStatusPagePostPostmortem deletes a post-mortem for a Status Page by Status Page ID and Post ID
func (c *Client) DeleteStatusPagePostPostmortem(statusPageID string, postID string) error {
/* Note: The API requires sending in the below header, but the client does not support headers for the delete() function, so we have to use do() */
h := map[string]string{
"X-EARLY-ACCESS": "status-pages-early-access",
@@ -674,12 +674,12 @@ func getStatusPagePostUpdateFromResponse(c *Client, resp *http.Response, err err
return &t, nil
}

func getStatusPagePostPostMortemFromResponse(c *Client, resp *http.Response, err error) (*PostMortem, error) {
func getStatusPagePostPostmortemFromResponse(c *Client, resp *http.Response, err error) (*Postmortem, error) {
if err != nil {
return nil, err
}

var target map[string]PostMortem
var target map[string]Postmortem
if dErr := c.decodeJSON(resp, &target); dErr != nil {
return nil, fmt.Errorf("Could not decode JSON response: %v", dErr)
}
47 changes: 47 additions & 0 deletions status_page_test.go
Original file line number Diff line number Diff line change
@@ -329,3 +329,50 @@ func TestStatusPage_GetStatus(t *testing.T) {

testEqual(t, want, res)
}

// ListStatusPagePosts
func TestStatusPage_ListPosts(t *testing.T) {
setup()
defer teardown()

mux.HandleFunc("/status_pages/1/posts", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testEqual(t, r.URL.Query()["post_type"], []string{"incident"})
testEqual(t, r.URL.Query()["reviewed_status"], []string{"approved"})
testEqual(t, r.URL.Query()["status"], []string{"status"})
_, _ = w.Write([]byte(`{"posts": [{"id": "1","post_type":"incident","status_page":{"id": "1","name":"MyStatusPage","published_at":"2024-02-12T09:23:23Z","status_page_type":"public","url":"https://mypagerduty"},"title":"MyPost","starts_at":"2024-02-12T09:23:23Z","ends_at":"2024-02-12T09:23:23Z"}]}`))
})

client := defaultTestClient(server.URL, "foo")
opts := ListStatusPagePostOptions{
PostType: "incident",
ReviewedStatus: "approved",
Status: []string{"status"},
}

res, err := client.ListStatusPagePosts("1", opts)
if err != nil {
t.Fatal(err)
}
want := &ListStatusPagePostsResponse{
APIListObject: APIListObject{},
StatusPagePosts: []StatusPagePost{
{
ID: "1",
PostType: "incident",
StatusPage: StatusPage{
ID: "1",
Name: "MyStatusPage",
PublishedAt: "2024-02-12T09:23:23Z",
StatusPageType: "public",
URL: "https://mypagerduty",
},
Title: "MyPost",
StartsAt: "2024-02-12T09:23:23Z",
EndsAt: "2024-02-12T09:23:23Z",
},
},
}

testEqual(t, want, res)
}