twitchhook

package module
v0.0.0-...-ded0729 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2020 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SubscriptionIDToTopic

func SubscriptionIDToTopic(id SubscriptionID) (string, error)

SubscriptionIDToTopic converts an id to a topic

Types

type InMemoryCache

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

InMemoryCache caches subscriptions

func (*InMemoryCache) Delete

func (c *InMemoryCache) Delete(topic string) error

Delete removes a subscription

func (*InMemoryCache) Get

func (c *InMemoryCache) Get(topic string) (*Subscription, error)

Get retrieves a subscription

func (*InMemoryCache) Save

func (c *InMemoryCache) Save(topic string, sub *Subscription) error

Save caches a subscription, returns an error if a subscription already exists

func (*InMemoryCache) SetSubscriptionLease

func (c *InMemoryCache) SetSubscriptionLease(topic string, lease time.Duration) (bool, error)

SetSubscriptionLease retrieves a subscription

type Manager

type Manager interface {
	SubscriptionCallbackHandler() http.HandlerFunc
	Subscribe(req SubscriptionRequest, deniedCallback func(reason string)) error
	Unsubscribe(topic string) error
	ValidateSignature(*http.Request) (valid bool, body io.Reader, err error)
}

Manager takes care of webhooks

type Subscription

type Subscription struct {
	Topic          string
	CallbackURL    string
	Lease          time.Duration
	Secret         string
	DenialCallback func(reason string)
	Renew          func()
}

Subscription is a cache item

type SubscriptionID

type SubscriptionID string

SubscriptionID describes an id

func NewSubscriptionID

func NewSubscriptionID(topic string) (SubscriptionID, error)

NewSubscriptionID generates a random subscription id using topic

type SubscriptionManager

type SubscriptionManager interface {
	Delete(topic string) error
	Get(topic string) (*Subscription, error)
	Save(topic string, sub *Subscription) error
	SetSubscriptionLease(topic string, lease time.Duration) (exists bool, err error)
}

SubscriptionManager manages subscription state

type SubscriptionRequest

type SubscriptionRequest struct {
	Topic           string
	CallbackBaseURL string
	Lease           time.Duration
}

SubscriptionRequest contains parameters for a subscription

type TwitchError

type TwitchError struct {
	Err     string `json:"error"`
	Status  int64  `json:"status"`
	Message string `json:"message"`
}

TwitchError is the api message format for errors

func (TwitchError) Error

func (e TwitchError) Error() string

type TwitchWebhookHandler

type TwitchWebhookHandler struct {
	Manager SubscriptionManager

	OAuth2ClientID     string
	OAuth2ClientSecret string

	Logger *zap.Logger
	// contains filtered or unexported fields
}

TwitchWebhookHandler is an implementation for twitch webhooks

func (*TwitchWebhookHandler) Subscribe

func (m *TwitchWebhookHandler) Subscribe(request SubscriptionRequest, denialCallback func(reason string)) (err error)

Subscribe subscribes the webhook

func (*TwitchWebhookHandler) SubscriptionCallbackHandler

func (m *TwitchWebhookHandler) SubscriptionCallbackHandler() http.HandlerFunc

SubscriptionCallbackHandler handles websub requests

func (*TwitchWebhookHandler) Unsubscribe

func (m *TwitchWebhookHandler) Unsubscribe(topic string) error

Unsubscribe unsubscribes the webhook

func (*TwitchWebhookHandler) ValidateSignature

func (m *TwitchWebhookHandler) ValidateSignature(r *http.Request) (bool, io.Reader, error)

ValidateSignature validates the notification using the subscription's secret

Jump to

Keyboard shortcuts

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