convoy_go

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2023 License: MIT Imports: 17 Imported by: 3

README

Convoy SDK for Go

This is the Convoy Go SDK. This SDK contains methods for easily interacting with Convoy's API. Below are examples to get you started. For additional examples, please see our official documentation at (https://convoy.readme.io/reference)

Installation

Install convoy-go with

go get github.com/frain-dev/convoy-go

Setup Client

import (
    convoy "github.com/frain-dev/convoy-go"
)

  c := convoy.New(convoy.Options{
      APIKey: "your_api_key",
      ProjectID: "your_project_id"
  })
Create an Endpoint

An endpoint represents a target URL to receive events.

endpoint, err := c.Endpoints.Create(&convoy.CreateEndpointRequest{
    Name: "Default Endpoint",
    URL: "http://localhost:8081",
    Description: "Some description",
}, nil)

  if err != nil {
      log.Fatal("failed to create app endpoint \n", err)
  }
Sending an Event

To send an event, you'll need the uid from the endpoint we created earlier.

event, err := c.Events.Create(&convoy.CreateEventRequest{
		EndpointID:     endpoint.UID,
		EventType: "test.customer.event",
		Data:      []byte(`{"event_type": "test.event", "data": { "Hello": "World", "Test": "Data" }}`),
	}, nil)

	if err != nil {
		log.Fatal("failed to create app event \n", err)
	}

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotListDeliveryAttemptResponse = errors.New("invalid list delivery attempt response")
	ErrNotDeliveryAttemptResponse     = errors.New("invalid delivery attempt response")
)
View Source
var (
	ErrNotListEndpointResponse = errors.New("invalid list endpoint response")
	ErrNotEndpointResponse     = errors.New("invalid endpoint response")
)
View Source
var (
	ErrNotListEventResponse = errors.New("invalid list event response")
	ErrNotEventResponse     = errors.New("invalid event response")
)
View Source
var (
	ErrNotListEventDeliveryResponse = errors.New("invalid list event delivery response")
	ErrNotEventDeliveryResponse     = errors.New("invalid event delivery response")
)
View Source
var (
	ErrNotListProjectResponse = errors.New("invalid list project response")
	ErrNotProjectResponse     = errors.New("invalid project response")
)
View Source
var (
	ErrNotListSourceResponse = errors.New("invalid list source response")
	ErrNotSourceResponse     = errors.New("invalid source response")
)
View Source
var (
	ErrNotListSubscriptionResponse = errors.New("invalid list subscription response")
	ErrNotSubscriptionResponse     = errors.New("invalid subscription response")
)
View Source
var (
	ErrInvalidSignatureHeader = errors.New("webhook has no signature header")
	ErrInvalidHeader          = errors.New("webhook has invalid header")
	ErrInvalidEncoding        = errors.New("invalid encoding")
	ErrInvalidSignature       = errors.New("webhook has no valid signature")
	ErrInvalidHashAlgorithm   = errors.New("invalid hash algorithm")
	ErrTimestampExpired       = errors.New("timestamp has expired")
)
View Source
var (
	DefaultTolerance              = 300 * time.Second
	DefaultEncoding  EncodingType = HexEncoding
	DefaultHash                   = "SHA256"
)

Functions

This section is empty.

Types

type APIResponse added in v0.3.0

type APIResponse struct {
	Status  bool             `json:"status"`
	Message string           `json:"message"`
	Data    *json.RawMessage `json:"data,omitempty"`
}

type AlertConfiguration added in v0.3.1

type AlertConfiguration struct {
	Count     int    `json:"count"`
	Threshold string `json:"threshold"`
}

type ApiKey added in v0.3.1

type ApiKey struct {
	HeaderValue string `json:"header_value"`
	HeaderName  string `json:"header_name"`
}

type ApiKeyAuth added in v1.0.0

type ApiKeyAuth struct {
	HeaderValue string `json:"header_value"`
	HeaderName  string `json:"header_name"`
}

type BasicAuth added in v0.3.1

type BasicAuth struct {
	UserName string `json:"username"`
	Password string `json:"password"`
}

type BatchResendRequest added in v0.3.0

type BatchResendRequest struct {
	IDs []string `json:"ids"`
}

type ConfigOpts added in v0.3.2

type ConfigOpts struct {
	Payload    []byte
	SigHeader  string
	Secret     string
	IsAdvanced bool
	Encoding   EncodingType
	Hash       string
	Tolerance  time.Duration
}

type Convoy

