Skip to content

Commit

Permalink
Tiny one to add specific incident_types stream
Browse files Browse the repository at this point in the history
We already have this resource and this endpoint exists so why not.
  • Loading branch information
rliddler committed Oct 19, 2023
1 parent a39fc89 commit 938aca7
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tap/stream_incident_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package tap

import (
"context"

kitlog "github.com/go-kit/log"
"github.com/incident-io/singer-tap/client"
"github.com/incident-io/singer-tap/model"
"github.com/pkg/errors"
)

func init() {
register(&StreamIncidentTypes{})
}

type StreamIncidentTypes struct {
}

func (s *StreamIncidentTypes) Output() *Output {
return &Output{
Type: OutputTypeSchema,
Stream: "incident_types",
Schema: &model.Schema{
HasAdditionalProperties: false,
Type: []string{"object"},
Properties: model.IncidentTypeV1.Schema().Properties,
},
KeyProperties: []string{"id"},
BookmarkProperties: []string{},
}
}

func (s *StreamIncidentTypes) GetRecords(ctx context.Context, logger kitlog.Logger, cl *client.ClientWithResponses) ([]map[string]any, error) {
var (
results = []map[string]any{}
)

response, err := cl.IncidentTypesV1ListWithResponse(ctx)
if err != nil {
return nil, errors.Wrap(err, "listing incidents for actions stream")
}

for _, element := range response.JSON200.IncidentTypes {
results = append(results, model.IncidentTypeV1.Serialize(&element))
}

return results, nil
}

0 comments on commit 938aca7

Please sign in to comment.