Skip to content

Commit

Permalink
add outgoing alert rules endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dheeruk12 committed Oct 26, 2023
1 parent 6c4182b commit c11f573
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Client struct {
Sla *SLAService
PostIncidentTask *PostIncidentTaskService
TaskTemplate *TaskTemplateService
OutgoingRules *OutgoingRulesService
}

type Response struct {
Expand Down Expand Up @@ -97,6 +98,7 @@ func NewClient(config *Config) (*Client, error) {
c.Sla = &SLAService{c}
c.PostIncidentTask = &PostIncidentTaskService{c}
c.TaskTemplate = &TaskTemplateService{c}
c.OutgoingRules = &OutgoingRulesService{c}
return c, nil

}
Expand Down
80 changes: 80 additions & 0 deletions client/outgoing_rules.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package client

import (
"encoding/json"
"fmt"
)

type OutgoingRulesService service

type OutgoingRule struct {
UniqueID string `json:"unique_id"`
Enabled bool `json:"is_enabled"`
RuleJSON string `json:"rule_json"`
}

func (c *OutgoingRulesService) CreateOutgoingRule(teamID, serviceID, integrationID string, rule *OutgoingRule) (*OutgoingRule, error) {
path := fmt.Sprintf("/api/v2/account/teams/%s/services/%s/integrations/%s/outgoingrules/", teamID, serviceID, integrationID)
body, err := c.client.newRequestDo("POST", path, rule)
if err != nil {
return nil, err
}
var s OutgoingRule
err = json.Unmarshal(body.BodyBytes, &s)
if err != nil {
return nil, err
}
return &s, nil
}

func (c *OutgoingRulesService) GetOutgoingRules(teamID, serviceID, integrationID string) ([]OutgoingRule, error) {

path := fmt.Sprintf("/api/v2/account/teams/%s/services/%s/integrations/%s/outgoingrules/", teamID, serviceID, integrationID)
body, err := c.client.newRequestDo("GET", path, nil)
if err != nil {
return nil, err
}
var s []OutgoingRule
err = json.Unmarshal(body.BodyBytes, &s)
if err != nil {
return nil, err
}
return s, nil
}

func (c *OutgoingRulesService) GetOutgoingRule(teamID, serviceID, integrationID, id string) (*OutgoingRule, error) {
path := fmt.Sprintf("/api/v2/account/teams/%s/services/%s/integrations/%s/outgoingrules/%s/", teamID, serviceID, integrationID, id)
body, err := c.client.newRequestDo("GET", path, nil)
if err != nil {
return nil, err
}
var s OutgoingRule
err = json.Unmarshal(body.BodyBytes, &s)
if err != nil {
return nil, err
}
return &s, nil
}

func (c *OutgoingRulesService) UpdateOutgoingRule(teamID, serviceID, integrationID, id string, rule *OutgoingRule) (*OutgoingRule, error) {
path := fmt.Sprintf("/api/v2/account/teams/%s/services/%s/integrations/%s/outgoingrules/%s/", teamID, serviceID, integrationID, id)
body, err := c.client.newRequestDo("PUT", path, rule)
if err != nil {
return nil, err
}
var s OutgoingRule
err = json.Unmarshal(body.BodyBytes, &s)
if err != nil {
return nil, err
}
return &s, nil
}

func (c *OutgoingRulesService) DeleteOutgoingRule(teamID, serviceID, integrationID, id string) error {
path := fmt.Sprintf("/api/v2/account/teams/%s/services/%s/integrations/%s/outgoingrules/%s/", teamID, serviceID, integrationID, id)
_, err := c.client.newRequestDo("DELETE", path, nil)
if err != nil {
return err
}
return nil
}

0 comments on commit c11f573

Please sign in to comment.