segment

package
v0.3.1-0...-9c07255 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// WorkspacesEndpoint is the API endpoint for listing workspaces
	WorkspacesEndpoint = "workspaces"
	// SourceEndpoint is the API endpoint for interacting with sources
	SourceEndpoint = "sources"
	// DestinationEndpoint is the API endpoint for interacting with destinations
	DestinationEndpoint = "destinations"
	// TrackingPlanEndpoint is the API endpoint for interacting with tracking plans
	TrackingPlanEndpoint = "tracking-plans"
	// DestinationFiltersEndpoint is the API endpoint for interacting with destination filters
	DestinationFiltersEndpoint = "filters"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client manages communication with Segment Config API.

func NewClient

func NewClient(accessToken string, workspace string) *Client

NewClient creates a new Segment Config API client.

func (*Client) CreateDestination

func (c *Client) CreateDestination(srcName string, destName string, connMode string, enabled bool, configs []DestinationConfig) (Destination, error)

CreateDestination creates a new destination for a source

func (*Client) CreateDestinationFilter

func (c *Client) CreateDestinationFilter(srcName string, destinationName string, filter DestinationFilter) (*DestinationFilter, error)

func (*Client) CreateSource

func (c *Client) CreateSource(srcName string, catName string) (Source, error)

CreateSource creates a new source

func (*Client) CreateTrackingPlan

func (c *Client) CreateTrackingPlan(data TrackingPlan) (TrackingPlan, error)

CreateTrackingPlan creates tracking plan

func (*Client) CreateTrackingPlanSourceConnection

func (c *Client) CreateTrackingPlanSourceConnection(planId string, sourceName string) error

CreateTrackingPlanSourceConnection associates a source to a tracking plan https://reference.segmentapis.com/#8c794e32-86e5-4a81-96e1-dc30368f7a9e

func (*Client) DeleteDestination

func (c *Client) DeleteDestination(srcName string, destName string) error

DeleteDestination deletes a destination for a source from the workspace

func (*Client) DeleteDestinationFilter

func (c *Client) DeleteDestinationFilter(srcName string, destinationName string, filterId string) error

func (*Client) DeleteSource

func (c *Client) DeleteSource(srcName string) error

DeleteSource deletes a source from the workspace

func (*Client) DeleteTrackingPlan

func (c *Client) DeleteTrackingPlan(trackingPlanID string) error

DeleteTrackingPlan Deletes a tracking plan

func (*Client) DeleteTrackingPlanSourceConnection

func (c *Client) DeleteTrackingPlanSourceConnection(planId string, sourceName string) error

DeleteTrackingPlanSourceConnection removes the connection between a source and a tracking plan API Doc: https://reference.segmentapis.com/#6d50bdb0-87fc-47b6-9169-5b022119fe2e

func (*Client) GetDestination

func (c *Client) GetDestination(srcName string, destName string) (Destination, error)

GetDestination returns information about a destination for a source

func (*Client) GetDestinationFilter

func (c *Client) GetDestinationFilter(srcName string, destinationName string, filterId string) (*DestinationFilter, error)

func (*Client) GetSource

func (c *Client) GetSource(srcName string) (Source, error)

GetSource returns information about a source

func (*Client) GetSourceConfig

func (c *Client) GetSourceConfig(srcName string) (SourceConfig, error)

GetSourceConfig retrieves the schema config of a given source API Doc: https://reference.segmentapis.com/#c74efb9b-b09e-4072-8da1-ba6ca60e6a78

func (*Client) GetTrackingPlan

func (c *Client) GetTrackingPlan(trackingPlanID string) (TrackingPlan, error)

GetTrackingPlan gets a specific tracking plan from segment

func (*Client) GetWorkspace

func (c *Client) GetWorkspace() (Workspace, error)

GetWorkspace returns information about a workspace

func (*Client) ListDestinationFilters

func (c *Client) ListDestinationFilters(srcName string, destinationName string) ([]DestinationFilter, error)

ListDestinations returns all destinations for a source

func (*Client) ListDestinations

func (c *Client) ListDestinations(srcName string) (Destinations, error)

