diff --git a/pagerduty/service.go b/pagerduty/service.go index a687060..a752408 100644 --- a/pagerduty/service.go +++ b/pagerduty/service.go @@ -156,6 +156,10 @@ type Service struct { Type string `json:"type,omitempty"` } +type EventOrchestrationServiceStatusPayload struct { + Active bool `json:"active"` +} + // ServicePayload represents a service. type ServicePayload struct { Service *Service `json:"service,omitempty"` @@ -395,3 +399,28 @@ func (s *ServicesService) DeleteEventRule(serviceID, ruleID string) (*Response, u := fmt.Sprintf("/services/%s/rules/%s", serviceID, ruleID) return s.client.newRequestDo("DELETE", u, nil, nil, nil) } + +func (s *ServicesService) GetEventOrchestrationServiceStatus(serviceID string) (*EventOrchestrationServiceStatusPayload, *Response, error) { + u := fmt.Sprintf("/event_orchestrations/services/%s/active", serviceID) + v := new(EventOrchestrationServiceStatusPayload) + + resp, err := s.client.newRequestDo("GET", u, nil, nil, &v) + if err != nil { + return nil, nil, err + } + + return v, resp, nil +} + +func (s *ServicesService) UpdateEventOrchestrationServiceStatus(serviceID string, active bool) (*EventOrchestrationServiceStatusPayload, *Response, error) { + u := fmt.Sprintf("/event_orchestrations/services/%s/active", serviceID) + v := new(EventOrchestrationServiceStatusPayload) + p := EventOrchestrationServiceStatusPayload{Active: active} + + resp, err := s.client.newRequestDo("PUT", u, nil, p, &v) + if err != nil { + return nil, nil, err + } + + return v, resp, nil +} diff --git a/pagerduty/service_test.go b/pagerduty/service_test.go index 249f574..2676e16 100644 --- a/pagerduty/service_test.go +++ b/pagerduty/service_test.go @@ -352,3 +352,57 @@ func TestServicesDeleteEventRule(t *testing.T) { t.Fatal(err) } } + +func TestEventOrchestrationServiceStatusGet(t *testing.T) { + setup() + defer teardown() + + mux.HandleFunc("/event_orchestrations/services/1/active", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + w.Write([]byte(`{"active": true}`)) + }) + + resp, _, err := client.Services.GetEventOrchestrationServiceStatus("1") + if err != nil { + t.Fatal(err) + } + + want := &EventOrchestrationServiceStatusPayload{ + Active: true, + } + + if !reflect.DeepEqual(resp, want) { + t.Errorf("returned \n\n%#v want \n\n%#v", resp, want) + } +} + +func TestEventOrchestrationServiceStatusUpdate(t *testing.T) { + setup() + defer teardown() + + input := true + + + mux.HandleFunc("/event_orchestrations/services/1/active", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + v := true + json.NewDecoder(r.Body).Decode(v) + if !reflect.DeepEqual(v, input) { + t.Errorf("Request body = %+v, want %+v", v, input) + } + w.Write([]byte(`{"active": true}`)) + }) + + resp, _, err := client.Services.UpdateEventOrchestrationServiceStatus("1", input) + if err != nil { + t.Fatal(err) + } + + want := &EventOrchestrationServiceStatusPayload{ + Active: true, + } + + if !reflect.DeepEqual(resp, want) { + t.Errorf("returned \n\n%#v want \n\n%#v", resp, want) + } +}