plexhooks

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2020 License: Apache-2.0 Imports: 11 Imported by: 1

README

Plex Hooks

Go Report Card

Library to listen Plex Webhook Events and execute actions.

Plex Webhooks require a Plex Pass subscription

Installation

Use the library in your own app to register your actions.

go get github.com/acamilleri/go-plexhooks

Usage

You can check a real world example with myplexhooks repository.

Example:

package main

import (
    "net"

    "github.com/sirupsen/logrus"
    "github.com/acamilleri/go-plexhooks"
    "github.com/acamilleri/go-plexhooks/plex"
)

type MyActionOnMediaPlay struct{}

func (a *MyActionOnMediaPlay) Name() string {
	return "MyActionOnMediaPlay"
}

func (a *MyActionOnMediaPlay) Execute(event plex.Event) error {
	fmt.Printf("I'm print a message when i received a MediaPlay event")
	return nil
}

func main() {
	listenAddr, err := net.ResolveTCPAddr("tcp4", "127.0.0.1:8080")
	if err != nil {
		panic(err)
	}

	actions := plexhooks.NewActions()
	actions.Add(plex.MediaPlay, &MyActionOnMediaPlay{})

	app := plexhooks.New(plexhooks.Definition{
		ListenAddr: listenAddr,
		Actions:    actions,
		Logger: plexhooks.LoggerDefinition{
			Level:     logrus.InfoLevel,
			Formatter: &logrus.JSONFormatter{},
		},
	})
    
    err := app.Run()
    if err != nil {
        panic(err)
    }
}
Metrics

The Run function running a metrics handler to have some metrics about the events handler and actions executed.

Metrics are expose at /metrics path in Prometheus format.

You can find all metrics available here

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action interface {
	Name() string
	Execute(event plex.Event) error
}

Action generic interface to create action

type Actions

type Actions map[plex.Name][]Action

Actions list of Action by Event name

func NewActions

func NewActions() *Actions

NewActions return an initialize map to define actions to run on each event

func (*Actions) Add

func (a *Actions) Add(hook plex.Name, actions ...Action)

Add define one action or multiple actions to run on Event

func (*Actions) GetByHook

func (a *Actions) GetByHook(hook plex.Name) []Action

GetByHook get actions by hook name

type App

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

App struct with listenAddr and actions

func New

func New(definition Definition) *App

New create app from Definition values

func (*App) Run

func (a *App) Run() error

Run running app with http server

type Definition

type Definition struct {
	ListenAddr *net.TCPAddr
	Actions    *Actions
	Logger     LoggerDefinition
}

Definition app configuration

type LoggerDefinition

type LoggerDefinition struct {
	Level     logrus.Level
	Formatter logrus.Formatter
}

LoggerDefinition logger configuration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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