ListDestinations returns all destinations for a source

func (*Client) ListSources

func (c *Client) ListSources() (Sources, error)

ListSources returns all sources for a workspace

func (*Client) ListTrackingPlanSources

func (c *Client) ListTrackingPlanSources(planId string) ([]TrackingPlanSourceConnection, error)

ListTrackingPlanSources lists all the sources associated with a given tracking plan API Doc: https://reference.segmentapis.com/#27a50096-e444-48e6-abb5-6e9445740634

func (*Client) ListTrackingPlans

func (c *Client) ListTrackingPlans() (TrackingPlans, error)

ListTrackingPlans lists all the tracking plans in the workspace

func (*Client) UpdateDestination

func (c *Client) UpdateDestination(srcName string, destName string, enabled bool, configs []DestinationConfig) (Destination, error)

UpdateDestination updates an existing destination with a new config

func (*Client) UpdateDestinationFilter

func (c *Client) UpdateDestinationFilter(srcName string, destinationName string, filter DestinationFilter) (*DestinationFilter, error)

func (*Client) UpdateSourceConfig

func (c *Client) UpdateSourceConfig(srcName string, config SourceConfig) (SourceConfig, error)

UpdateSourceConfig updates the schema config of a given source API Doc: https://reference.segmentapis.com/#af54244f-4ec7-4e78-96e9-8966dd18e56f

func (*Client) UpdateTrackingPlan

func (c *Client) UpdateTrackingPlan(trackingPlanID string, data TrackingPlan) (TrackingPlan, error)

UpdateTrackingPlan updates a tracking plan

type CommonEventSettings

type CommonEventSettings string

CommonEventSettings provides accepted values for CommonTrackEventOnViolations, CommonIdentifyEventOnViolations and CommonGroupEventOnViolations

const (
	Allow CommonEventSettings = "ALLOW"

	// Only for use with CommonTrackEventOnViolations
	OmitProps CommonEventSettings = "OMIT_PROPERTIES"

	// Only for use with CommonIdentifyEventOnViolations and CommonIdentifyEventOnViolations
	OmitTraits CommonEventSettings = "OMIT_TRAITS"

	Block CommonEventSettings = "BLOCK"
)

type Destination

type Destination struct {
	Name           string              `json:"name,omitempty"`
	Parent         string              `json:"parent,omitempty"`
	DisplayName    string              `json:"display_name,omitempty"`
	Enabled        bool                `json:"enabled,omitempty"`
	ConnectionMode string              `json:"connection_mode,omitempty"`
	Configs        []DestinationConfig `json:"config,omitempty"`
	CreateTime     time.Time           `json:"create_time,omitempty"`
	UpdateTime     time.Time           `json:"update_time,omitempty"`
}

Destination defines the struct for the destination object

type DestinationConfig

type DestinationConfig struct {
	Name        string      `json:"name,omitempty"`
	DisplayName string      `json:"display_name,omitempty"`
	Value       interface{} `json:"value,omitempty"`
	Type        string      `json:"type,omitempty"`
}

DestinationConfig contains information about how a Destination is configured

type DestinationFilter

type DestinationFilter struct {
	Name        string `json:"name"`
	Title       string `json:"title"`
	Description string `json:"description"`
	// FQL statement to match events coming through
	Conditions string                   `json:"if"`
	Actions    DestinationFilterActions `json:"actions"`
	IsEnabled  bool                     `json:"enabled"`
}

type DestinationFilterAction

type DestinationFilterAction interface {
	ActionType() DestinationFilterActionType
}

Destination Filter action to be taken on the events matching the condition

type DestinationFilterActionType

type DestinationFilterActionType string
const (
	DestinationFilterActionTypeDropEvent DestinationFilterActionType = "drop_event"
	DestinationFilterActionTypeAllowList DestinationFilterActionType = "whitelist_fields"
	DestinationFilterActionTypeBlockList DestinationFilterActionType = "blacklist_fields"
	DestinationFilterActionTypeSampling  DestinationFilterActionType = "sample_event"
)

type DestinationFilterActions

type DestinationFilterActions []DestinationFilterAction

