convoy_go

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2022 License: MIT Imports: 11 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",
  })

The SDK also supports authenticating via Basic Auth by providing your username and password

  c := convoy.New(convoy.Options{
      APIUsername: "default",
      APIPassword: "default",
  })

In the event you're using a self hosted convoy instance, you can define the url as part of what is passed into the convoy.Options struct

   c := convoy.New(convoy.Options{
       APIKey: "your_api_key",
       APIEndpoint: "self-hosted-instance",
   })
Creating an Application

An application represents a user's application trying to receive webhooks. Once you create an application, you'll receive a uid as part of the response that you should save and supply in subsequent API calls to perform other requests such as creating an event.

  app, err := c.Applications.Create(&convoy.CreateApplicationRequest{
      Name: "My_app",
      SupportEmail: "support@myapp.com",
  }, nil)

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

After creating an application, you'll need to add an endpoint to the application you just created. An endpoint represents a target URL to receive events.

endpoint, err := c.Endpoints.Create(app.UID, &Convoy.CreateEndpointRequest{
    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 application we created earlier.

event, err := c.Events.Create(&convoy.CreateEventRequest{
		AppID:     app.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 (
	ErrNotListApplicationResponse = errors.New("invalid list application response")
	ErrNotApplicationResponse     = errors.New("invalid application response")
)
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 (
	ErrNotListGroupResponse = errors.New("invalid list group response")
	ErrNotGroupResponse     = errors.New("invalid group response")
)

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 AppMetadata added in v0.3.0

type AppMetadata struct {
	UID          string `json:"uid"`
	Title        string `json:"title"`
	GroupID      string `json:"group_id"`
	SupportEmail string `json:"support_email"`
}

type Application added in v0.3.0

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

func (*Application) All added in v0.3.0

func (*Application) Create added in v0.3.0

func (*Application) Delete added in v0.3.0

func (a *Application) Delete(id string, query *ApplicationQueryParam) error

func (*Application) Find added in v0.3.0

func (*Application) Update added in v0.3.0

type ApplicationQueryParam added in v0.3.0

type ApplicationQueryParam struct {
	GroupID string
	PerPage int
	Page    int
}

type ApplicationResponse added in v0.3.0

type ApplicationResponse struct {
	UID     string `json:"uid"`
	GroupID string `json:"group_id"`
	Name    string `json:"name"`

	Endpoints []EndpointResponse `json:"endpoints"`

	SupportEmail string `json:"support_email"`
	IsDisabled   bool   `json:"is_disabled"`

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

	Events int64 `json:"events"`
}

type BatchResendRequest added in v0.3.0

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

type Convoy

type Convoy struct {
	Applications     *Application
	Groups           *Group
	Endpoints        *Endpoint
	Events           *Event
	EventDeliveries  *EventDelivery
	DeliveryAttempts *DeliveryAttempt
	// contains filtered or unexported fields
}

func New

func New(opts Options) *Convoy

type CreateApplicationRequest added in v0.3.0

type CreateApplicationRequest struct {
	Name         string `json:"name"`
	SupportEmail string `json:"support_email,omitempty"`
	IsDisabled   bool   `json:"is_disabled,omitempty"`
}

type CreateEndpointRequest added in v0.3.0

type CreateEndpointRequest struct {
	URL         string   `json:"url"`
	Secret      string   `json:"secret,omitempty"`
	Description string   `json:"description,omitempty"`
	Events      []string `json:"events,omitempty"`

	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 {
	AppID     string          `json:"app_id"`
	EventType string          `json:"event_type"`
	Data      json.RawMessage `json:"data"`
}

type CreateGroupRequest added in v0.3.0

type CreateGroupRequest struct {
	Name              string      `json:"name"`
	LogoUrl           string      `json:"logo_url,omitempty"`
	RateLimit         int         `json:"rate_limit,omitempty"`
	RateLimitDuration string      `json:"rate_limit_duration,omitempty"`
	Group             GroupConfig `json:"config"`
}

type DefaultStrategyConfiguration added in v0.3.0

type DefaultStrategyConfiguration struct {
	IntervalSeconds uint64 `json:"intervalSeconds"`
	RetryLimit      uint64 `json:"retryLimit"`
}

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 Endpoint added in v0.3.0

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

func (*Endpoint) All added in v0.3.0

func (e *Endpoint) All(appId string, query *EndpointQueryParam) (*ListEndpointResponse, error)

func (*Endpoint) Create added in v0.3.0

func (e *Endpoint) Create(appId string, opts *CreateEndpointRequest, query *EndpointQueryParam) (*EndpointResponse, error)

func (*Endpoint) Delete added in v0.3.0

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

func (*Endpoint) Find added in v0.3.0

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

func (*Endpoint) Update added in v0.3.0

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

type EndpointMetadata added in v0.3.0

type EndpointMetadata struct {
	UID               string `json:"uid"`
	TargetURL         string `json:"target_url"`
	Status            string `json:"status"`
	Secret            string `json:"secret"`
	HttpTimeout       string `json:"http_timeout"`
	RateLimit         int    `json:"rate_limit"`
	RateLimitDuration string `json:"rate_limit_duration"`

	Sent bool `json:"sent"`
}

type EndpointQueryParam added in v0.3.0

type EndpointQueryParam struct {
	GroupID string
}

type EndpointResponse added in v0.3.0

type EndpointResponse struct {
	UID               string   `json:"uid"`
	TargetUrl         string   `json:"target_url"`
	Description       string   `json:"description"`
	Status            string   `json:"status"`
	Secret            string   `json:"secret"`
	HttpTimeout       string   `json:"http_timeout"`
	RateLimit         int      `json:"rate_limit"`
	RateLimitDuration string   `json:"rate_limit_duration"`
	Events            []string `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) 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
	AppID   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 EndpointMetadata `json:"endpoint"`
	AppMetadata      AppMetadata      `json:"app_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
	AppID   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"`
	AppMetadata      AppMetadata     `json:"app_metadata"`

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

type ExponentialBackoffStrategyConfiguration added in v0.3.0

type ExponentialBackoffStrategyConfiguration struct {
	RetryLimit uint64 `json:"retryLimit"`
}

type Group added in v0.3.0

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

func (*Group) All added in v0.3.0

func (g *Group) All(query *GroupQueryParams) (*ListGroupResponse, error)

func (*Group) Create added in v0.3.0

func (g *Group) Create(opts *CreateGroupRequest) (*GroupResponse, error)

func (*Group) Delete added in v0.3.0

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

func (*Group) Find added in v0.3.0

func (g *Group) Find(id string) (*GroupResponse, error)

func (*Group) Update added in v0.3.0

func (g *Group) Update(id string, opts *CreateGroupRequest) (*GroupResponse, error)

type GroupConfig added in v0.3.0

type GroupConfig struct {
	Strategy        StrategyConfiguration  `json:"strategy"`
	Signature       SignatureConfiguration `json:"signature"`
	DisableEndpoint bool                   `json:"disable_endpoint"`
	ReplayAttacks   bool                   `json:"replay_attacks"`
}

type GroupQueryParams added in v0.3.0

type GroupQueryParams struct {
	GroupID string
	Name    string
}

type GroupResponse added in v0.3.0

type GroupResponse struct {
	UID        string      `json:"uid"`
	Name       string      `json:"name"`
	LogoUrl    string      `json:"logo_url"`
	Group      GroupConfig `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"`

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

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 ListApplicationResponse added in v0.3.0

type ListApplicationResponse struct {
	Content    []ApplicationResponse `json:"content"`
	Pagination Pagination            `json:"pagination"`
}

type ListDeliveryAttemptResponse added in v0.3.0

type ListDeliveryAttemptResponse []DeliveryAttemptResponse

type ListEndpointResponse added in v0.3.0

type ListEndpointResponse []EndpointResponse

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 ListGroupResponse added in v0.3.0

type ListGroupResponse []GroupResponse

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
	APIUsername string
	APIPassword 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 QueryParameter added in v0.3.0

type QueryParameter struct {
	Parameters map[string]string
}

type SignatureConfiguration added in v0.3.0

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

type StrategyConfiguration added in v0.3.0

type StrategyConfiguration struct {
	Type               string                                  `json:"type"`
	Default            DefaultStrategyConfiguration            `json:"default"`
	ExponentialBackoff ExponentialBackoffStrategyConfiguration `json:"exponentialBackoff,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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