type Convoy struct {
	Projects         *Project
	Endpoints        *Endpoint
	Events           *Event
	EventDeliveries  *EventDelivery
	DeliveryAttempts *DeliveryAttempt
	Sources          *Source
	Subscriptions    *Subscription
	// contains filtered or unexported fields
}

func New

func New(opts Options) *Convoy

type CreateEndpointRequest added in v0.3.0

type CreateEndpointRequest struct {
	Name               string `json:"name"`
	SupportEmail       string `json:"support_email"`
	OwnerID            string `json:"owner_id"`
	SlackWebhookUrl    string `json:"slack_webhook_url"`
	URL                string `json:"url"`
	Secret             string `json:"secret,omitempty"`
	Description        string `json:"description,omitempty"`
	AdvancedSignatures *bool  `json:"advanced_signatures"`
	IsDisabled         bool   `json:"is_disabled"`

	Authentication *EndpointAuth `json:"authentication"`

	HttpTimeout       string `json:"http_timeout,omitempty"`
	RateLimit         int    `json:"rate_limit,omitempty"`
	RateLimitDuration string `json:"rate_limit_duration,omitempty"`
}

type CreateEventRequest added in v0.3.0

type CreateEventRequest struct {
	EndpointID    string            `json:"endpoint_id"`
	EventType     string            `json:"event_type"`
	CustomHeaders map[string]string `json:"custom_headers"`
	Data          json.RawMessage   `json:"data"`
}

type CreateFanoutEventRequest added in v1.0.2

type CreateFanoutEventRequest struct {
	OwnerID       string            `json:"owner_id"`
	EventType     string            `json:"event_type"`
	CustomHeaders map[string]string `json:"custom_headers"`
	Data          json.RawMessage   `json:"data"`
}

type CreateProjectRequest added in v1.0.0

type CreateProjectRequest struct {
	Name              string         `json:"name"`
	Type              string         `json:"type"`
	LogoUrl           string         `json:"logo_url,omitempty"`
	RateLimit         int            `json:"rate_limit,omitempty"`
	RateLimitDuration string         `json:"rate_limit_duration,omitempty"`
	Project           *ProjectConfig `json:"config"`
}

type CreateSourceRequest added in v0.3.1

type CreateSourceRequest struct {
	Name       string         `json:"name"`
	Type       string         `json:"type"`
	Provider   string         `json:"provider"`
	IsDisabled bool           `json:"is_disabled"`
	Verifier   VerifierConfig `json:"verifier"`
}

type CreateSubscriptionRequest added in v0.3.1

type CreateSubscriptionRequest struct {
	Name       string `json:"name"`
	SourceID   string `json:"source_id"`
	EndpointID string `json:"endpoint_id"`

	AlertConfig  *AlertConfiguration  `json:"alert_config"`
	RetryConfig  *RetryConfiguration  `json:"retry_config"`
	FilterConfig *FilterConfiguration `json:"filter_config"`
}

type DeliveryAttempt added in v0.3.0

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

func (*DeliveryAttempt) All added in v0.3.0

func (*DeliveryAttempt) Find added in v0.3.0

func (d *DeliveryAttempt) Find(eventDeliveryId, deliveryAttemptId string, query *DeliveryAttemptQueryParam) (*DeliveryAttemptResponse, error)

type DeliveryAttemptQueryParam added in v0.3.0

type DeliveryAttemptQueryParam struct {
	GroupID string
}

type DeliveryAttemptResponse added in v0.3.0