func (*DestinationFilterActions) UnmarshalJSON

func (actions *DestinationFilterActions) UnmarshalJSON(data []byte) error

type Destinations

type Destinations struct {
	Destinations []Destination `json:"destinations,omitempty"`
}

Destinations defines the struct for the destination object

type DropEventAction

type DropEventAction struct {
	Type DestinationFilterActionType `json:"type"`
}

func NewDropEventAction

func NewDropEventAction() DropEventAction

func (DropEventAction) ActionType

type Event

type Event struct {
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Rules       Rules  `json:"rules,omitempty"`
	Version     *int   `json:"version,omitempty"`
}

Event contains information about a single event of the tracking plan

type EventDescription

type EventDescription struct {
	Context    *EventFieldsSelection `json:"context,omitempty"`
	Traits     *EventFieldsSelection `json:"traits,omitempty"`
	Properties *EventFieldsSelection `json:"properties,omitempty"`
}

type EventFieldsSelection

type EventFieldsSelection struct {
	Fields []string `json:"fields"`
}

type FieldsListEventAction

type FieldsListEventAction struct {
	Type   DestinationFilterActionType `json:"type"`
	Fields EventDescription            `json:"fields"`
}

func NewAllowListEventAction

func NewAllowListEventAction(properties []string, context []string, traits []string) FieldsListEventAction

func NewBlockListEventAction

func NewBlockListEventAction(properties []string, context []string, traits []string) FieldsListEventAction

func (FieldsListEventAction) ActionType

type LibraryConfig

type LibraryConfig struct {
	MetricsEnabled       bool   `json:"metrics_enabled,omitempty"`
	RetryQueue           bool   `json:"retry_queue,omitempty"`
	CrossDomainIDEnabled bool   `json:"cross_domain_id_enabled,omitempty"`
	APIHost              string `json:"api_host,omitempty"`
}

LibraryConfig contains information about a source's library

type Properties

type Properties struct {
	Properties map[string]Property `json:"properties,omitempty"`
	Required   []string            `json:"required,omitempty"`
	Type       string              `json:"type,omitempty"`
}

Properties contains information about a specific type of rule properties

type Property

type Property struct {
	Description          string              `json:"description,omitempty"`
	Type                 interface{}         `json:"type,omitempty"`
	Pattern              *string             `json:"pattern,omitempty"`
	Format               *string             `json:"format,omitempty"`
	Items                *Property           `json:"items,omitempty"`
	MinItems             *int                `json:"minItems,omitempty"`
	AdditionalItems      interface{}         `json:"additionalItems,omitempty"`
	Contains             *Property           `json:"contains,omitempty"`
	Properties           map[string]Property `json:"properties,omitempty"`
	AdditionalProperties interface{}         `json:"additionalProperties,omitempty"`
	PatternProperties    map[string]Property `json:"patternProperties,omitempty"`
	Required             []string            `json:"required,omitempty"`
	Enum                 []*string           `json:"enum,omitempty"`
}

Property contains information of a single property

type RuleProperties

type RuleProperties struct {
	Context    Properties `json:"context,omitempty"`
	Properties Properties `json:"properties,omitempty"`
	Traits     Properties `json:"traits,omitempty"`
}

RuleProperties contains the different properties of a specific type of rules

type RuleSet

type RuleSet struct {
	Global   Rules   `json:"global,omitempty"`
	Events   []Event `json:"events,omitempty"`
	Identify Rules   `json:"identify,omitempty"`
	Group    Rules   `json:"group,omitempty"`
}

RuleSet contains a set of different rules about the tracking plan

type Rules

type Rules struct {
	Schema     string         `json:"$schema,omitempty"`
	Type       string         `json:"type,omitempty"`
	Properties RuleProperties `json:"properties,omitempty"`
	Required   []string       `json:"required,omitempty"`
}

Rules contains information about a specific type of rules of the tracking plan

type SamplingEventAction

type SamplingEventAction struct {
	Type DestinationFilterActionType `json:"type"`
	// If the type is "sample_event", then the value is a number between 0.0 and 1.0
	Percent float32 `json:"percent"`
	Path    string  `json:"path"`
}

