From a77fa40b65ba93c5a875074bfc638a36b885578e Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 06:57:13 +0200 Subject: [PATCH 01/55] Add ListStatusPages function --- status_page.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 status_page.go diff --git a/status_page.go b/status_page.go new file mode 100644 index 00000000..d6e333ce --- /dev/null +++ b/status_page.go @@ -0,0 +1,38 @@ +package pagerduty + +import ( + "context" +) + +type StatusPage struct { + ID string + Name string + PublishedAt string + StatusPageType string + URL string + Type string +} + +// ListStatusPagesResponse is the data structure returned from calling the ListStatusPages API endpoint. +type ListStatusPagesResponse struct { + APIListObject + StatusPages []StatusPage `json:"status_pages"` +} + +// ListStatusPages lists the given types of status pages +func (c *Client) ListStatusPages(statusPageType string) (*ListStatusPagesResponse, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + resp, err := c.get(context.Background(), "/status_pages?status_page_type="+statusPageType, h) + if err != nil { + return nil, err + } + + var result ListStatusPagesResponse + if err := c.decodeJSON(resp, &result); err != nil { + return nil, err + } + + return &result, nil +} From d0af0c2a0d91bdfefdfbd554e32641e38b0df1d1 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 07:03:22 +0200 Subject: [PATCH 02/55] Add ListStatusPageImpacts function --- status_page.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/status_page.go b/status_page.go index d6e333ce..1348d1d6 100644 --- a/status_page.go +++ b/status_page.go @@ -13,12 +13,27 @@ type StatusPage struct { Type string } +type StatusPageImpact struct { + ID string + Self string + Description string + PostType string + StatusPage StatusPage + Type string +} + // ListStatusPagesResponse is the data structure returned from calling the ListStatusPages API endpoint. type ListStatusPagesResponse struct { APIListObject StatusPages []StatusPage `json:"status_pages"` } +// ListStatusPageImpactsResponse is the data structure returned from calling the ListStatusPagesImpacts API endpoint. +type ListStatusPageImpactsResponse struct { + APIListObject + StatusPageImpacts []StatusPageImpact `json:"impacts"` +} + // ListStatusPages lists the given types of status pages func (c *Client) ListStatusPages(statusPageType string) (*ListStatusPagesResponse, error) { h := map[string]string{ @@ -36,3 +51,21 @@ func (c *Client) ListStatusPages(statusPageType string) (*ListStatusPagesRespons return &result, nil } + +// ListStatusPageImpacts lists the given types of impacts for the specific status page +func (c *Client) ListStatusPageImpacts(id string, postType string) (*ListStatusPageImpactsResponse, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + resp, err := c.get(context.Background(), "/status_pages/"+id+"/impacts?post_type="+postType, h) + if err != nil { + return nil, err + } + + var result ListStatusPageImpactsResponse + if err := c.decodeJSON(resp, &result); err != nil { + return nil, err + } + + return &result, nil +} From e249277cee12ae15cb9b8c3ff457214fe7227db5 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 07:06:38 +0200 Subject: [PATCH 03/55] Add GetStatusPageImpact function --- status_page.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/status_page.go b/status_page.go index 1348d1d6..30c3b52c 100644 --- a/status_page.go +++ b/status_page.go @@ -69,3 +69,21 @@ func (c *Client) ListStatusPageImpacts(id string, postType string) (*ListStatusP return &result, nil } + +// GetStatusPageImpact gets the specified status page impact +func (c *Client) GetStatusPageImpact(statusPageID string, impactID string) (*StatusPageImpact, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + resp, err := c.get(context.Background(), "/status_pages/"+statusPageID+"/impacts/"+impactID, h) + if err != nil { + return nil, err + } + + var result StatusPageImpact + if err := c.decodeJSON(resp, &result); err != nil { + return nil, err + } + + return &result, nil +} From e7abd7020759b1aaffce8f2fcfbc50ab29e4b6ba Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 07:10:47 +0200 Subject: [PATCH 04/55] Add ListStatusPageServices function --- status_page.go | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/status_page.go b/status_page.go index 30c3b52c..337a277a 100644 --- a/status_page.go +++ b/status_page.go @@ -22,6 +22,15 @@ type StatusPageImpact struct { Type string } +type StatusPageService struct { + ID string + Self string + Name string + StatusPage StatusPage + BusinessService Service + Type string +} + // ListStatusPagesResponse is the data structure returned from calling the ListStatusPages API endpoint. type ListStatusPagesResponse struct { APIListObject @@ -34,6 +43,12 @@ type ListStatusPageImpactsResponse struct { StatusPageImpacts []StatusPageImpact `json:"impacts"` } +// ListStatusPageServicesResponse is the data structure returned from calling the ListStatusPagesServices API endpoint. +type ListStatusPageServicesResponse struct { + APIListObject + StatusPageServices []StatusPageService `json:"services"` +} + // ListStatusPages lists the given types of status pages func (c *Client) ListStatusPages(statusPageType string) (*ListStatusPagesResponse, error) { h := map[string]string{ @@ -52,7 +67,7 @@ func (c *Client) ListStatusPages(statusPageType string) (*ListStatusPagesRespons return &result, nil } -// ListStatusPageImpacts lists the given types of impacts for the specific status page +// ListStatusPageImpacts lists the given types of impacts for the specified status page func (c *Client) ListStatusPageImpacts(id string, postType string) (*ListStatusPageImpactsResponse, error) { h := map[string]string{ "X-EARLY-ACCESS": "status-pages-early-access", @@ -87,3 +102,21 @@ func (c *Client) GetStatusPageImpact(statusPageID string, impactID string) (*Sta return &result, nil } + +// ListStatusPageServices lists the services for the specified status page +func (c *Client) ListStatusPageServices(id string) (*ListStatusPageServicesResponse, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + resp, err := c.get(context.Background(), "/status_pages/"+id+"/services", h) + if err != nil { + return nil, err + } + + var result ListStatusPageServicesResponse + if err := c.decodeJSON(resp, &result); err != nil { + return nil, err + } + + return &result, nil +} From ed3a7acc26518d2dc81767ce6863a07a32afba52 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 07:17:59 +0200 Subject: [PATCH 05/55] Add ListStatusPageSeverities function --- status_page.go | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/status_page.go b/status_page.go index 337a277a..44023b29 100644 --- a/status_page.go +++ b/status_page.go @@ -31,6 +31,15 @@ type StatusPageService struct { Type string } +type StatusPageSeverity struct { + ID string + Self string + Description string + PostType string + StatusPage StatusPage + Type string +} + // ListStatusPagesResponse is the data structure returned from calling the ListStatusPages API endpoint. type ListStatusPagesResponse struct { APIListObject @@ -49,6 +58,12 @@ type ListStatusPageServicesResponse struct { StatusPageServices []StatusPageService `json:"services"` } +// ListStatusPageSeveritiesResponse is the data structure returned from calling the ListStatusPageSeverities API endpoint. +type ListStatusPageSeveritiesResponse struct { + APIListObject + StatusPageSeverities []StatusPageSeverity `json:"severities"` +} + // ListStatusPages lists the given types of status pages func (c *Client) ListStatusPages(statusPageType string) (*ListStatusPagesResponse, error) { h := map[string]string{ @@ -120,3 +135,39 @@ func (c *Client) ListStatusPageServices(id string) (*ListStatusPageServicesRespo return &result, nil } + +// GetStatusPageService gets the specified status page service +func (c *Client) GetStatusPageService(statusPageID string, serviceID string) (*StatusPageService, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + resp, err := c.get(context.Background(), "/status_pages/"+statusPageID+"/services/"+serviceID, h) + if err != nil { + return nil, err + } + + var result StatusPageService + if err := c.decodeJSON(resp, &result); err != nil { + return nil, err + } + + return &result, nil +} + +// ListStatusPageSeverities lists the severities for the specified status page +func (c *Client) ListStatusPageSeverities(id string, postType string) (*ListStatusPageSeveritiesResponse, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + resp, err := c.get(context.Background(), "/status_pages/"+id+"/severities?post_type="+postType, h) + if err != nil { + return nil, err + } + + var result ListStatusPageSeveritiesResponse + if err := c.decodeJSON(resp, &result); err != nil { + return nil, err + } + + return &result, nil +} From 400c9fc10120d3ef054b5a68849b441516fa338e Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 07:19:07 +0200 Subject: [PATCH 06/55] Add GetStatusPageSeverity function --- status_page.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/status_page.go b/status_page.go index 44023b29..a7a1671c 100644 --- a/status_page.go +++ b/status_page.go @@ -171,3 +171,21 @@ func (c *Client) ListStatusPageSeverities(id string, postType string) (*ListStat return &result, nil } + +// GetStatusPageSeverity gets the specified status page severity +func (c *Client) GetStatusPageSeverity(statusPageID string, severityID string) (*StatusPageSeverity, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + resp, err := c.get(context.Background(), "/status_pages/"+statusPageID+"/severities/"+severityID, h) + if err != nil { + return nil, err + } + + var result StatusPageSeverity + if err := c.decodeJSON(resp, &result); err != nil { + return nil, err + } + + return &result, nil +} From 899c6722654e8364ad32df040bef643602657c82 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 07:22:21 +0200 Subject: [PATCH 07/55] Add ListStatusPageStatuses function --- status_page.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/status_page.go b/status_page.go index a7a1671c..616b301d 100644 --- a/status_page.go +++ b/status_page.go @@ -40,6 +40,15 @@ type StatusPageSeverity struct { Type string } +type StatusPageStatus struct { + ID string + Self string + Description string + PostType string + StatusPage StatusPage + Type string +} + // ListStatusPagesResponse is the data structure returned from calling the ListStatusPages API endpoint. type ListStatusPagesResponse struct { APIListObject @@ -64,6 +73,12 @@ type ListStatusPageSeveritiesResponse struct { StatusPageSeverities []StatusPageSeverity `json:"severities"` } +// ListStatusPageStatusesResponse is the data structure returned from calling the ListStatusPageStatuses API endpoint. +type ListStatusPageStatusesResponse struct { + APIListObject + StatusPageStatuses []StatusPageStatus `json:"statuses"` +} + // ListStatusPages lists the given types of status pages func (c *Client) ListStatusPages(statusPageType string) (*ListStatusPagesResponse, error) { h := map[string]string{ @@ -189,3 +204,21 @@ func (c *Client) GetStatusPageSeverity(statusPageID string, severityID string) ( return &result, nil } + +// ListStatusPageStatuses lists the statuses for the specified status page +func (c *Client) ListStatusPageStatuses(id string, postType string) (*ListStatusPageStatusesResponse, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + resp, err := c.get(context.Background(), "/status_pages/"+id+"/statuses?post_type="+postType, h) + if err != nil { + return nil, err + } + + var result ListStatusPageStatusesResponse + if err := c.decodeJSON(resp, &result); err != nil { + return nil, err + } + + return &result, nil +} From ef6987e73f7b197227997d4fd24f2488a5f19e9c Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 07:23:35 +0200 Subject: [PATCH 08/55] Add GetStatusPageStatus function --- status_page.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/status_page.go b/status_page.go index 616b301d..64d81d6f 100644 --- a/status_page.go +++ b/status_page.go @@ -222,3 +222,21 @@ func (c *Client) ListStatusPageStatuses(id string, postType string) (*ListStatus return &result, nil } + +// GetStatusPageStatus gets the specified status page status +func (c *Client) GetStatusPageStatus(statusPageID string, statusID string) (*StatusPageStatus, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + resp, err := c.get(context.Background(), "/status_pages/"+statusPageID+"/statuses/"+statusID, h) + if err != nil { + return nil, err + } + + var result StatusPageStatus + if err := c.decodeJSON(resp, &result); err != nil { + return nil, err + } + + return &result, nil +} From 46597cc19b686cf996847178fb29d9f6cb04e99b Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 07:45:26 +0200 Subject: [PATCH 09/55] Add ListStatusPagePosts function --- status_page.go | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/status_page.go b/status_page.go index 64d81d6f..92780d94 100644 --- a/status_page.go +++ b/status_page.go @@ -2,6 +2,8 @@ package pagerduty import ( "context" + + "github.com/google/go-querystring/query" ) type StatusPage struct { @@ -49,6 +51,55 @@ type StatusPageStatus struct { Type string } +type StatusPagePost struct { + ID string + Self string + Type string + PostType string + StatusPage StatusPage + LinkedResource LinkedResource + PostMortem PostMortem + Title string + StartsAt string + EndsAt string + Updates []StatusPageUpdate +} + +type LinkedResource struct { + ID string + Self string +} + +type PostMortem struct { + ID string + Self string +} + +type StatusPageUpdate struct { + ID string + Self string + Message string + ReviewedStatus string + Status StatusPageStatus + Severity StatusPageSeverity + ImpactedServices []StatusPagePostUpdateImpact + UpdateFrequencyMS uint + NotifySubscribers bool + ReportedAt string + Type string +} + +type StatusPagePostUpdateImpact struct { + Service Service + Severity StatusPageSeverity +} + +type ListStatusPagePostOptions struct { + PostType string `url:"post_type,omitempty"` + ReviewedStatus string `url:"reviewed_status,omitempty"` + Statuses []StatusPageStatus `url:"statuses,omitempty"` +} + // ListStatusPagesResponse is the data structure returned from calling the ListStatusPages API endpoint. type ListStatusPagesResponse struct { APIListObject @@ -79,6 +130,12 @@ type ListStatusPageStatusesResponse struct { StatusPageStatuses []StatusPageStatus `json:"statuses"` } +// ListStatusPagePostsResponse is the data structure returned from calling the ListStatusPagePosts API endpoint. +type ListStatusPagePostsResponse struct { + APIListObject + StatusPagePosts []StatusPagePost `json:"posts"` +} + // ListStatusPages lists the given types of status pages func (c *Client) ListStatusPages(statusPageType string) (*ListStatusPagesResponse, error) { h := map[string]string{ @@ -240,3 +297,25 @@ func (c *Client) GetStatusPageStatus(statusPageID string, statusID string) (*Sta return &result, nil } + +// ListStatusPagePosts lists the posts for the specified status page +func (c *Client) ListStatusPagePosts(id string, o ListStatusPagePostOptions) (*ListStatusPagePostsResponse, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + v, err := query.Values(o) + if err != nil { + return nil, err + } + resp, err := c.get(context.Background(), "/status_pages/"+id+"/posts?"+v.Encode(), h) + if err != nil { + return nil, err + } + + var result ListStatusPagePostsResponse + if err := c.decodeJSON(resp, &result); err != nil { + return nil, err + } + + return &result, nil +} From 5fcea848a3246d7ecaf81a658031d4643e335ad2 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 07:50:52 +0200 Subject: [PATCH 10/55] Add CreateStatusPagePost function --- status_page.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/status_page.go b/status_page.go index 92780d94..3f89bd98 100644 --- a/status_page.go +++ b/status_page.go @@ -2,6 +2,8 @@ package pagerduty import ( "context" + "fmt" + "net/http" "github.com/google/go-querystring/query" ) @@ -319,3 +321,35 @@ func (c *Client) ListStatusPagePosts(id string, o ListStatusPagePostOptions) (*L return &result, nil } + +// CreateStatusPagePost create a Post for a Status Page by Status Page ID +func (c *Client) CreateStatusPagePost(id string, p StatusPagePost) (*StatusPagePost, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + d := map[string]StatusPagePost{ + "post": p, + } + resp, err := c.post(context.Background(), "/status_pages/"+id+"/posts", d, h) + return getStatusPagePostFromResponse(c, resp, err) +} + +func getStatusPagePostFromResponse(c *Client, resp *http.Response, err error) (*StatusPagePost, error) { + if err != nil { + return nil, err + } + + var target map[string]StatusPagePost + if dErr := c.decodeJSON(resp, &target); dErr != nil { + return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) + } + + const rootNode = "post" + + t, nodeOK := target[rootNode] + if !nodeOK { + return nil, fmt.Errorf("JSON response does not have %s field", rootNode) + } + + return &t, nil +} From 5ec7674320ce1765bedfd1a629dc3abbf38cc79e Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 07:52:44 +0200 Subject: [PATCH 11/55] Add GetStatusPagePost function --- status_page.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/status_page.go b/status_page.go index 3f89bd98..71e91ea6 100644 --- a/status_page.go +++ b/status_page.go @@ -353,3 +353,21 @@ func getStatusPagePostFromResponse(c *Client, resp *http.Response, err error) (* return &t, nil } + +// GetStatusPageStatus gets the specified status page status +func (c *Client) GetStatusPagePost(statusPageID string, postID string) (*StatusPagePost, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + resp, err := c.get(context.Background(), "/status_pages/"+statusPageID+"/posts/"+postID, h) + if err != nil { + return nil, err + } + + var result StatusPagePost + if err := c.decodeJSON(resp, &result); err != nil { + return nil, err + } + + return &result, nil +} From ef1d3a7e9aa54e8075b3036f7705cda1b3b0b81c Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 08:00:08 +0200 Subject: [PATCH 12/55] Add helper functions to get the objects from response --- status_page.go | 137 +++++++++++++++++++++++++++++++------------------ 1 file changed, 86 insertions(+), 51 deletions(-) diff --git a/status_page.go b/status_page.go index 71e91ea6..72949112 100644 --- a/status_page.go +++ b/status_page.go @@ -180,16 +180,7 @@ func (c *Client) GetStatusPageImpact(statusPageID string, impactID string) (*Sta "X-EARLY-ACCESS": "status-pages-early-access", } resp, err := c.get(context.Background(), "/status_pages/"+statusPageID+"/impacts/"+impactID, h) - if err != nil { - return nil, err - } - - var result StatusPageImpact - if err := c.decodeJSON(resp, &result); err != nil { - return nil, err - } - - return &result, nil + return getStatusPageImpactFromResponse(c, resp, err) } // ListStatusPageServices lists the services for the specified status page @@ -216,16 +207,7 @@ func (c *Client) GetStatusPageService(statusPageID string, serviceID string) (*S "X-EARLY-ACCESS": "status-pages-early-access", } resp, err := c.get(context.Background(), "/status_pages/"+statusPageID+"/services/"+serviceID, h) - if err != nil { - return nil, err - } - - var result StatusPageService - if err := c.decodeJSON(resp, &result); err != nil { - return nil, err - } - - return &result, nil + return getStatusPageServiceFromResponse(c, resp, err) } // ListStatusPageSeverities lists the severities for the specified status page @@ -252,16 +234,7 @@ func (c *Client) GetStatusPageSeverity(statusPageID string, severityID string) ( "X-EARLY-ACCESS": "status-pages-early-access", } resp, err := c.get(context.Background(), "/status_pages/"+statusPageID+"/severities/"+severityID, h) - if err != nil { - return nil, err - } - - var result StatusPageSeverity - if err := c.decodeJSON(resp, &result); err != nil { - return nil, err - } - - return &result, nil + return getStatusPageSeverityFromResponse(c, resp, err) } // ListStatusPageStatuses lists the statuses for the specified status page @@ -288,16 +261,7 @@ func (c *Client) GetStatusPageStatus(statusPageID string, statusID string) (*Sta "X-EARLY-ACCESS": "status-pages-early-access", } resp, err := c.get(context.Background(), "/status_pages/"+statusPageID+"/statuses/"+statusID, h) - if err != nil { - return nil, err - } - - var result StatusPageStatus - if err := c.decodeJSON(resp, &result); err != nil { - return nil, err - } - - return &result, nil + return getStatusPageStatusFromResponse(c, resp, err) } // ListStatusPagePosts lists the posts for the specified status page @@ -334,17 +298,26 @@ func (c *Client) CreateStatusPagePost(id string, p StatusPagePost) (*StatusPageP return getStatusPagePostFromResponse(c, resp, err) } -func getStatusPagePostFromResponse(c *Client, resp *http.Response, err error) (*StatusPagePost, error) { +// GetStatusPagePost gets the specified status page status +func (c *Client) GetStatusPagePost(statusPageID string, postID string) (*StatusPagePost, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + resp, err := c.get(context.Background(), "/status_pages/"+statusPageID+"/posts/"+postID, h) + return getStatusPagePostFromResponse(c, resp, err) +} + +func getStatusPageImpactFromResponse(c *Client, resp *http.Response, err error) (*StatusPageImpact, error) { if err != nil { return nil, err } - var target map[string]StatusPagePost + var target map[string]StatusPageImpact if dErr := c.decodeJSON(resp, &target); dErr != nil { return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) } - const rootNode = "post" + const rootNode = "impact" t, nodeOK := target[rootNode] if !nodeOK { @@ -354,20 +327,82 @@ func getStatusPagePostFromResponse(c *Client, resp *http.Response, err error) (* return &t, nil } -// GetStatusPageStatus gets the specified status page status -func (c *Client) GetStatusPagePost(statusPageID string, postID string) (*StatusPagePost, error) { - h := map[string]string{ - "X-EARLY-ACCESS": "status-pages-early-access", +func getStatusPageServiceFromResponse(c *Client, resp *http.Response, err error) (*StatusPageService, error) { + if err != nil { + return nil, err } - resp, err := c.get(context.Background(), "/status_pages/"+statusPageID+"/posts/"+postID, h) + + var target map[string]StatusPageService + if dErr := c.decodeJSON(resp, &target); dErr != nil { + return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) + } + + const rootNode = "service" + + t, nodeOK := target[rootNode] + if !nodeOK { + return nil, fmt.Errorf("JSON response does not have %s field", rootNode) + } + + return &t, nil +} + +func getStatusPageStatusFromResponse(c *Client, resp *http.Response, err error) (*StatusPageStatus, error) { if err != nil { return nil, err } - var result StatusPagePost - if err := c.decodeJSON(resp, &result); err != nil { + var target map[string]StatusPageStatus + if dErr := c.decodeJSON(resp, &target); dErr != nil { + return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) + } + + const rootNode = "status" + + t, nodeOK := target[rootNode] + if !nodeOK { + return nil, fmt.Errorf("JSON response does not have %s field", rootNode) + } + + return &t, nil +} + +func getStatusPageSeverityFromResponse(c *Client, resp *http.Response, err error) (*StatusPageSeverity, error) { + if err != nil { return nil, err } - return &result, nil + var target map[string]StatusPageSeverity + if dErr := c.decodeJSON(resp, &target); dErr != nil { + return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) + } + + const rootNode = "severity" + + t, nodeOK := target[rootNode] + if !nodeOK { + return nil, fmt.Errorf("JSON response does not have %s field", rootNode) + } + + return &t, nil +} + +func getStatusPagePostFromResponse(c *Client, resp *http.Response, err error) (*StatusPagePost, error) { + if err != nil { + return nil, err + } + + var target map[string]StatusPagePost + if dErr := c.decodeJSON(resp, &target); dErr != nil { + return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) + } + + const rootNode = "post" + + t, nodeOK := target[rootNode] + if !nodeOK { + return nil, fmt.Errorf("JSON response does not have %s field", rootNode) + } + + return &t, nil } From ec7976e09228ee96bc34bb162533cfba87570f83 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 08:02:29 +0200 Subject: [PATCH 13/55] Add UpdateStatusPagePost function --- status_page.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/status_page.go b/status_page.go index 72949112..bcdfd2ec 100644 --- a/status_page.go +++ b/status_page.go @@ -286,7 +286,7 @@ func (c *Client) ListStatusPagePosts(id string, o ListStatusPagePostOptions) (*L return &result, nil } -// CreateStatusPagePost create a Post for a Status Page by Status Page ID +// CreateStatusPagePost creates a Post for a Status Page by Status Page ID func (c *Client) CreateStatusPagePost(id string, p StatusPagePost) (*StatusPagePost, error) { h := map[string]string{ "X-EARLY-ACCESS": "status-pages-early-access", @@ -307,6 +307,18 @@ func (c *Client) GetStatusPagePost(statusPageID string, postID string) (*StatusP return getStatusPagePostFromResponse(c, resp, err) } +// UpdateStatusPagePost updates a Post for a Status Page by Status Page ID +func (c *Client) UpdateStatusPagePost(statusPageID string, postID string, p StatusPagePost) (*StatusPagePost, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + d := map[string]StatusPagePost{ + "post": p, + } + resp, err := c.put(context.Background(), "/status_pages/"+statusPageID+"/posts/"+postID, d, h) + return getStatusPagePostFromResponse(c, resp, err) +} + func getStatusPageImpactFromResponse(c *Client, resp *http.Response, err error) (*StatusPageImpact, error) { if err != nil { return nil, err From de8965865d2c65f29b0f45a34756389db68de83a Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 08:09:30 +0200 Subject: [PATCH 14/55] Add DeleteStatusPagePost function --- status_page.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/status_page.go b/status_page.go index bcdfd2ec..6d23e534 100644 --- a/status_page.go +++ b/status_page.go @@ -319,6 +319,16 @@ func (c *Client) UpdateStatusPagePost(statusPageID string, postID string, p Stat return getStatusPagePostFromResponse(c, resp, err) } +// DeleteStatusPagePost deletes a Post for a Status Page by Status Page ID +func (c *Client) DeleteStatusPagePost(statusPageID string, postID string) (*StatusPagePost, 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", + } + resp, err := c.do(context.Background(), http.MethodDelete, "/status_pages/"+statusPageID+"/posts/"+postID, nil, h) + return getStatusPagePostFromResponse(c, resp, err) +} + func getStatusPageImpactFromResponse(c *Client, resp *http.Response, err error) (*StatusPageImpact, error) { if err != nil { return nil, err From c811fff4112ad4d02e578c333e90a0d4e9504863 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 08:18:27 +0200 Subject: [PATCH 15/55] Add ListStatusPagePostUpdates function --- status_page.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/status_page.go b/status_page.go index 6d23e534..5619677a 100644 --- a/status_page.go +++ b/status_page.go @@ -64,7 +64,7 @@ type StatusPagePost struct { Title string StartsAt string EndsAt string - Updates []StatusPageUpdate + Updates []StatusPagePostUpdate } type LinkedResource struct { @@ -77,7 +77,7 @@ type PostMortem struct { Self string } -type StatusPageUpdate struct { +type StatusPagePostUpdate struct { ID string Self string Message string @@ -138,6 +138,12 @@ type ListStatusPagePostsResponse struct { StatusPagePosts []StatusPagePost `json:"posts"` } +// ListStatusPagePostUpdatesResponse is the data structure returned from calling the ListStatusPagePostUpdates API endpoint. +type ListStatusPagePostUpdatesResponse struct { + APIListObject + StatusPagePostUpdates []StatusPagePostUpdate `json:"post_updates"` +} + // ListStatusPages lists the given types of status pages func (c *Client) ListStatusPages(statusPageType string) (*ListStatusPagesResponse, error) { h := map[string]string{ @@ -329,6 +335,24 @@ func (c *Client) DeleteStatusPagePost(statusPageID string, postID string) (*Stat return getStatusPagePostFromResponse(c, resp, err) } +// ListStatusPagePostUpdates lists the post updates for the specified status page and post +func (c *Client) ListStatusPagePostUpdates(statusPageID, string, postID string, reviewedStatus string) (*ListStatusPagePostUpdatesResponse, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + resp, err := c.get(context.Background(), "/status_pages/"+statusPageID+"/posts/"+postID+"/post_updates?reviewed_status="+reviewedStatus, h) + if err != nil { + return nil, err + } + + var result ListStatusPagePostUpdatesResponse + if err := c.decodeJSON(resp, &result); err != nil { + return nil, err + } + + return &result, nil +} + func getStatusPageImpactFromResponse(c *Client, resp *http.Response, err error) (*StatusPageImpact, error) { if err != nil { return nil, err From fe61be188510fbfbc48c5004a4515fbff73641e7 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 08:21:31 +0200 Subject: [PATCH 16/55] Add CreateStatusPagePostUpdate function --- status_page.go | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/status_page.go b/status_page.go index 5619677a..fdccf799 100644 --- a/status_page.go +++ b/status_page.go @@ -336,7 +336,7 @@ func (c *Client) DeleteStatusPagePost(statusPageID string, postID string) (*Stat } // ListStatusPagePostUpdates lists the post updates for the specified status page and post -func (c *Client) ListStatusPagePostUpdates(statusPageID, string, postID string, reviewedStatus string) (*ListStatusPagePostUpdatesResponse, error) { +func (c *Client) ListStatusPagePostUpdates(statusPageID string, postID string, reviewedStatus string) (*ListStatusPagePostUpdatesResponse, error) { h := map[string]string{ "X-EARLY-ACCESS": "status-pages-early-access", } @@ -353,6 +353,18 @@ func (c *Client) ListStatusPagePostUpdates(statusPageID, string, postID string, return &result, nil } +// CreateStatusPagePostUpdate creates an Post Update for a Status Page by Status Page ID and Post ID +func (c *Client) CreateStatusPagePostUpdate(statusPageID string, postID string, u StatusPagePostUpdate) (*StatusPagePostUpdate, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + d := map[string]StatusPagePostUpdate{ + "post_update": u, + } + resp, err := c.post(context.Background(), "/status_pages/"+statusPageID+"/posts/"+postID+"/post_updates", d, h) + return getStatusPagePostUpdateFromResponse(c, resp, err) +} + func getStatusPageImpactFromResponse(c *Client, resp *http.Response, err error) (*StatusPageImpact, error) { if err != nil { return nil, err @@ -452,3 +464,23 @@ func getStatusPagePostFromResponse(c *Client, resp *http.Response, err error) (* return &t, nil } + +func getStatusPagePostUpdateFromResponse(c *Client, resp *http.Response, err error) (*StatusPagePostUpdate, error) { + if err != nil { + return nil, err + } + + var target map[string]StatusPagePostUpdate + if dErr := c.decodeJSON(resp, &target); dErr != nil { + return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) + } + + const rootNode = "post_update" + + t, nodeOK := target[rootNode] + if !nodeOK { + return nil, fmt.Errorf("JSON response does not have %s field", rootNode) + } + + return &t, nil +} From 2e2c92d5c45d151f200b178f552624e362e8019d Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 08:23:32 +0200 Subject: [PATCH 17/55] Add GetStatusPagePostUpdate function --- status_page.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/status_page.go b/status_page.go index fdccf799..120f1958 100644 --- a/status_page.go +++ b/status_page.go @@ -365,6 +365,15 @@ func (c *Client) CreateStatusPagePostUpdate(statusPageID string, postID string, return getStatusPagePostUpdateFromResponse(c, resp, err) } +// GetStatusPagePostUpdate gets the specified status page post update +func (c *Client) GetStatusPagePostUpdate(statusPageID string, postID string, postUpdateID string) (*StatusPagePostUpdate, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + resp, err := c.get(context.Background(), "/status_pages/"+statusPageID+"/posts/"+postID+"/post_updates/"+postUpdateID, h) + return getStatusPagePostUpdateFromResponse(c, resp, err) +} + func getStatusPageImpactFromResponse(c *Client, resp *http.Response, err error) (*StatusPageImpact, error) { if err != nil { return nil, err From f14428160495b9928f49b5e68fbc28925cb3d691 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 08:25:12 +0200 Subject: [PATCH 18/55] Add UpdateStatusPagePostUpdate function --- status_page.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/status_page.go b/status_page.go index 120f1958..576f0991 100644 --- a/status_page.go +++ b/status_page.go @@ -374,6 +374,18 @@ func (c *Client) GetStatusPagePostUpdate(statusPageID string, postID string, pos return getStatusPagePostUpdateFromResponse(c, resp, err) } +// UpdateStatusPagePostUpdate updates a Post Update for a Status Page by Status Page ID and Post ID +func (c *Client) UpdateStatusPagePostUpdate(statusPageID string, postID string, postUpdateID string, p StatusPagePostUpdate) (*StatusPagePostUpdate, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + d := map[string]StatusPagePostUpdate{ + "post": p, + } + resp, err := c.put(context.Background(), "/status_pages/"+statusPageID+"/posts/"+postID+"/post_updates/"+postUpdateID, d, h) + return getStatusPagePostUpdateFromResponse(c, resp, err) +} + func getStatusPageImpactFromResponse(c *Client, resp *http.Response, err error) (*StatusPageImpact, error) { if err != nil { return nil, err From 67214cb5e3466d10eb5ed4bff9b63e50533d433a Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 08:26:46 +0200 Subject: [PATCH 19/55] Add DeleteStatusPagePostUpdate function --- status_page.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/status_page.go b/status_page.go index 576f0991..d076f8e5 100644 --- a/status_page.go +++ b/status_page.go @@ -386,6 +386,16 @@ func (c *Client) UpdateStatusPagePostUpdate(statusPageID string, postID string, return getStatusPagePostUpdateFromResponse(c, resp, err) } +// DeleteStatusPagePostUpdate deletes a Post Update for a Status Page by Status Page ID and Post ID +func (c *Client) DeleteStatusPagePostUpdate(statusPageID string, postID string, postUpdateID string) (*StatusPagePostUpdate, 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", + } + resp, err := c.do(context.Background(), http.MethodDelete, "/status_pages/"+statusPageID+"/posts/"+postID+"/post_updates/"+postUpdateID, nil, h) + return getStatusPagePostUpdateFromResponse(c, resp, err) +} + func getStatusPageImpactFromResponse(c *Client, resp *http.Response, err error) (*StatusPageImpact, error) { if err != nil { return nil, err From d62a17aa41bb60a1149140493d83b4db5f9b1b04 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 08:30:32 +0200 Subject: [PATCH 20/55] Add GetStatusPagePostPostMortem function --- status_page.go | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/status_page.go b/status_page.go index d076f8e5..649e8624 100644 --- a/status_page.go +++ b/status_page.go @@ -73,8 +73,11 @@ type LinkedResource struct { } type PostMortem struct { - ID string - Self string + ID string + Self string + NotifySubscribers bool + ReportedAt string + Type string } type StatusPagePostUpdate struct { @@ -396,6 +399,15 @@ func (c *Client) DeleteStatusPagePostUpdate(statusPageID string, postID string, return getStatusPagePostUpdateFromResponse(c, resp, err) } +// 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) +} + func getStatusPageImpactFromResponse(c *Client, resp *http.Response, err error) (*StatusPageImpact, error) { if err != nil { return nil, err @@ -515,3 +527,23 @@ func getStatusPagePostUpdateFromResponse(c *Client, resp *http.Response, err err return &t, nil } + +func getStatusPagePostPostMortemFromResponse(c *Client, resp *http.Response, err error) (*PostMortem, error) { + if err != nil { + return nil, err + } + + var target map[string]PostMortem + if dErr := c.decodeJSON(resp, &target); dErr != nil { + return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) + } + + const rootNode = "postmortem" + + t, nodeOK := target[rootNode] + if !nodeOK { + return nil, fmt.Errorf("JSON response does not have %s field", rootNode) + } + + return &t, nil +} From 4727923680375d145e016739283fe3e87e8e1dbc Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 08:32:37 +0200 Subject: [PATCH 21/55] Add CreateStatusPagePostPostMortem function --- status_page.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/status_page.go b/status_page.go index 649e8624..e3c4ad54 100644 --- a/status_page.go +++ b/status_page.go @@ -408,6 +408,18 @@ func (c *Client) GetStatusPagePostPostMortem(statusPageID string, postID string) 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) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + 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) +} + func getStatusPageImpactFromResponse(c *Client, resp *http.Response, err error) (*StatusPageImpact, error) { if err != nil { return nil, err From c24446931404e7ce75e953a63be113a3ebc1837e Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 08:34:43 +0200 Subject: [PATCH 22/55] Add UpdateStatusPagePostPostMortem function --- status_page.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/status_page.go b/status_page.go index e3c4ad54..7bd83246 100644 --- a/status_page.go +++ b/status_page.go @@ -378,12 +378,12 @@ func (c *Client) GetStatusPagePostUpdate(statusPageID string, postID string, pos } // UpdateStatusPagePostUpdate updates a Post Update for a Status Page by Status Page ID and Post ID -func (c *Client) UpdateStatusPagePostUpdate(statusPageID string, postID string, postUpdateID string, p StatusPagePostUpdate) (*StatusPagePostUpdate, error) { +func (c *Client) UpdateStatusPagePostUpdate(statusPageID string, postID string, postUpdateID string, u StatusPagePostUpdate) (*StatusPagePostUpdate, error) { h := map[string]string{ "X-EARLY-ACCESS": "status-pages-early-access", } d := map[string]StatusPagePostUpdate{ - "post": p, + "post_update": u, } resp, err := c.put(context.Background(), "/status_pages/"+statusPageID+"/posts/"+postID+"/post_updates/"+postUpdateID, d, h) return getStatusPagePostUpdateFromResponse(c, resp, err) @@ -420,6 +420,18 @@ func (c *Client) CreateStatusPagePostPostMortem(statusPageID string, postID stri 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) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + 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) +} + func getStatusPageImpactFromResponse(c *Client, resp *http.Response, err error) (*StatusPageImpact, error) { if err != nil { return nil, err From 65f66ea257c7afc4605736b596a5bfde45c371db Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 08:40:59 +0200 Subject: [PATCH 23/55] Add DeleteStatusPagePostPostMortem function --- status_page.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/status_page.go b/status_page.go index 7bd83246..e8864068 100644 --- a/status_page.go +++ b/status_page.go @@ -432,6 +432,16 @@ func (c *Client) UpdateStatusPagePostPostMortem(statusPageID string, postID stri 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 { + /* 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", + } + _, err := c.do(context.Background(), http.MethodDelete, "/status_pages/"+statusPageID+"/posts/"+postID+"/postmortem", nil, h) + return err +} + func getStatusPageImpactFromResponse(c *Client, resp *http.Response, err error) (*StatusPageImpact, error) { if err != nil { return nil, err From 0a393f4e108c2c43d9599a69de4adbc361b5f169 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 08:42:13 +0200 Subject: [PATCH 24/55] Fix returnables from delete functions --- status_page.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/status_page.go b/status_page.go index e8864068..ec56f89d 100644 --- a/status_page.go +++ b/status_page.go @@ -329,13 +329,13 @@ func (c *Client) UpdateStatusPagePost(statusPageID string, postID string, p Stat } // DeleteStatusPagePost deletes a Post for a Status Page by Status Page ID -func (c *Client) DeleteStatusPagePost(statusPageID string, postID string) (*StatusPagePost, error) { +func (c *Client) DeleteStatusPagePost(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", } - resp, err := c.do(context.Background(), http.MethodDelete, "/status_pages/"+statusPageID+"/posts/"+postID, nil, h) - return getStatusPagePostFromResponse(c, resp, err) + _, err := c.do(context.Background(), http.MethodDelete, "/status_pages/"+statusPageID+"/posts/"+postID, nil, h) + return err } // ListStatusPagePostUpdates lists the post updates for the specified status page and post @@ -390,13 +390,13 @@ func (c *Client) UpdateStatusPagePostUpdate(statusPageID string, postID string, } // DeleteStatusPagePostUpdate deletes a Post Update for a Status Page by Status Page ID and Post ID -func (c *Client) DeleteStatusPagePostUpdate(statusPageID string, postID string, postUpdateID string) (*StatusPagePostUpdate, error) { +func (c *Client) DeleteStatusPagePostUpdate(statusPageID string, postID string, postUpdateID 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", } - resp, err := c.do(context.Background(), http.MethodDelete, "/status_pages/"+statusPageID+"/posts/"+postID+"/post_updates/"+postUpdateID, nil, h) - return getStatusPagePostUpdateFromResponse(c, resp, err) + _, err := c.do(context.Background(), http.MethodDelete, "/status_pages/"+statusPageID+"/posts/"+postID+"/post_updates/"+postUpdateID, nil, h) + return err } // GetStatusPagePostPostMortem gets the specified status page post post-mortem From 44764eb86e5065271eb490ba98916d5210269a4a Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 08:50:49 +0200 Subject: [PATCH 25/55] Add ListStatusPageSubscriptions function --- status_page.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/status_page.go b/status_page.go index ec56f89d..c2785dd5 100644 --- a/status_page.go +++ b/status_page.go @@ -99,12 +99,33 @@ type StatusPagePostUpdateImpact struct { Severity StatusPageSeverity } +type StatusPageSubscription struct { + Channel string + Contact string + ID string + Self string + Status string + StatusPage StatusPage + SubscribableObject SubscribableObject + Type string +} + +type SubscribableObject struct { + ID string + Type string +} + type ListStatusPagePostOptions struct { PostType string `url:"post_type,omitempty"` ReviewedStatus string `url:"reviewed_status,omitempty"` Statuses []StatusPageStatus `url:"statuses,omitempty"` } +type ListStatusPageSubscriptionsOptions struct { + Channel string + Status string +} + // ListStatusPagesResponse is the data structure returned from calling the ListStatusPages API endpoint. type ListStatusPagesResponse struct { APIListObject @@ -147,6 +168,12 @@ type ListStatusPagePostUpdatesResponse struct { StatusPagePostUpdates []StatusPagePostUpdate `json:"post_updates"` } +// ListStatusPageSubscriptionsResponse is the data structure returned from calling the ListStatusPageSubscriptions API endpoint. +type ListStatusPageSubscriptionsResponse struct { + APIListObject + StatusPageSubscriptions []StatusPageSubscription `json:"subscriptions"` +} + // ListStatusPages lists the given types of status pages func (c *Client) ListStatusPages(statusPageType string) (*ListStatusPagesResponse, error) { h := map[string]string{ @@ -442,6 +469,28 @@ func (c *Client) DeleteStatusPagePostPostMortem(statusPageID string, postID stri return err } +// ListStatusPageSubscriptions lists the subscriptions for the specified status page +func (c *Client) ListStatusPageSubscriptions(id string, o ListStatusPageSubscriptionsOptions) (*ListStatusPageSubscriptionsResponse, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + v, err := query.Values(o) + if err != nil { + return nil, err + } + resp, err := c.get(context.Background(), "/status_pages/"+id+"/subscriptions?"+v.Encode(), h) + if err != nil { + return nil, err + } + + var result ListStatusPageSubscriptionsResponse + if err := c.decodeJSON(resp, &result); err != nil { + return nil, err + } + + return &result, nil +} + func getStatusPageImpactFromResponse(c *Client, resp *http.Response, err error) (*StatusPageImpact, error) { if err != nil { return nil, err From 324ee3beafe223f3c32e1acd3135d7ac92fd3fbf Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 08:53:19 +0200 Subject: [PATCH 26/55] Add CreateStatusPageSubscription function --- status_page.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/status_page.go b/status_page.go index c2785dd5..b71e27df 100644 --- a/status_page.go +++ b/status_page.go @@ -491,6 +491,18 @@ func (c *Client) ListStatusPageSubscriptions(id string, o ListStatusPageSubscrip return &result, nil } +// CreateStatusPageSubscription creates a Subscription for a Status Page by Status Page ID +func (c *Client) CreateStatusPageSubscription(statusPageID string, s StatusPageSubscription) (*StatusPageSubscription, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + d := map[string]StatusPageSubscription{ + "subscription": s, + } + resp, err := c.post(context.Background(), "/status_pages/"+statusPageID+"/subscriptions", d, h) + return getStatusPageSubscriptionFromResponse(c, resp, err) +} + func getStatusPageImpactFromResponse(c *Client, resp *http.Response, err error) (*StatusPageImpact, error) { if err != nil { return nil, err @@ -630,3 +642,23 @@ func getStatusPagePostPostMortemFromResponse(c *Client, resp *http.Response, err return &t, nil } + +func getStatusPageSubscriptionFromResponse(c *Client, resp *http.Response, err error) (*StatusPageSubscription, error) { + if err != nil { + return nil, err + } + + var target map[string]StatusPageSubscription + if dErr := c.decodeJSON(resp, &target); dErr != nil { + return nil, fmt.Errorf("Could not decode JSON response: %v", dErr) + } + + const rootNode = "subscription" + + t, nodeOK := target[rootNode] + if !nodeOK { + return nil, fmt.Errorf("JSON response does not have %s field", rootNode) + } + + return &t, nil +} From e82a8276497728a7212258992f4b043694dd60d8 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 08:55:06 +0200 Subject: [PATCH 27/55] Add GetStatusPageSubscription function --- status_page.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/status_page.go b/status_page.go index b71e27df..743db9e4 100644 --- a/status_page.go +++ b/status_page.go @@ -503,6 +503,15 @@ func (c *Client) CreateStatusPageSubscription(statusPageID string, s StatusPageS return getStatusPageSubscriptionFromResponse(c, resp, err) } +// GetStatusPageSubscription gets the Subscription for a Status Page by Status Page ID and Subscription ID. +func (c *Client) GetStatusPageSubscription(statusPageID string, subscriptionID string) (*StatusPageSubscription, error) { + h := map[string]string{ + "X-EARLY-ACCESS": "status-pages-early-access", + } + resp, err := c.get(context.Background(), "/status_pages/"+statusPageID+"/subscriptions/"+subscriptionID, h) + return getStatusPageSubscriptionFromResponse(c, resp, err) +} + func getStatusPageImpactFromResponse(c *Client, resp *http.Response, err error) (*StatusPageImpact, error) { if err != nil { return nil, err From 604e2c519318bc79489fc2c8c4269eb7ad67ab76 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 08:56:26 +0200 Subject: [PATCH 28/55] Add DeleteStatusPageSubscription function --- status_page.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/status_page.go b/status_page.go index 743db9e4..fbbffdcd 100644 --- a/status_page.go +++ b/status_page.go @@ -512,6 +512,16 @@ func (c *Client) GetStatusPageSubscription(statusPageID string, subscriptionID s return getStatusPageSubscriptionFromResponse(c, resp, err) } +// DeleteStatusPageSubscription deletes a Subscription for a Status Page by Status Page ID and Subscription ID. +func (c *Client) DeleteStatusPageSubscription(statusPageID string, subscriptionID 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", + } + _, err := c.do(context.Background(), http.MethodDelete, "/status_pages/"+statusPageID+"/subscriptions/"+subscriptionID, nil, h) + return err +} + func getStatusPageImpactFromResponse(c *Client, resp *http.Response, err error) (*StatusPageImpact, error) { if err != nil { return nil, err From ffbc981c29da7da30aae3a5dc762f8712589eab7 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 09:27:09 +0200 Subject: [PATCH 29/55] Test for ListStatusPages --- status_page.go | 24 ++++++++++++++++-------- status_page_test.go | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 status_page_test.go diff --git a/status_page.go b/status_page.go index fbbffdcd..f12f7cb9 100644 --- a/status_page.go +++ b/status_page.go @@ -9,12 +9,12 @@ import ( ) type StatusPage struct { - ID string - Name string - PublishedAt string - StatusPageType string - URL string - Type string + ID string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + PublishedAt string `json:"published_at,omitempty"` + StatusPageType string `json:"status_page_type,omitempty"` + URL string `json:"url,omitempty"` + Type string `json:"type,omitempty"` } type StatusPageImpact struct { @@ -115,6 +115,10 @@ type SubscribableObject struct { Type string } +type ListStatusPageOptions struct { + StatusPageType string `url:"status_page_type,omitempty"` +} + type ListStatusPagePostOptions struct { PostType string `url:"post_type,omitempty"` ReviewedStatus string `url:"reviewed_status,omitempty"` @@ -175,11 +179,15 @@ type ListStatusPageSubscriptionsResponse struct { } // ListStatusPages lists the given types of status pages -func (c *Client) ListStatusPages(statusPageType string) (*ListStatusPagesResponse, error) { +func (c *Client) ListStatusPages(o ListStatusPageOptions) (*ListStatusPagesResponse, error) { h := map[string]string{ "X-EARLY-ACCESS": "status-pages-early-access", } - resp, err := c.get(context.Background(), "/status_pages?status_page_type="+statusPageType, h) + v, err := query.Values(o) + if err != nil { + return nil, err + } + resp, err := c.get(context.Background(), "/status_pages?"+v.Encode(), h) if err != nil { return nil, err } diff --git a/status_page_test.go b/status_page_test.go new file mode 100644 index 00000000..02656f90 --- /dev/null +++ b/status_page_test.go @@ -0,0 +1,41 @@ +package pagerduty + +import ( + "net/http" + "testing" +) + +// ListTags +func TestStatusPage_List(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testEqual(t, r.URL.Query()["status_page_type"], []string{"public"}) + _, _ = w.Write([]byte(`{"status_pages": [{"id": "1","name":"MyStatusPage","published_at":"2024-02-12T09:23:23Z","status_page_type":"public","url":"https://mypagerduty"}]}`)) + }) + + client := defaultTestClient(server.URL, "foo") + opts := ListStatusPageOptions{ + StatusPageType: "public", + } + res, err := client.ListStatusPages(opts) + if err != nil { + t.Fatal(err) + } + want := &ListStatusPagesResponse{ + APIListObject: APIListObject{}, + StatusPages: []StatusPage{ + { + ID: "1", + Name: "MyStatusPage", + PublishedAt: "2024-02-12T09:23:23Z", + StatusPageType: "public", + URL: "https://mypagerduty", + }, + }, + } + + testEqual(t, want, res) +} From 691581a3d317367081ab931e9e3ceb416d4a80f5 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 09:38:15 +0200 Subject: [PATCH 30/55] Test for ListStatusPageImpacts --- status_page.go | 24 ++++++++++++++++-------- status_page_test.go | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/status_page.go b/status_page.go index f12f7cb9..d565cc34 100644 --- a/status_page.go +++ b/status_page.go @@ -18,12 +18,12 @@ type StatusPage struct { } type StatusPageImpact struct { - ID string - Self string - Description string - PostType string - StatusPage StatusPage - Type string + ID string `json:"id,omitempty"` + Self string `json:"self,omitempty"` + Description string `json:"description,omitempty"` + PostType string `json:"post_type,omitempty"` + StatusPage StatusPage `json:"status_page,omitempty"` + Type string `json:"type,omitempty"` } type StatusPageService struct { @@ -119,6 +119,10 @@ type ListStatusPageOptions struct { StatusPageType string `url:"status_page_type,omitempty"` } +type ListStatusPageImpactOptions struct { + PostType string `url:"post_type,omitempty"` +} + type ListStatusPagePostOptions struct { PostType string `url:"post_type,omitempty"` ReviewedStatus string `url:"reviewed_status,omitempty"` @@ -201,11 +205,15 @@ func (c *Client) ListStatusPages(o ListStatusPageOptions) (*ListStatusPagesRespo } // ListStatusPageImpacts lists the given types of impacts for the specified status page -func (c *Client) ListStatusPageImpacts(id string, postType string) (*ListStatusPageImpactsResponse, error) { +func (c *Client) ListStatusPageImpacts(id string, o ListStatusPageImpactOptions) (*ListStatusPageImpactsResponse, error) { h := map[string]string{ "X-EARLY-ACCESS": "status-pages-early-access", } - resp, err := c.get(context.Background(), "/status_pages/"+id+"/impacts?post_type="+postType, h) + v, err := query.Values(o) + if err != nil { + return nil, err + } + resp, err := c.get(context.Background(), "/status_pages/"+id+"/impacts?"+v.Encode(), h) if err != nil { return nil, err } diff --git a/status_page_test.go b/status_page_test.go index 02656f90..590f0788 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -5,7 +5,7 @@ import ( "testing" ) -// ListTags +// ListStatusPages func TestStatusPage_List(t *testing.T) { setup() defer teardown() @@ -39,3 +39,43 @@ func TestStatusPage_List(t *testing.T) { testEqual(t, want, res) } + +// ListStatusPageImpacts +func TestStatusPage_ListImpacts(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/impacts", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testEqual(t, r.URL.Query()["post_type"], []string{"incident"}) + _, _ = w.Write([]byte(`{"impacts": [{"id": "1","description":"Extreme","post_type":"incident","status_page":{"id": "1","name":"MyStatusPage","published_at":"2024-02-12T09:23:23Z","status_page_type":"public","url":"https://mypagerduty"}}]}`)) + }) + + client := defaultTestClient(server.URL, "foo") + opts := ListStatusPageImpactOptions{ + PostType: "incident", + } + res, err := client.ListStatusPageImpacts("1", opts) + if err != nil { + t.Fatal(err) + } + want := &ListStatusPageImpactsResponse{ + APIListObject: APIListObject{}, + StatusPageImpacts: []StatusPageImpact{ + { + ID: "1", + Description: "Extreme", + PostType: "incident", + StatusPage: StatusPage{ + ID: "1", + Name: "MyStatusPage", + PublishedAt: "2024-02-12T09:23:23Z", + StatusPageType: "public", + URL: "https://mypagerduty", + }, + }, + }, + } + + testEqual(t, want, res) +} From 1007d061363434b3452c771d5dac4100794ae290 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 09:43:08 +0200 Subject: [PATCH 31/55] Test for GetStatusPageImpact --- status_page_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/status_page_test.go b/status_page_test.go index 590f0788..1a7d804a 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -79,3 +79,34 @@ func TestStatusPage_ListImpacts(t *testing.T) { testEqual(t, want, res) } + +// GetStatusPageImpact +func TestStatusPage_GetImpact(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/impacts/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + _, _ = w.Write([]byte(`{"impact": {"id": "1","description":"Extreme","post_type":"incident","status_page":{"id": "1","name":"MyStatusPage","published_at":"2024-02-12T09:23:23Z","status_page_type":"public","url":"https://mypagerduty"}}}`)) + }) + + client := defaultTestClient(server.URL, "foo") + res, err := client.GetStatusPageImpact("1", "1") + if err != nil { + t.Fatal(err) + } + want := &StatusPageImpact{ + ID: "1", + Description: "Extreme", + PostType: "incident", + StatusPage: StatusPage{ + ID: "1", + Name: "MyStatusPage", + PublishedAt: "2024-02-12T09:23:23Z", + StatusPageType: "public", + URL: "https://mypagerduty", + }, + } + + testEqual(t, want, res) +} From 90a0914463f461d0d3219da439fd2b316b8419d9 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 09:49:38 +0200 Subject: [PATCH 32/55] Test for ListStatusPageServices --- status_page.go | 12 ++++++------ status_page_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/status_page.go b/status_page.go index d565cc34..f87e5fb9 100644 --- a/status_page.go +++ b/status_page.go @@ -27,12 +27,12 @@ type StatusPageImpact struct { } type StatusPageService struct { - ID string - Self string - Name string - StatusPage StatusPage - BusinessService Service - Type string + ID string `json:"id,omitempty"` + Self string `json:"self,omitempty"` + Name string `json:"name,omitempty"` + StatusPage StatusPage `json:"status_page,omitempty"` + BusinessService Service `json:"business_service,omitempty"` + Type string `json:"type,omitempty"` } type StatusPageSeverity struct { diff --git a/status_page_test.go b/status_page_test.go index 1a7d804a..e15d987b 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -110,3 +110,42 @@ func TestStatusPage_GetImpact(t *testing.T) { testEqual(t, want, res) } + +// ListStatusPageServices +func TestStatusPage_ListServices(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/services", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + _, _ = w.Write([]byte(`{"services": [{"id": "1","name":"MyService","status_page":{"id": "1","name":"MyStatusPage","published_at":"2024-02-12T09:23:23Z","status_page_type":"public","url":"https://mypagerduty"},"business_service":{"name":"MyService"}}]}`)) + }) + + client := defaultTestClient(server.URL, "foo") + + res, err := client.ListStatusPageServices("1") + if err != nil { + t.Fatal(err) + } + want := &ListStatusPageServicesResponse{ + APIListObject: APIListObject{}, + StatusPageServices: []StatusPageService{ + { + ID: "1", + Name: "MyService", + StatusPage: StatusPage{ + ID: "1", + Name: "MyStatusPage", + PublishedAt: "2024-02-12T09:23:23Z", + StatusPageType: "public", + URL: "https://mypagerduty", + }, + BusinessService: Service{ + Name: "MyService", + }, + }, + }, + } + + testEqual(t, want, res) +} From 16081e2e3f981b7fb144b02c4fe6f0ad50aeb6a9 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 09:52:45 +0200 Subject: [PATCH 33/55] Test for GetStatusPageService --- status_page_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/status_page_test.go b/status_page_test.go index e15d987b..3fc00148 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -149,3 +149,37 @@ func TestStatusPage_ListServices(t *testing.T) { testEqual(t, want, res) } + +// GetStatusPageService +func TestStatusPage_GetServices(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/services/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + _, _ = w.Write([]byte(`{"service": {"id": "1","name":"MyService","status_page":{"id": "1","name":"MyStatusPage","published_at":"2024-02-12T09:23:23Z","status_page_type":"public","url":"https://mypagerduty"},"business_service":{"name":"MyService"}}}`)) + }) + + client := defaultTestClient(server.URL, "foo") + + res, err := client.GetStatusPageService("1", "1") + if err != nil { + t.Fatal(err) + } + want := &StatusPageService{ + ID: "1", + Name: "MyService", + StatusPage: StatusPage{ + ID: "1", + Name: "MyStatusPage", + PublishedAt: "2024-02-12T09:23:23Z", + StatusPageType: "public", + URL: "https://mypagerduty", + }, + BusinessService: Service{ + Name: "MyService", + }, + } + + testEqual(t, want, res) +} From bca85e45b235bfa06bf9e71992353d666b0003b9 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 09:59:05 +0200 Subject: [PATCH 34/55] Test for ListStatusPageSeverities --- status_page.go | 24 ++++++++++++++++-------- status_page_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/status_page.go b/status_page.go index f87e5fb9..6ee3a250 100644 --- a/status_page.go +++ b/status_page.go @@ -36,12 +36,12 @@ type StatusPageService struct { } type StatusPageSeverity struct { - ID string - Self string - Description string - PostType string - StatusPage StatusPage - Type string + ID string `json:"id,omitempty"` + Self string `json:"self,omitempty"` + Description string `json:"description,omitempty"` + PostType string `json:"post_type,omitempty"` + StatusPage StatusPage `json:"status_page,omitempty"` + Type string `json:"type,omitempty"` } type StatusPageStatus struct { @@ -123,6 +123,10 @@ type ListStatusPageImpactOptions struct { PostType string `url:"post_type,omitempty"` } +type ListStatusPageSeveritiesOptions struct { + PostType string `url:"post_type,omitempty"` +} + type ListStatusPagePostOptions struct { PostType string `url:"post_type,omitempty"` ReviewedStatus string `url:"reviewed_status,omitempty"` @@ -263,11 +267,15 @@ func (c *Client) GetStatusPageService(statusPageID string, serviceID string) (*S } // ListStatusPageSeverities lists the severities for the specified status page -func (c *Client) ListStatusPageSeverities(id string, postType string) (*ListStatusPageSeveritiesResponse, error) { +func (c *Client) ListStatusPageSeverities(id string, o ListStatusPageSeveritiesOptions) (*ListStatusPageSeveritiesResponse, error) { h := map[string]string{ "X-EARLY-ACCESS": "status-pages-early-access", } - resp, err := c.get(context.Background(), "/status_pages/"+id+"/severities?post_type="+postType, h) + v, err := query.Values(o) + if err != nil { + return nil, err + } + resp, err := c.get(context.Background(), "/status_pages/"+id+"/severities?"+v.Encode(), h) if err != nil { return nil, err } diff --git a/status_page_test.go b/status_page_test.go index 3fc00148..d7d2fdc3 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -183,3 +183,43 @@ func TestStatusPage_GetServices(t *testing.T) { testEqual(t, want, res) } + +// ListStatusPageSeverities +func TestStatusPage_ListSeverities(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/severities", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + _, _ = w.Write([]byte(`{"severities": [{"id": "1","description":"Extreme","post_type":"incident","status_page":{"id": "1","name":"MyStatusPage","published_at":"2024-02-12T09:23:23Z","status_page_type":"public","url":"https://mypagerduty"}}]}`)) + }) + + client := defaultTestClient(server.URL, "foo") + opts := ListStatusPageSeveritiesOptions{ + PostType: "incident", + } + + res, err := client.ListStatusPageSeverities("1", opts) + if err != nil { + t.Fatal(err) + } + want := &ListStatusPageSeveritiesResponse{ + APIListObject: APIListObject{}, + StatusPageSeverities: []StatusPageSeverity{ + { + ID: "1", + Description: "Extreme", + PostType: "incident", + StatusPage: StatusPage{ + ID: "1", + Name: "MyStatusPage", + PublishedAt: "2024-02-12T09:23:23Z", + StatusPageType: "public", + URL: "https://mypagerduty", + }, + }, + }, + } + + testEqual(t, want, res) +} From 944be1202bfeff6e8bde9b36b2e50720ebf5be5d Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 10:01:39 +0200 Subject: [PATCH 35/55] Test for GetStatusPageSeverity --- status_page_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/status_page_test.go b/status_page_test.go index d7d2fdc3..eda3946a 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -223,3 +223,35 @@ func TestStatusPage_ListSeverities(t *testing.T) { testEqual(t, want, res) } + +// GetStatusPageSeverity +func TestStatusPage_GetSeverity(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/severities/1/", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + _, _ = w.Write([]byte(`{"severity": {"id": "1","description":"Extreme","post_type":"incident","status_page":{"id": "1","name":"MyStatusPage","published_at":"2024-02-12T09:23:23Z","status_page_type":"public","url":"https://mypagerduty"}}}`)) + }) + + client := defaultTestClient(server.URL, "foo") + + res, err := client.GetStatusPageSeverity("1", "1") + if err != nil { + t.Fatal(err) + } + want := &StatusPageSeverity{ + ID: "1", + Description: "Extreme", + PostType: "incident", + StatusPage: StatusPage{ + ID: "1", + Name: "MyStatusPage", + PublishedAt: "2024-02-12T09:23:23Z", + StatusPageType: "public", + URL: "https://mypagerduty", + }, + } + + testEqual(t, want, res) +} From d49141628928458a1075652e82c677bc0b02c319 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 10:20:28 +0200 Subject: [PATCH 36/55] Test for ListStatusPageStatuses --- status_page.go | 24 ++++++++++++++++-------- status_page_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 8 deletions(-) diff --git a/status_page.go b/status_page.go index 6ee3a250..768815b0 100644 --- a/status_page.go +++ b/status_page.go @@ -45,12 +45,12 @@ type StatusPageSeverity struct { } type StatusPageStatus struct { - ID string - Self string - Description string - PostType string - StatusPage StatusPage - Type string + ID string `json:"id,omitempty"` + Self string `json:"self,omitempty"` + Description string `json:"description,omitempty"` + PostType string `json:"post_type,omitempty"` + StatusPage StatusPage `json:"status_page,omitempty"` + Type string `json:"type,omitempty"` } type StatusPagePost struct { @@ -127,6 +127,10 @@ type ListStatusPageSeveritiesOptions struct { PostType string `url:"post_type,omitempty"` } +type ListStatusPageStatusesOptions struct { + PostType string `url:"post_type,omitempty"` +} + type ListStatusPagePostOptions struct { PostType string `url:"post_type,omitempty"` ReviewedStatus string `url:"reviewed_status,omitempty"` @@ -298,11 +302,15 @@ func (c *Client) GetStatusPageSeverity(statusPageID string, severityID string) ( } // ListStatusPageStatuses lists the statuses for the specified status page -func (c *Client) ListStatusPageStatuses(id string, postType string) (*ListStatusPageStatusesResponse, error) { +func (c *Client) ListStatusPageStatuses(id string, o ListStatusPageStatusesOptions) (*ListStatusPageStatusesResponse, error) { h := map[string]string{ "X-EARLY-ACCESS": "status-pages-early-access", } - resp, err := c.get(context.Background(), "/status_pages/"+id+"/statuses?post_type="+postType, h) + v, err := query.Values(o) + if err != nil { + return nil, err + } + resp, err := c.get(context.Background(), "/status_pages/"+id+"/statuses?"+v.Encode(), h) if err != nil { return nil, err } diff --git a/status_page_test.go b/status_page_test.go index eda3946a..8dc42fcd 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -191,6 +191,7 @@ func TestStatusPage_ListSeverities(t *testing.T) { mux.HandleFunc("/status_pages/1/severities", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") + testEqual(t, r.URL.Query()["post_type"], []string{"incident"}) _, _ = w.Write([]byte(`{"severities": [{"id": "1","description":"Extreme","post_type":"incident","status_page":{"id": "1","name":"MyStatusPage","published_at":"2024-02-12T09:23:23Z","status_page_type":"public","url":"https://mypagerduty"}}]}`)) }) @@ -255,3 +256,44 @@ func TestStatusPage_GetSeverity(t *testing.T) { testEqual(t, want, res) } + +// ListStatusPageStatuses +func TestStatusPage_ListStatuses(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/statuses", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testEqual(t, r.URL.Query()["post_type"], []string{"incident"}) + _, _ = w.Write([]byte(`{"statuses": [{"id": "1","description":"Extreme","post_type":"incident","status_page":{"id": "1","name":"MyStatusPage","published_at":"2024-02-12T09:23:23Z","status_page_type":"public","url":"https://mypagerduty"}}]}`)) + }) + + client := defaultTestClient(server.URL, "foo") + opts := ListStatusPageStatusesOptions{ + PostType: "incident", + } + + res, err := client.ListStatusPageStatuses("1", opts) + if err != nil { + t.Fatal(err) + } + want := &ListStatusPageStatusesResponse{ + APIListObject: APIListObject{}, + StatusPageStatuses: []StatusPageStatus{ + { + ID: "1", + Description: "Extreme", + PostType: "incident", + StatusPage: StatusPage{ + ID: "1", + Name: "MyStatusPage", + PublishedAt: "2024-02-12T09:23:23Z", + StatusPageType: "public", + URL: "https://mypagerduty", + }, + }, + }, + } + + testEqual(t, want, res) +} From e82fac2af32c607f5ab1101943f338bdae58248d Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 10:22:08 +0200 Subject: [PATCH 37/55] Test for GetStatusPageStatus --- status_page_test.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/status_page_test.go b/status_page_test.go index 8dc42fcd..6da45ddb 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -297,3 +297,35 @@ func TestStatusPage_ListStatuses(t *testing.T) { testEqual(t, want, res) } + +// GetStatusPageStatus +func TestStatusPage_GetStatus(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/statuses/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + _, _ = w.Write([]byte(`{"status": {"id": "1","description":"Extreme","post_type":"incident","status_page":{"id": "1","name":"MyStatusPage","published_at":"2024-02-12T09:23:23Z","status_page_type":"public","url":"https://mypagerduty"}}}`)) + }) + + client := defaultTestClient(server.URL, "foo") + + res, err := client.GetStatusPageStatus("1", "1") + if err != nil { + t.Fatal(err) + } + want := &StatusPageStatus{ + ID: "1", + Description: "Extreme", + PostType: "incident", + StatusPage: StatusPage{ + ID: "1", + Name: "MyStatusPage", + PublishedAt: "2024-02-12T09:23:23Z", + StatusPageType: "public", + URL: "https://mypagerduty", + }, + } + + testEqual(t, want, res) +} From 1e6f77835566c058f98e752b4de206b74563ed67 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 10:34:54 +0200 Subject: [PATCH 38/55] Test for ListStatusPagePosts --- status_page.go | 60 ++++++++++++++++++++++----------------------- status_page_test.go | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 30 deletions(-) diff --git a/status_page.go b/status_page.go index 768815b0..a7cd4db5 100644 --- a/status_page.go +++ b/status_page.go @@ -54,17 +54,17 @@ 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 { @@ -72,7 +72,7 @@ type LinkedResource struct { 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) } diff --git a/status_page_test.go b/status_page_test.go index 6da45ddb..53a7f50f 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -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) +} From 523001679f9768a7532d3f62f3288c60939ce50a Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 10:40:58 +0200 Subject: [PATCH 39/55] Test for CreateStatusPagePost --- status_page_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/status_page_test.go b/status_page_test.go index 53a7f50f..96f0de46 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -376,3 +376,47 @@ func TestStatusPage_ListPosts(t *testing.T) { testEqual(t, want, res) } + +// CreateStatusPagePost +func TestStatusPage_CreatePost(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/posts", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + _, _ = w.Write([]byte(`{"post": {"id": "1","post_type":"incident","status_page":{"id": "1","type":"status_page"},"title":"MyPost","starts_at":"2024-02-12T09:23:23Z","ends_at":"2024-02-12T09:23:23Z"}}`)) + }) + + client := defaultTestClient(server.URL, "foo") + + input := StatusPagePost{ + 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", + } + res, err := client.CreateStatusPagePost("1", input) + if err != nil { + t.Fatal(err) + } + want := &StatusPagePost{ + ID: "1", + PostType: "incident", + StatusPage: StatusPage{ + ID: "1", + Type: "status_page", + }, + Title: "MyPost", + StartsAt: "2024-02-12T09:23:23Z", + EndsAt: "2024-02-12T09:23:23Z", + } + + testEqual(t, want, res) +} From 32d1664cee608c930bbcb4b09aa091a564ce3f90 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 10:45:14 +0200 Subject: [PATCH 40/55] Test for GetStatusPagePost --- status_page.go | 1 + status_page_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/status_page.go b/status_page.go index a7cd4db5..2eb26e80 100644 --- a/status_page.go +++ b/status_page.go @@ -325,6 +325,7 @@ func (c *Client) ListStatusPageStatuses(id string, o ListStatusPageStatusesOptio // GetStatusPageStatus gets the specified status page status func (c *Client) GetStatusPageStatus(statusPageID string, statusID string) (*StatusPageStatus, error) { + /* Note: Does not currently support the include query parameter */ h := map[string]string{ "X-EARLY-ACCESS": "status-pages-early-access", } diff --git a/status_page_test.go b/status_page_test.go index 96f0de46..9089344e 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -420,3 +420,34 @@ func TestStatusPage_CreatePost(t *testing.T) { testEqual(t, want, res) } + +// GetStatusPagePost +func TestStatusPage_GetPost(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/posts/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + _, _ = w.Write([]byte(`{"post": {"id": "1","post_type":"incident","status_page":{"id": "1","type":"status_page"},"title":"MyPost","starts_at":"2024-02-12T09:23:23Z","ends_at":"2024-02-12T09:23:23Z"}}`)) + }) + + client := defaultTestClient(server.URL, "foo") + + res, err := client.GetStatusPagePost("1", "1") + if err != nil { + t.Fatal(err) + } + want := &StatusPagePost{ + ID: "1", + PostType: "incident", + StatusPage: StatusPage{ + ID: "1", + Type: "status_page", + }, + Title: "MyPost", + StartsAt: "2024-02-12T09:23:23Z", + EndsAt: "2024-02-12T09:23:23Z", + } + + testEqual(t, want, res) +} From 0cb6ba2c0b280349a71207e46710afafa069d6bf Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 10:46:34 +0200 Subject: [PATCH 41/55] Test for UpdateStatusPagePost --- status_page_test.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/status_page_test.go b/status_page_test.go index 9089344e..e1ad4563 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -451,3 +451,47 @@ func TestStatusPage_GetPost(t *testing.T) { testEqual(t, want, res) } + +// UpdateStatusPagePost +func TestStatusPage_UpdatePost(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/posts/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + _, _ = w.Write([]byte(`{"post": {"id": "1","post_type":"incident","status_page":{"id": "1","type":"status_page"},"title":"MyPost","starts_at":"2024-02-12T09:23:23Z","ends_at":"2024-02-12T09:23:23Z"}}`)) + }) + + client := defaultTestClient(server.URL, "foo") + + input := StatusPagePost{ + 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", + } + res, err := client.UpdateStatusPagePost("1", "1", input) + if err != nil { + t.Fatal(err) + } + want := &StatusPagePost{ + ID: "1", + PostType: "incident", + StatusPage: StatusPage{ + ID: "1", + Type: "status_page", + }, + Title: "MyPost", + StartsAt: "2024-02-12T09:23:23Z", + EndsAt: "2024-02-12T09:23:23Z", + } + + testEqual(t, want, res) +} From 5cea63cc54f3dd5d41dc388c31daddd0b64ea006 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 10:49:14 +0200 Subject: [PATCH 42/55] Test for DeleteStatusPagePost --- status_page_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/status_page_test.go b/status_page_test.go index e1ad4563..8011db19 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -495,3 +495,21 @@ func TestStatusPage_UpdatePost(t *testing.T) { testEqual(t, want, res) } + +// DeleteStatusPagePost +func TestStatusPage_DeletePost(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/posts/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + _, _ = w.Write([]byte(`{"post": {"id": "1","post_type":"incident","status_page":{"id": "1","type":"status_page"},"title":"MyPost","starts_at":"2024-02-12T09:23:23Z","ends_at":"2024-02-12T09:23:23Z"}}`)) + }) + + client := defaultTestClient(server.URL, "foo") + + err := client.DeleteStatusPagePost("1", "1") + if err != nil { + t.Fatal(err) + } +} From 076cac7910bbb23b8d3bb989cd5cee073c9408a4 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 11:10:25 +0200 Subject: [PATCH 43/55] Test for ListStatusPagePostUpdates --- status_page.go | 35 +++++++++++++++--------- status_page_test.go | 66 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 13 deletions(-) diff --git a/status_page.go b/status_page.go index 2eb26e80..24e95ac2 100644 --- a/status_page.go +++ b/status_page.go @@ -81,17 +81,18 @@ type Postmortem struct { } type StatusPagePostUpdate struct { - ID string - Self string - Message string - ReviewedStatus string - Status StatusPageStatus - Severity StatusPageSeverity - ImpactedServices []StatusPagePostUpdateImpact - UpdateFrequencyMS uint - NotifySubscribers bool - ReportedAt string - Type string + ID string `json:"id,omitempty"` + Self string `json:"self,omitempty"` + Message string `json:"message,omitempty"` + ReviewedStatus string `json:"reviewed_status,omitempty"` + Status StatusPageStatus `json:"status,omitempty"` + Severity StatusPageSeverity `json:"severity,omitempty"` + ImpactedServices []StatusPagePostUpdateImpact `json:"impacted_services,omitempty"` + UpdateFrequencyMS uint `json:"update_frequency_ms,omitempty"` + Post StatusPagePost `json:"post,omitempty"` + NotifySubscribers bool `json:"notify_subscribers,omitempty"` + ReportedAt string `json:"reported_at,omitempty"` + Type string `json:"type,omitempty"` } type StatusPagePostUpdateImpact struct { @@ -137,6 +138,10 @@ type ListStatusPagePostOptions struct { Status []string `url:"status,omitempty"` } +type ListStatusPagePostUpdateOptions struct { + ReviewedStatus string `url:"reviewed_status,omitempty"` +} + type ListStatusPageSubscriptionsOptions struct { Channel string Status string @@ -399,11 +404,15 @@ func (c *Client) DeleteStatusPagePost(statusPageID string, postID string) error } // ListStatusPagePostUpdates lists the post updates for the specified status page and post -func (c *Client) ListStatusPagePostUpdates(statusPageID string, postID string, reviewedStatus string) (*ListStatusPagePostUpdatesResponse, error) { +func (c *Client) ListStatusPagePostUpdates(statusPageID string, postID string, o ListStatusPagePostUpdateOptions) (*ListStatusPagePostUpdatesResponse, error) { h := map[string]string{ "X-EARLY-ACCESS": "status-pages-early-access", } - resp, err := c.get(context.Background(), "/status_pages/"+statusPageID+"/posts/"+postID+"/post_updates?reviewed_status="+reviewedStatus, h) + v, err := query.Values(o) + if err != nil { + return nil, err + } + resp, err := c.get(context.Background(), "/status_pages/"+statusPageID+"/posts/"+postID+"/post_updates?"+v.Encode(), h) if err != nil { return nil, err } diff --git a/status_page_test.go b/status_page_test.go index 8011db19..32d2a51c 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -513,3 +513,69 @@ func TestStatusPage_DeletePost(t *testing.T) { t.Fatal(err) } } + +// ListStatusPagePostUpdates +func TestStatusPage_ListPostUpdates(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/posts/1/post_updates", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testEqual(t, r.URL.Query()["reviewed_status"], []string{"approved"}) + _, _ = w.Write([]byte(`{ + "post_updates": [ + { + "id":"1", "message":"Hello world", "reviewed_status":"approved", "notify_subscribers":false, "impacted_services": [ + { + "impact":{ + "id":"1"," type":"status_page_impact" + }, + "service":{ + "id":"1", "type":"status_page_service" + } + }], + "post": { + "id":"1", "type":"status_page_post" + } + } + ] + }`)) + }) + + client := defaultTestClient(server.URL, "foo") + opts := ListStatusPagePostUpdateOptions{ + ReviewedStatus: "approved", + } + + res, err := client.ListStatusPagePostUpdates("1", "1", opts) + if err != nil { + t.Fatal(err) + } + want := &ListStatusPagePostUpdatesResponse{ + APIListObject: APIListObject{}, + StatusPagePostUpdates: []StatusPagePostUpdate{ + { + ID: "1", + Message: "Hello world", + ReviewedStatus: "approved", + ImpactedServices: []StatusPagePostUpdateImpact{ + { + Service: Service{ + APIObject: APIObject{ + ID: "1", + Type: "status_page_service", + }, + }, + }, + }, + NotifySubscribers: false, + Post: StatusPagePost{ + ID: "1", + Type: "status_page_post", + }, + }, + }, + } + + testEqual(t, want, res) +} From ff8dd535d392e712ad7553b9dc097375f9970956 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 12:34:01 +0200 Subject: [PATCH 44/55] Test for CreateStatusPagePostUpdate --- status_page_test.go | 120 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/status_page_test.go b/status_page_test.go index 32d2a51c..4486db0e 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -579,3 +579,123 @@ func TestStatusPage_ListPostUpdates(t *testing.T) { testEqual(t, want, res) } + +// CreateStatusPagePost +func TestStatusPage_CreatePostUpdate(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/posts/1/post_updates", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + _, _ = w.Write([]byte(`{ + "post_update": { + "id": "1", + "message": "Hello world", + "reviewed_status": "approved", + "notify_subscribers": false, + "update_frequency_ms": 30000, + "reported_at": "2024-02-12T09:23:23Z", + "impacted_services": [ + { + "severity": { + "id": "1", + "type": "status_page_severity" + }, + "service": { + "id": "1", + "type": "status_page_service" + } + } + ], + "status": { + "id": "1", + "type": "status_page_status" + }, + "severity": { + "id": "1", + "type": "status_page_severity" + }, + "post": { + "id": "1", + "type": "status_page_post" + } + } + }`)) + }) + + client := defaultTestClient(server.URL, "foo") + + input := StatusPagePostUpdate{ + Message: "Hello world", + NotifySubscribers: false, + ReportedAt: "2024-02-12T09:23:23Z", + UpdateFrequencyMS: 30000, + ReviewedStatus: "approved", + Post: StatusPagePost{ + ID: "1", + Type: "status_page_post", + }, + Status: StatusPageStatus{ + ID: "1", + Type: "status_page_status", + }, + Severity: StatusPageSeverity{ + ID: "1", + Type: "status_page_severity", + }, + ImpactedServices: []StatusPagePostUpdateImpact{ + { + Service: Service{ + APIObject: APIObject{ + ID: "1", + Type: "status_page_service", + }, + }, + Severity: StatusPageSeverity{ + ID: "1", + Type: "status_page_severity", + }, + }, + }, + } + res, err := client.CreateStatusPagePostUpdate("1", "1", input) + if err != nil { + t.Fatal(err) + } + want := &StatusPagePostUpdate{ + ID: "1", + Message: "Hello world", + NotifySubscribers: false, + ReportedAt: "2024-02-12T09:23:23Z", + UpdateFrequencyMS: 30000, + ReviewedStatus: "approved", + Post: StatusPagePost{ + ID: "1", + Type: "status_page_post", + }, + Status: StatusPageStatus{ + ID: "1", + Type: "status_page_status", + }, + Severity: StatusPageSeverity{ + ID: "1", + Type: "status_page_severity", + }, + ImpactedServices: []StatusPagePostUpdateImpact{ + { + Service: Service{ + APIObject: APIObject{ + ID: "1", + Type: "status_page_service", + }, + }, + Severity: StatusPageSeverity{ + ID: "1", + Type: "status_page_severity", + }, + }, + }, + } + + testEqual(t, want, res) +} From 97ffc2ed2d8a90a546f66c6fc05dc7728f53c475 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 12:36:22 +0200 Subject: [PATCH 45/55] Test for GetStatusPagePostUpdate --- status_page_test.go | 89 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/status_page_test.go b/status_page_test.go index 4486db0e..0dbe9521 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -580,7 +580,7 @@ func TestStatusPage_ListPostUpdates(t *testing.T) { testEqual(t, want, res) } -// CreateStatusPagePost +// CreateStatusPagePostUpdate func TestStatusPage_CreatePostUpdate(t *testing.T) { setup() defer teardown() @@ -699,3 +699,90 @@ func TestStatusPage_CreatePostUpdate(t *testing.T) { testEqual(t, want, res) } + +// GetStatusPagePostUpdate +func TestStatusPage_GetPostUpdate(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/posts/1/post_updates/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + _, _ = w.Write([]byte(`{ + "post_update": { + "id": "1", + "message": "Hello world", + "reviewed_status": "approved", + "notify_subscribers": false, + "update_frequency_ms": 30000, + "reported_at": "2024-02-12T09:23:23Z", + "impacted_services": [ + { + "severity": { + "id": "1", + "type": "status_page_severity" + }, + "service": { + "id": "1", + "type": "status_page_service" + } + } + ], + "status": { + "id": "1", + "type": "status_page_status" + }, + "severity": { + "id": "1", + "type": "status_page_severity" + }, + "post": { + "id": "1", + "type": "status_page_post" + } + } + }`)) + }) + + client := defaultTestClient(server.URL, "foo") + + res, err := client.GetStatusPagePostUpdate("1", "1", "1") + if err != nil { + t.Fatal(err) + } + want := &StatusPagePostUpdate{ + ID: "1", + Message: "Hello world", + NotifySubscribers: false, + ReportedAt: "2024-02-12T09:23:23Z", + UpdateFrequencyMS: 30000, + ReviewedStatus: "approved", + Post: StatusPagePost{ + ID: "1", + Type: "status_page_post", + }, + Status: StatusPageStatus{ + ID: "1", + Type: "status_page_status", + }, + Severity: StatusPageSeverity{ + ID: "1", + Type: "status_page_severity", + }, + ImpactedServices: []StatusPagePostUpdateImpact{ + { + Service: Service{ + APIObject: APIObject{ + ID: "1", + Type: "status_page_service", + }, + }, + Severity: StatusPageSeverity{ + ID: "1", + Type: "status_page_severity", + }, + }, + }, + } + + testEqual(t, want, res) +} From f91c6ac8d4c3cefa6710cb8a2274d2bffd5a1796 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 12:38:21 +0200 Subject: [PATCH 46/55] Test for UpdateStatusPagePostUpdate --- status_page_test.go | 120 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) diff --git a/status_page_test.go b/status_page_test.go index 0dbe9521..3a3f52cc 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -786,3 +786,123 @@ func TestStatusPage_GetPostUpdate(t *testing.T) { testEqual(t, want, res) } + +// UpdateStatusPagePostUpdate +func TestStatusPage_UpdatePostUpdate(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/posts/1/post_updates/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + _, _ = w.Write([]byte(`{ + "post_update": { + "id": "1", + "message": "Hello world", + "reviewed_status": "approved", + "notify_subscribers": false, + "update_frequency_ms": 30000, + "reported_at": "2024-02-12T09:23:23Z", + "impacted_services": [ + { + "severity": { + "id": "1", + "type": "status_page_severity" + }, + "service": { + "id": "1", + "type": "status_page_service" + } + } + ], + "status": { + "id": "1", + "type": "status_page_status" + }, + "severity": { + "id": "1", + "type": "status_page_severity" + }, + "post": { + "id": "1", + "type": "status_page_post" + } + } + }`)) + }) + + client := defaultTestClient(server.URL, "foo") + + input := StatusPagePostUpdate{ + Message: "Hello world", + NotifySubscribers: false, + ReportedAt: "2024-02-12T09:23:23Z", + UpdateFrequencyMS: 30000, + ReviewedStatus: "approved", + Post: StatusPagePost{ + ID: "1", + Type: "status_page_post", + }, + Status: StatusPageStatus{ + ID: "1", + Type: "status_page_status", + }, + Severity: StatusPageSeverity{ + ID: "1", + Type: "status_page_severity", + }, + ImpactedServices: []StatusPagePostUpdateImpact{ + { + Service: Service{ + APIObject: APIObject{ + ID: "1", + Type: "status_page_service", + }, + }, + Severity: StatusPageSeverity{ + ID: "1", + Type: "status_page_severity", + }, + }, + }, + } + res, err := client.UpdateStatusPagePostUpdate("1", "1", "1", input) + if err != nil { + t.Fatal(err) + } + want := &StatusPagePostUpdate{ + ID: "1", + Message: "Hello world", + NotifySubscribers: false, + ReportedAt: "2024-02-12T09:23:23Z", + UpdateFrequencyMS: 30000, + ReviewedStatus: "approved", + Post: StatusPagePost{ + ID: "1", + Type: "status_page_post", + }, + Status: StatusPageStatus{ + ID: "1", + Type: "status_page_status", + }, + Severity: StatusPageSeverity{ + ID: "1", + Type: "status_page_severity", + }, + ImpactedServices: []StatusPagePostUpdateImpact{ + { + Service: Service{ + APIObject: APIObject{ + ID: "1", + Type: "status_page_service", + }, + }, + Severity: StatusPageSeverity{ + ID: "1", + Type: "status_page_severity", + }, + }, + }, + } + + testEqual(t, want, res) +} From 2598971e519530a814b9da23e72080e45b18e2a7 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 12:40:23 +0200 Subject: [PATCH 47/55] Test for DeleteStatusPagePostUpdate --- status_page_test.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/status_page_test.go b/status_page_test.go index 3a3f52cc..33a73fd2 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -503,7 +503,6 @@ func TestStatusPage_DeletePost(t *testing.T) { mux.HandleFunc("/status_pages/1/posts/1", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "DELETE") - _, _ = w.Write([]byte(`{"post": {"id": "1","post_type":"incident","status_page":{"id": "1","type":"status_page"},"title":"MyPost","starts_at":"2024-02-12T09:23:23Z","ends_at":"2024-02-12T09:23:23Z"}}`)) }) client := defaultTestClient(server.URL, "foo") @@ -906,3 +905,20 @@ func TestStatusPage_UpdatePostUpdate(t *testing.T) { testEqual(t, want, res) } + +// DeleteStatusPagePostUpdate +func TestStatusPage_DeletePostUpdate(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/posts/1/post_updates/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + }) + + client := defaultTestClient(server.URL, "foo") + + err := client.DeleteStatusPagePostUpdate("1", "1", "1") + if err != nil { + t.Fatal(err) + } +} From e79e8d560ec572f7296e029201bc2a10f2c0f27e Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 12:45:57 +0200 Subject: [PATCH 48/55] Test for GetStatusPagePostPostmortem --- status_page.go | 15 ++++++++------- status_page_test.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/status_page.go b/status_page.go index 24e95ac2..1685db6f 100644 --- a/status_page.go +++ b/status_page.go @@ -68,16 +68,17 @@ type StatusPagePost struct { } type LinkedResource struct { - ID string - Self string + ID string `json:"id,omitempty"` + Self string `json:"self,omitempty"` } type Postmortem struct { - ID string - Self string - NotifySubscribers bool - ReportedAt string - Type string + ID string `json:"id,omitempty"` + Self string `json:"self,omitempty"` + NotifySubscribers bool `json:"notify_subscribers,omitempty"` + ReportedAt string `json:"reported_at,omitempty"` + Type string `json:"type,omitempty"` + Message string `json:"message,omitempty"` } type StatusPagePostUpdate struct { diff --git a/status_page_test.go b/status_page_test.go index 33a73fd2..1cccfdb9 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -922,3 +922,38 @@ func TestStatusPage_DeletePostUpdate(t *testing.T) { t.Fatal(err) } } + +// GetStatusPagePostPostmortem +func TestStatusPage_GetPostPostmortem(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/posts/1/postmortem", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + _, _ = w.Write([]byte(`{ + "postmortem": { + "id": "1", + "notify_subscribers": false, + "message": "Hello world", + "reported_at": "2024-02-12T09:23:23Z", + "type": "status_page_post_postmortem" + } + }`)) + }) + + client := defaultTestClient(server.URL, "foo") + + res, err := client.GetStatusPagePostPostmortem("1", "1") + if err != nil { + t.Fatal(err) + } + want := &Postmortem{ + ID: "1", + NotifySubscribers: false, + Message: "Hello world", + ReportedAt: "2024-02-12T09:23:23Z", + Type: "status_page_post_postmortem", + } + + testEqual(t, want, res) +} From eeaa5cd92949f2eb7b12a28bf57ea777d8cdbd9c Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 12:57:09 +0200 Subject: [PATCH 49/55] Test for CreateStatusPagePostPostmortem --- status_page.go | 18 ++++++++++++------ status_page_test.go | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/status_page.go b/status_page.go index 1685db6f..1f598fe4 100644 --- a/status_page.go +++ b/status_page.go @@ -73,12 +73,18 @@ type LinkedResource struct { } type Postmortem struct { - ID string `json:"id,omitempty"` - Self string `json:"self,omitempty"` - NotifySubscribers bool `json:"notify_subscribers,omitempty"` - ReportedAt string `json:"reported_at,omitempty"` - Type string `json:"type,omitempty"` - Message string `json:"message,omitempty"` + ID string `json:"id,omitempty"` + Self string `json:"self,omitempty"` + NotifySubscribers bool `json:"notify_subscribers,omitempty"` + ReportedAt string `json:"reported_at,omitempty"` + Type string `json:"type,omitempty"` + Message string `json:"message,omitempty"` + Post ShortPostType `json:"post,omitempty"` +} + +type ShortPostType struct { + ID string `json:"id,omitempty"` + Type string `json:"type,omitempty"` } type StatusPagePostUpdate struct { diff --git a/status_page_test.go b/status_page_test.go index 1cccfdb9..f6b83fae 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -957,3 +957,40 @@ func TestStatusPage_GetPostPostmortem(t *testing.T) { testEqual(t, want, res) } + +// CreateStatusPagePostPostmortem +func TestStatusPage_CreatePostPostmortem(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/posts/1/postmortem", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + _, _ = w.Write([]byte(`{"postmortem": {"id": "1","message":"Hello world","notify_subscribers":false,"post":{"id": "1","type":"status_page_post"}}}`)) + }) + + client := defaultTestClient(server.URL, "foo") + + input := Postmortem{ + Message: "Hello world", + NotifySubscribers: false, + Post: ShortPostType{ + ID: "1", + Type: "status_page_post", + }, + } + res, err := client.CreateStatusPagePostPostmortem("1", "1", input) + if err != nil { + t.Fatal(err) + } + want := &Postmortem{ + ID: "1", + Message: "Hello world", + NotifySubscribers: false, + Post: ShortPostType{ + ID: "1", + Type: "status_page_post", + }, + } + + testEqual(t, want, res) +} From d9ee48808e4b36c30f2f9341fedd7ccc1455002c Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 12:59:43 +0200 Subject: [PATCH 50/55] Test for UpdateStatusPagePostPostmortem --- status_page_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/status_page_test.go b/status_page_test.go index f6b83fae..697b7e02 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -994,3 +994,40 @@ func TestStatusPage_CreatePostPostmortem(t *testing.T) { testEqual(t, want, res) } + +// UpdateStatusPagePostPostmortem +func TestStatusPage_UpdatePostPostmortem(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/posts/1/postmortem", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + _, _ = w.Write([]byte(`{"postmortem": {"id": "1","message":"Hello world","notify_subscribers":false,"post":{"id": "1","type":"status_page_post"}}}`)) + }) + + client := defaultTestClient(server.URL, "foo") + + input := Postmortem{ + Message: "Hello world", + NotifySubscribers: false, + Post: ShortPostType{ + ID: "1", + Type: "status_page_post", + }, + } + res, err := client.UpdateStatusPagePostPostmortem("1", "1", input) + if err != nil { + t.Fatal(err) + } + want := &Postmortem{ + ID: "1", + Message: "Hello world", + NotifySubscribers: false, + Post: ShortPostType{ + ID: "1", + Type: "status_page_post", + }, + } + + testEqual(t, want, res) +} From 8d52894139847892d37af266932c39b4b10d3f01 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 13:01:06 +0200 Subject: [PATCH 51/55] Test for DeleteStatusPagePostPostmortem --- status_page_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/status_page_test.go b/status_page_test.go index 697b7e02..48f4ed7a 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -1031,3 +1031,20 @@ func TestStatusPage_UpdatePostPostmortem(t *testing.T) { testEqual(t, want, res) } + +// DeleteStatusPagePostPostmortem +func TestStatusPage_DeletePostPostmortem(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/posts/1/postmortem", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + }) + + client := defaultTestClient(server.URL, "foo") + + err := client.DeleteStatusPagePostPostmortem("1", "1") + if err != nil { + t.Fatal(err) + } +} From 5f5fef231309e4cc195c5e966f2c8a2659a97f58 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 13:11:56 +0200 Subject: [PATCH 52/55] Test for ListStatusPageSubscriptions --- status_page.go | 28 ++++++++++++++-------------- status_page_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/status_page.go b/status_page.go index 1f598fe4..2992999f 100644 --- a/status_page.go +++ b/status_page.go @@ -103,24 +103,24 @@ type StatusPagePostUpdate struct { } type StatusPagePostUpdateImpact struct { - Service Service - Severity StatusPageSeverity + Service Service `json:"service,omitempty"` + Severity StatusPageSeverity `json:"severity,omitempty"` } type StatusPageSubscription struct { - Channel string - Contact string - ID string - Self string - Status string - StatusPage StatusPage - SubscribableObject SubscribableObject - Type string + Channel string `json:"channel,omitempty"` + Contact string `json:"contact,omitempty"` + ID string `json:"id,omitempty"` + Self string `json:"self,omitempty"` + Status string `json:"status,omitempty"` + StatusPage StatusPage `json:"status_page,omitempty"` + SubscribableObject SubscribableObject `json:"subscribable_object,omitempty"` + Type string `json:"type,omitempty"` } type SubscribableObject struct { - ID string - Type string + ID string `json:"id,omitempty"` + Type string `json:"type,omitempty"` } type ListStatusPageOptions struct { @@ -150,8 +150,8 @@ type ListStatusPagePostUpdateOptions struct { } type ListStatusPageSubscriptionsOptions struct { - Channel string - Status string + Channel string `url:"channel,omitempty"` + Status string `url:"status,omitempty"` } // ListStatusPagesResponse is the data structure returned from calling the ListStatusPages API endpoint. diff --git a/status_page_test.go b/status_page_test.go index 48f4ed7a..021d0a3a 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -1048,3 +1048,48 @@ func TestStatusPage_DeletePostPostmortem(t *testing.T) { t.Fatal(err) } } + +// ListStatusPageSubscriptions +func TestStatusPage_ListSubscriptions(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/subscriptions", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + testEqual(t, r.URL.Query()["channel"], []string{"email"}) + testEqual(t, r.URL.Query()["status"], []string{"active"}) + _, _ = w.Write([]byte(`{"subscriptions": [{"id": "1","channel":"email","contact":"address@email.example","status":"active","status_page":{"id": "1","type":"status_page"},"subscribable_object":{"id": "1","type":"status_page"},"type":"status_page_subscription"}]}`)) + }) + + client := defaultTestClient(server.URL, "foo") + opts := ListStatusPageSubscriptionsOptions{ + Channel: "email", + Status: "active", + } + res, err := client.ListStatusPageSubscriptions("1", opts) + if err != nil { + t.Fatal(err) + } + want := &ListStatusPageSubscriptionsResponse{ + APIListObject: APIListObject{}, + StatusPageSubscriptions: []StatusPageSubscription{ + { + ID: "1", + Channel: "email", + Contact: "address@email.example", + Status: "active", + StatusPage: StatusPage{ + ID: "1", + Type: "status_page", + }, + SubscribableObject: SubscribableObject{ + ID: "1", + Type: "status_page", + }, + Type: "status_page_subscription", + }, + }, + } + + testEqual(t, want, res) +} From 0296aebd19ead85365ee116e97eb2aee679a0142 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 13:16:03 +0200 Subject: [PATCH 53/55] Test for CreateStatusPageSubscription --- status_page_test.go | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/status_page_test.go b/status_page_test.go index 021d0a3a..bc8dc25f 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -1093,3 +1093,52 @@ func TestStatusPage_ListSubscriptions(t *testing.T) { testEqual(t, want, res) } + +// CreateStatusPageSubscription +func TestStatusPage_CreateSubscription(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/subscriptions", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "POST") + _, _ = w.Write([]byte(`{"subscription": {"id": "1","channel":"email","contact":"address@email.example","status":"active","status_page":{"id": "1","type":"status_page"},"subscribable_object":{"id": "1","type":"status_page_service"},"type":"status_page_subscription"}}`)) + }) + + client := defaultTestClient(server.URL, "foo") + + input := StatusPageSubscription{ + Channel: "email", + Contact: "address@email.example", + Status: "active", + StatusPage: StatusPage{ + ID: "1", + Type: "status_page", + }, + SubscribableObject: SubscribableObject{ + ID: "1", + Type: "status_page", + }, + Type: "status_page_subscription", + } + res, err := client.CreateStatusPageSubscription("1", input) + if err != nil { + t.Fatal(err) + } + want := &StatusPageSubscription{ + ID: "1", + Channel: "email", + Contact: "address@email.example", + Status: "active", + StatusPage: StatusPage{ + ID: "1", + Type: "status_page", + }, + SubscribableObject: SubscribableObject{ + ID: "1", + Type: "status_page_service", + }, + Type: "status_page_subscription", + } + + testEqual(t, want, res) +} From 0508372b6cb9fef3a1aa72930a412d96fc6f2643 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 13:18:04 +0200 Subject: [PATCH 54/55] Test for GetStatusPageSubscription --- status_page_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/status_page_test.go b/status_page_test.go index bc8dc25f..c3e23591 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -1142,3 +1142,39 @@ func TestStatusPage_CreateSubscription(t *testing.T) { testEqual(t, want, res) } + +// GetStatusPageSubscription +func TestStatusPage_GetSubscription(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/subscriptions/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + _, _ = w.Write([]byte(`{"subscription": {"id": "1","channel":"email","contact":"address@email.example","status":"active","status_page":{"id": "1","type":"status_page"},"subscribable_object":{"id": "1","type":"status_page_service"},"type":"status_page_subscription"}}`)) + + }) + + client := defaultTestClient(server.URL, "foo") + + res, err := client.GetStatusPageSubscription("1", "1") + if err != nil { + t.Fatal(err) + } + want := &StatusPageSubscription{ + ID: "1", + Channel: "email", + Contact: "address@email.example", + Status: "active", + StatusPage: StatusPage{ + ID: "1", + Type: "status_page", + }, + SubscribableObject: SubscribableObject{ + ID: "1", + Type: "status_page_service", + }, + Type: "status_page_subscription", + } + + testEqual(t, want, res) +} From a2587c6f93423f0dde85c1fd374764e02909c1e2 Mon Sep 17 00:00:00 2001 From: Willem Potgieter Date: Mon, 12 Feb 2024 13:19:06 +0200 Subject: [PATCH 55/55] Test for DeleteStatusPageSubscription --- status_page_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/status_page_test.go b/status_page_test.go index c3e23591..dabeb225 100644 --- a/status_page_test.go +++ b/status_page_test.go @@ -1178,3 +1178,20 @@ func TestStatusPage_GetSubscription(t *testing.T) { testEqual(t, want, res) } + +// DeleteStatusPageSubscription +func TestStatusPage_DeleteSubscription(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/status_pages/1/subscriptions/1", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + }) + + client := defaultTestClient(server.URL, "foo") + + err := client.DeleteStatusPageSubscription("1", "1") + if err != nil { + t.Fatal(err) + } +}