type DeliveryAttemptResponse struct {
	UID        string `json:"uid"`
	MsgID      string `json:"msg_id"`
	URL        string `json:"url"`
	Method     string `json:"method"`
	EndpointID string `json:"endpoint_id"`
	APIVersion string `json:"api_version"`

	IPAddress        string            `json:"ip_address,omitempty"`
	RequestHeader    map[string]string `json:"request_http_header,omitempty"`
	ResponseHeader   map[string]string `json:"response_http_header,omitempty"`
	HttpResponseCode string            `json:"http_status,omitempty"`
	ResponseData     string            `json:"response_data,omitempty"`
	Error            string            `json:"error,omitempty"`
	Status           bool              `json:"status,omitempty"`

	CreatedAt time.Time `json:"created_at,omitempty"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	DeletedAt time.Time `json:"deleted_at,omitempty"`
}

type EncodingType added in v0.3.2

type EncodingType string
const (
	Base64Encoding EncodingType = "base64"
	HexEncoding    EncodingType = "hex"
)

type Endpoint added in v0.3.0

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

func (*Endpoint) All added in v0.3.0

func (*Endpoint) Create added in v0.3.0

func (*Endpoint) Delete added in v0.3.0

func (e *Endpoint) Delete(endpointId string, query *EndpointQueryParam) error

func (*Endpoint) Find added in v0.3.0

func (e *Endpoint) Find(endpointId string, query *EndpointQueryParam) (*EndpointResponse, error)

func (*Endpoint) Update added in v0.3.0

func (e *Endpoint) Update(endpointId string, opts *CreateEndpointRequest, query *EndpointQueryParam) (*EndpointResponse, error)

type EndpointAuth added in v1.0.0

type EndpointAuth struct {
	Type   string      `json:"type"`
	ApiKey *ApiKeyAuth `json:"api_key"`
}

type EndpointQueryParam added in v0.3.0

type EndpointQueryParam struct {
	GroupID string
	OwnerID string
}

type EndpointResponse added in v0.3.0

type EndpointResponse struct {
	UID         string `json:"uid"`
	GroupID     string `json:"group_id"`
	OwnerID     string `json:"owner_id"`
	TargetUrl   string `json:"target_url"`
	Title       string `json:"title"`
	Description string `json:"description"`

	Status             string   `json:"status"`
	Secrets            []Secret `json:"secrets"`
	AdvancedSignatures bool     `json:"advanced_signatures"`
	SlackWebhookUrl    string   `json:"slack_webhook_url"`
	SupportEmail       string   `json:"support_email"`
	IsDisabled         bool     `json:"is_disabled"`

	HttpTimeout       string `json:"http_timeout"`
	RateLimit         int    `json:"rate_limit"`
	RateLimitDuration string `json:"rate_limit_duration"`

	Authentication *EndpointAuth `json:"authentication"`
	Events         int64         `json:"events"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type Event added in v0.3.0

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

func (*Event) All added in v0.3.0

func (e *Event) All(query *EventQueryParam) (*ListEventResponse, error)

func (*Event) Create added in v0.3.0

func (e *Event) Create(opts *CreateEventRequest, query *EventQueryParam) (*EventResponse, error)

func (*Event) CreateFanoutEvent added in v1.0.2

func (e *Event) CreateFanoutEvent(opts *CreateFanoutEventRequest) (*EventResponse, error)

func (*Event) Find added in v0.3.0

func (e *Event) Find(id string, query *EventQueryParam) (*EventResponse, error)

type EventDelivery added in v0.3.0

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

func (*EventDelivery) All added in v0.3.0

func (*EventDelivery) BatchResend added in v0.3.0

func (e *EventDelivery) BatchResend(opts *BatchResendRequest, query *EventDeliveryQueryParam) error

func (*EventDelivery) Find added in v0.3.0

func (*EventDelivery) Resend added in v0.3.0

type EventDeliveryQueryParam added in v0.3.0

type EventDeliveryQueryParam struct {
	GroupID    string
	EndpointID string
	EventID    string
	PerPage    int
	Page       int
}

type EventDeliveryResponse added in v0.3.0

type EventDeliveryResponse struct {
	UID              string           `json:"uid"`
	EventMetadata    EventMetadata    `json:"event_metadata"`
	EndpointMetadata EndpointResponse `json:"endpoint_metadata"`
	Metadata         Metadata         `json:"metadata"`
	Description      string           `json:"description,omitempty"`
	Status           string           `json:"status"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type EventMetadata added in v0.3.0

type EventMetadata struct {
	UID  string `json:"uid"`
	Name string `json:"name"`
}

type EventQueryParam added in v0.3.0

type EventQueryParam struct {
	GroupID    string
	EndpointID string
	PerPage    int
	Page       int
}

type EventResponse added in v0.3.0

type EventResponse struct {
	UID              string              `json:"uid"`
	EventType        string              `json:"event_type"`
	MatchedEndpoints int                 `json:"matched_endpoints"`
	ProviderID       string              `json:"provider_id"`
	Data             json.RawMessage     `json:"data"`
	EndpointMetadata []*EndpointResponse `json:"endpoint_metadata"`

	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type FilterConfiguration added in v0.3.1

type FilterConfiguration struct {
	EventTypes []string `json:"event_types" bson:"event_types,omitempty"`
}

type HMac added in v0.3.1

type HMac struct {
	Header   string `json:"header"`
	Hash     string `json:"hash"`
	Secret   string `json:"secret"`
	Encoding string `json:"encoding"`
}

type HttpClient added in v0.3.0

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

func NewClient added in v0.3.0

func NewClient(opts Options) *HttpClient

func (*HttpClient) SendRequest added in v0.3.0

func (c *HttpClient) SendRequest(opts *requestOpts) (interface{}, error)

type ListDeliveryAttemptResponse added in v0.3.0

type ListDeliveryAttemptResponse []DeliveryAttemptResponse

type ListEndpointResponse added in v0.3.0

type ListEndpointResponse struct {
	Content    []EndpointResponse `json:"content"`
	Pagination Pagination         `json:"pagination"`
}

type ListEventDeliveryResponse added in v0.3.0

type ListEventDeliveryResponse struct {
	Content    []EventDeliveryResponse `json:"content"`
	Pagination Pagination              `json:"pagination"`
}

type ListEventResponse added in v0.3.0

type ListEventResponse struct {
	Content    []EventResponse `json:"content"`
	Pagination Pagination      `json:"pagination"`
}

type ListProjectResponse added in v1.0.0

type ListProjectResponse []ProjectResponse

type ListSourceResponse added in v0.3.1

type ListSourceResponse struct {
	Content    []SourceResponse `json:"content"`
	Pagination Pagination       `json:"pagination"`
}

type ListSubscriptionResponse added in v0.3.1

type ListSubscriptionResponse struct {
	Content    []SubscriptionResponse `json:"content"`
	Pagination Pagination             `json:"pagination"`
}

type Metadata added in v0.3.0

type Metadata struct {
	// Data to be sent to endpoint.
	Data     json.RawMessage `json:"data"`
	Strategy string          `json:"strategy"`
	// NextSendTime denotes the next time a Event will be published in
	// case it failed the first time
	NextSendTime time.Time `json:"next_send_time"`

	// NumTrials: number of times we have tried to deliver this Event to
	// an application
	NumTrials uint64 `json:"num_trials"`

	IntervalSeconds uint64 `json:"interval_seconds"`

	RetryLimit uint64 `json:"retry_limit"`
}

type Options

type Options struct {
	APIKey      string
	APIEndpoint string
	ProjectID   string
}

type Pagination added in v0.3.0

type Pagination struct {
	Total     int `json:"total"`
	Page      int `json:"page"`
	PerPage   int `json:"perPage"`
	Prev      int `json:"prev"`
	Next      int `json:"next"`
	TotalPage int `json:"totalPage"`
}

type Project added in v1.0.0

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

func (*Project) Delete added in v1.0.0

func (g *Project) Delete(id string) error

func (*Project) Find added in v1.0.0

func (g *Project) Find(id string) (*ProjectResponse, error)

func (*Project) Update added in v1.0.0

func (g *Project) Update(id string, opts *CreateProjectRequest) (*ProjectResponse, error)

type ProjectConfig added in v1.0.0

type ProjectConfig struct {
	RateLimit                *RateLimitConfiguration       `json:"ratelimit"`
	Strategy                 *StrategyConfiguration        `json:"strategy"`
	Signature                *SignatureConfiguration       `json:"signature"`
	RetentionPolicy          *RetentionPolicyConfiguration `json:"retention_policy"`
	DisableEndpoint          bool                          `json:"disable_endpoint"`
	ReplayAttacks            bool                          `json:"replay_attacks"`
	IsRetentionPolicyEnabled bool                          `json:"is_retention_policy_enabled"`
}

type ProjectMetadata added in v1.0.0

type ProjectMetadata struct {
	RetainedEvents int `json:"retained_events"`
}

type ProjectResponse added in v1.0.0

type ProjectResponse struct {
	UID            string         `json:"uid"`
	Name           string         `json:"name"`
	LogoUrl        string         `json:"logo_url"`
	OrganisationID string         `json:"organisation_id"`
	Type           string         `json:"type"`
	Config         *ProjectConfig `json:"config"`
	Statistics     struct {
		MessageSent int `json:"messages_sent"`
		TotalApps   int `json:"total_apps"`
	} `json:"statistics"`
	RateLimit         int              `json:"rate_limit"`
	RateLimitDuration string           `json:"rate_limit_duration"`
	Metadata          *ProjectMetadata `json:"metadata"`

	CreatedAt time.Time `json:"created_at,omitempty"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
}

type ProviderConfig added in v0.3.1

type ProviderConfig struct {
	Twitter *TwitterProviderConfig `json:"twitter" bson:"twitter"`
}

type QueryParameter added in v0.3.0

type QueryParameter struct {
	Parameters map[string]string
}

type RateLimitConfiguration added in v0.3.1

type RateLimitConfiguration struct {
	Count    int    `json:"count"`
	Duration uint64 `json:"duration"`
}

type RetentionPolicyConfiguration added in v0.3.1

type RetentionPolicyConfiguration struct {
	Policy string `json:"policy"`
}

type RetryConfiguration added in v0.3.1

type RetryConfiguration struct {
	Type       string `json:"type"`
	Duration   string `json:"duration"`
	RetryCount int    `json:"retry_count"`
}

type Secret added in v1.0.0

type Secret struct {
	UID   string `json:"uid" bson:"uid"`
	Value string `json:"value" bson:"value"`

	ExpiresAt time.Time  `json:"expires_at,omitempty"`
	CreatedAt time.Time  `json:"created_at,omitempty"`
	UpdatedAt time.Time  `json:"updated_at,omitempty"`
	DeletedAt *time.Time `json:"deleted_at,omitempty"`
}

type SignatureConfiguration added in v0.3.0

type SignatureConfiguration struct {
	Header string `json:"header"`
	Hash   string `json:"hash"`
}

type Source added in v0.3.1

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

func (*Source) All added in v0.3.1

func (s *Source) All(query *SourceQueryParam) (*ListSourceResponse, error)

func (*Source) Create added in v0.3.1

func (s *Source) Create(opts *CreateSourceRequest) (*SourceResponse, error)

func (*Source) Delete added in v0.3.1

func (s *Source) Delete(id string) error

func (*Source) Find added in v0.3.1

func (s *Source) Find(id string) (*SourceResponse, error)

func (*Source) Update added in v0.3.1

func (s *Source) Update(id string, opts *CreateSourceRequest) (*SourceResponse, error)

type SourceQueryParam added in v0.3.1

type SourceQueryParam struct {
	GroupID string
	PerPage int
	Page    int
}

type SourceResponse added in v0.3.1

type SourceResponse struct {
	UID            string          `json:"uid"`
	GroupID        string          `json:"group_id"`
	MaskID         string          `json:"mask_id"`
	Name           string          `json:"name"`
	Type           string          `json:"type"`
	Provider       string          `json:"provider"`
	IsDisabled     bool            `json:"is_disabled"`
	Verifier       *VerifierConfig `json:"verifier"`
	ProviderConfig *ProviderConfig `json:"provider_config"`
	ForwardHeaders []string        `json:"forward_headers"`

	CreatedAt time.Time `json:"created_at,omitempty"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
}

type StrategyConfiguration added in v0.3.0

type StrategyConfiguration struct {
	Type       string `json:"type"`
	Duration   uint64 `json:"duration"`
	RetryCount uint64 `json:"retry_count"`
}

type Subscription added in v0.3.1

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

func (*Subscription) All added in v0.3.1

func (*Subscription) Create added in v0.3.1

func (*Subscription) Delete added in v0.3.1

func (s *Subscription) Delete(id string) error

func (*Subscription) Find added in v0.3.1

func (*Subscription) Update added in v0.3.1

type SubscriptionQueryParam added in v0.3.1

type SubscriptionQueryParam struct {
	GroupID    string
	EndpointID string
	PerPage    int
	Page       int
}

type SubscriptionResponse added in v0.3.1

type SubscriptionResponse struct {
	UID    string `json:"uid"`
	Name   string `json:"name"`
	Type   string `json:"type"`
	Status string `json:"status"`

	Source   *SourceResponse   `json:"source_metadata,omitempty"`
	Endpoint *EndpointResponse `json:"endpoint_metadata,omitempty"`

	// subscription config
	AlertConfig  *AlertConfiguration  `json:"alert_config,omitempty"`
	RetryConfig  *RetryConfiguration  `json:"retry_config,omitempty"`
	FilterConfig *FilterConfiguration `json:"filter_config,omitempty"`

	CreatedAt time.Time `json:"created_at,omitempty"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
}

type TwitterProviderConfig added in v0.3.1

type TwitterProviderConfig struct {
	CrcVerifiedAt time.Time `json:"crc_verified_at"`
}

type VerifierConfig added in v0.3.1

type VerifierConfig struct {
	Type      string     `json:"type,omitempty"`
	HMac      *HMac      `json:"hmac"`
	BasicAuth *BasicAuth `json:"basic_auth"`
	ApiKey    *ApiKey    `json:"api_key"`
}

type Webhook added in v0.3.2

type Webhook struct {
	Payload    []byte
	SigHeader  string
	Secret     string
	IsAdvanced bool
	Encoding   EncodingType
	Hash       string
	Tolerance  time.Duration
}

func NewWebhook added in v0.3.2

func NewWebhook(data *ConfigOpts) *Webhook

func (*Webhook) Verify added in v0.3.2

func (w *Webhook) Verify() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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