func NewSamplingEventAction

func NewSamplingEventAction(percent float32, path string) SamplingEventAction

func (SamplingEventAction) ActionType

type SegmentApiError

type SegmentApiError struct {
	Message string `json:"error,omitempty"`
	Code    int    `json:"code,omitempty"`
}

func (*SegmentApiError) Error

func (err *SegmentApiError) Error() string

type Source

type Source struct {
	Name          string        `json:"name,omitempty"`
	CatalogName   string        `json:"catalog_name,omitempty"`
	Parent        string        `json:"parent,omitempty"`
	WriteKeys     []string      `json:"write_keys,omitempty"`
	LibraryConfig LibraryConfig `json:"library_config,omitempty"`
	CreateTime    time.Time     `json:"create_time,omitempty"`
}

Source defines the struct for the source object

type SourceConfig

type SourceConfig struct {
	Name                                string              `json:"name,omitempty"`
	Parent                              string              `json:"parent,omitempty"`
	AllowUnplannedTrackEvents           bool                `json:"allow_unplanned_track_events,omitempty"`
	AllowUnplannedIdentifyTraits        bool                `json:"allow_unplanned_identify_traits,omitempty"`
	AllowUnplannedGroupTraits           bool                `json:"allow_unplanned_group_traits,omitempty"`
	AllowTrackEventOnViolations         bool                `json:"allow_track_event_on_violations,omitempty"`
	AllowIdentifyTraitsOnViolations     bool                `json:"allow_identify_traits_on_violations,omitempty"`
	AllowGroupTraitsOnViolations        bool                `json:"allow_group_traits_on_violations,omitempty"`
	AllowUnplannedTrackEventsProperties bool                `json:"allow_unplanned_track_event_properties,omitempty"`
	AllowTrackPropertiesOnViolations    bool                `json:"allow_track_properties_on_violations,omitempty"`
	ForwardingBlockedEventsTo           string              `json:"forwarding_blocked_events_to,omitempty"`
	ForwardingViolationsTo              string              `json:"forwarding_violations_to,omitempty"`
	CommonTrackEventOnViolations        CommonEventSettings `json:"common_track_event_on_violations,omitempty"`
	CommonIdentifyEventOnViolations     CommonEventSettings `json:"common_identify_event_on_violations,omitempty"`
	CommonGroupEventOnViolations        CommonEventSettings `json:"common_group_event_on_violations,omitempty"`
}

type Sources

type Sources struct {
	Sources []Source `json:"sources,omitempty"`
}

Sources defines the struct for the sources object

type TrackingPlan

type TrackingPlan struct {
	Name        string    `json:"name,omitempty"`
	DisplayName string    `json:"display_name,omitempty"`
	Rules       RuleSet   `json:"rules,omitempty"`
	CreateTime  time.Time `json:"create_time,omitempty"`
	UpdateTime  time.Time `json:"update_time,omitempty"`
}

TrackingPlan contains information about a tracking plan

type TrackingPlanSourceConnection

type TrackingPlanSourceConnection struct {
	// Source is the full name of the source (including the workspace path)
	Source         string `json:"source_name,omitempty"`
	TrackingPlanId string `json:"tracking_plan_id,omitempty"`
}

TrackingPlanSourceConnection represents the link between a tracking plan and a source

type TrackingPlanSourceConnections

type TrackingPlanSourceConnections struct {
	Connections []TrackingPlanSourceConnection `json:"connections,omitempty"`
}

type TrackingPlans

type TrackingPlans struct {
	TrackingPlans []TrackingPlan `json:"tracking_plans,omitempty"`
}

TrackingPlans is a list of tracking plans

type UpdateMask

type UpdateMask struct {
	Paths []string `json:"paths,omitempty"`
}

UpdateMask contains information for updating Destinations and Sources

type Workspace

type Workspace struct {
	Name        string    `json:"name,omitempty"`
	DisplayName string    `json:"display_name,omitempty"`
	ID          string    `json:"id,omitempty"`
	CreateTime  time.Time `json:"create_time,omitempty"`
}

Workspace defines the struct for the workspace object

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL