Skip to content

Commit

Permalink
add incident template & schedule & service search
Browse files Browse the repository at this point in the history
  • Loading branch information
STLVRTX committed Sep 4, 2022
1 parent 68b1fdc commit 6531e16
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
38 changes: 38 additions & 0 deletions incidenttemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,44 @@ func (c *Client) GetIncidentTemplate(input *GetIncidentTemplateInput) (*GetIncid
return &GetIncidentTemplateOutput{IncidentTemplate: incidentTemplate}, nil
}

// SearchIncidentTemplateInput represents the input of a SearchIncidentTemplate operation.
type SearchIncidentTemplateInput struct {
_ struct{}
IncidentTemplateName *string
}

// SearchIncidentTemplateOutput represents the output of a SearchIncidentTemplate operation.
type SearchIncidentTemplateOutput struct {
_ struct{}
IncidentTemplate *IncidentTemplate
}

// SearchIncidentTemplate gets the incidentTemplate with specified name.
func (c *Client) SearchIncidentTemplate(input *SearchIncidentTemplateInput) (*SearchIncidentTemplateOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.IncidentTemplateName == nil {
return nil, errors.New("incident template name is required")
}

resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/name/%s", apiRoutes.incidentTemplates, *input.IncidentTemplateName))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}

incidentTemplate := &IncidentTemplate{}
err = json.Unmarshal(resp.Body(), incidentTemplate)
if err != nil {
return nil, err
}

return &SearchIncidentTemplateOutput{IncidentTemplate: incidentTemplate}, nil
}

// UpdateIncidentTemplateInput represents the input of a UpdateIncidentTemplate operation.
type UpdateIncidentTemplateInput struct {
_ struct{}
Expand Down
38 changes: 38 additions & 0 deletions schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,44 @@ func (c *Client) GetScheduleUserOnCall(input *GetScheduleUserOnCallInput) (*GetS
return &GetScheduleUserOnCallOutput{Shift: shift}, nil
}

// SearchScheduleInput represents the input of a SearchSchedule operation.
type SearchScheduleInput struct {
_ struct{}
ScheduleName *string
}

// SearchScheduleOutput represents the output of a SearchSchedule operation.
type SearchScheduleOutput struct {
_ struct{}
Schedule *Schedule
}

// SearchSchedule gets the schedule with specified name.
func (c *Client) SearchSchedule(input *SearchScheduleInput) (*SearchScheduleOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.ScheduleName == nil {
return nil, errors.New("schedule name is required")
}

resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/name/%s", apiRoutes.schedules, *input.ScheduleName))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}

schedule := &Schedule{}
err = json.Unmarshal(resp.Body(), schedule)
if err != nil {
return nil, err
}

return &SearchScheduleOutput{Schedule: schedule}, nil
}

// UpdateScheduleInput represents the input of a UpdateSchedule operation.
type UpdateScheduleInput struct {
_ struct{}
Expand Down
38 changes: 38 additions & 0 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,44 @@ func (c *Client) GetServiceSubscribers(input *GetServiceSubscribersInput) (*GetS
return &GetServiceSubscribersOutput{Subscribers: subscribers}, nil
}

// SearchServiceInput represents the input of a SearchService operation.
type SearchServiceInput struct {
_ struct{}
ServiceName *string
}

// SearchServiceOutput represents the output of a SearchService operation.
type SearchServiceOutput struct {
_ struct{}
Service *Service
}

// SearchService gets the service with specified name.
func (c *Client) SearchService(input *SearchServiceInput) (*SearchServiceOutput, error) {
if input == nil {
return nil, errors.New("input is required")
}
if input.ServiceName == nil {
return nil, errors.New("service name is required")
}

resp, err := c.httpClient.R().Get(fmt.Sprintf("%s/name/%s", apiRoutes.services, *input.ServiceName))
if err != nil {
return nil, err
}
if apiErr := getGenericAPIError(resp, 200); apiErr != nil {
return nil, apiErr
}

service := &Service{}
err = json.Unmarshal(resp.Body(), service)
if err != nil {
return nil, err
}

return &SearchServiceOutput{Service: service}, nil
}

// UpdateServiceInput represents the input of a UpdateService operation.
type UpdateServiceInput struct {
_ struct{}
Expand Down

0 comments on commit 6531e16

Please sign in to comment.