Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add ServicePayload to remove nested Service attribute from Service struct #58

Merged
merged 1 commit into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions pagerduty/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,18 @@ type Service struct {
Name string `json:"name,omitempty"`
ScheduledActions []*ScheduledAction `json:"scheduled_actions,omitempty"`
Self string `json:"self,omitempty"`
Service *Service `json:"service,omitempty"`
Status string `json:"status,omitempty"`
Summary string `json:"summary,omitempty"`
SupportHours *SupportHours `json:"support_hours,omitempty"`
Teams []*TeamReference `json:"teams,omitempty"`
Type string `json:"type,omitempty"`
}

// ServicePayload represents a service.
type ServicePayload struct {
Service *Service `json:"service,omitempty"`
}

// ServiceEventRule represents a service event rule
type ServiceEventRule struct {
ID string `json:"id,omitempty"`
Expand Down Expand Up @@ -182,9 +186,9 @@ func (s *ServicesService) List(o *ListServicesOptions) (*ListServicesResponse, *
// Create creates a new service.
func (s *ServicesService) Create(service *Service) (*Service, *Response, error) {
u := "/services"
v := new(Service)
v := new(ServicePayload)

resp, err := s.client.newRequestDo("POST", u, nil, &Service{Service: service}, &v)
resp, err := s.client.newRequestDo("POST", u, nil, &ServicePayload{Service: service}, &v)
if err != nil {
return nil, nil, err
}
Expand All @@ -201,7 +205,7 @@ func (s *ServicesService) Delete(id string) (*Response, error) {
// Get retrieves information about a service.
func (s *ServicesService) Get(id string, o *GetServiceOptions) (*Service, *Response, error) {
u := fmt.Sprintf("/services/%s", id)
v := new(Service)
v := new(ServicePayload)

resp, err := s.client.newRequestDo("GET", u, o, nil, &v)
if err != nil {
Expand All @@ -214,9 +218,9 @@ func (s *ServicesService) Get(id string, o *GetServiceOptions) (*Service, *Respo
// Update updates an existing service.
func (s *ServicesService) Update(id string, service *Service) (*Service, *Response, error) {
u := fmt.Sprintf("/services/%s", id)
v := new(Service)
v := new(ServicePayload)

resp, err := s.client.newRequestDo("PUT", u, nil, &Service{Service: service}, &v)
resp, err := s.client.newRequestDo("PUT", u, nil, &ServicePayload{Service: service}, &v)
if err != nil {
return nil, nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions pagerduty/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestServicesCreate(t *testing.T) {

mux.HandleFunc("/services", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
v := new(Service)
v := new(ServicePayload)
json.NewDecoder(r.Body).Decode(v)
if !reflect.DeepEqual(v.Service, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestServicesUpdate(t *testing.T) {

mux.HandleFunc("/services/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
v := new(Service)
v := new(ServicePayload)
json.NewDecoder(r.Body).Decode(v)
if !reflect.DeepEqual(v.Service, input) {
t.Errorf("Request body = %+v, want %+v", v, input)
Expand Down