Skip to content

Commit

Permalink
Merge pull request #6 from incident-io/rob/add-incident-types-stream
Browse files Browse the repository at this point in the history
Tiny one to add specific incident_types stream
  • Loading branch information
rliddler authored Oct 19, 2023
2 parents a39fc89 + 938aca7 commit ae5f45d
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 ae5f45d

Please sign in to comment.