Documentation
¶
Index ¶
Constants ¶
const ( // APIVERSION specifies API version APIVERSION = "v1" // Timeout is bot response timeout Timeout = 3 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API struct {
// contains filtered or unexported fields
}
API provides a simple HTTP API
func NewAPI ¶
NewAPI creates and configures API server
NewAPI creates and initializes API server with provided configuration It returns error if either configuration is invalid or if API server could not be created
func (*API) ListenAndServe ¶
ListenAndServe starts API server and listens for HTTP requests
ListenAndServe blocks until http server returns error Due to its blocking behaviour this function should be run in its own goroutine
type Bot ¶
Bot plays spotify songs when requested
func NewBot ¶
NewBot creates new alertify bot and returns it It fails with error if neither of the following couldnt be created: Spotify API client, Slack API client, HTTP API service
func (*Bot) ListenAndAlert ¶
ListenAndAlert starts Bot message listener and plays Spotify song when it receives alert message This is a blocking function call and therefore should be run in a dedicated goroutine
func (*Bot) RegisterMonitor ¶
RegisterMonitor registers remote monitor
type BotConfig ¶
type BotConfig struct {
// Spotify configures Spotify API client
Spotify *SpotifyConfig
}
BotConfig configures alertify bot
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context provides API service context
type Monitor ¶
type Monitor interface {
// MonitorAndAlert sends messages to message channel
MonitorAndAlert(chan<- *Msg) error
// Stop stops the monitor
Stop()
// String implements stringer interface
String() string
}
Monitor monitors some activity and sends message to channel
type Msg ¶
type Msg struct {
// Cmd is specifies command name
Cmd string
// Data allows to attach arbitrary data to the message
Data interface{}
// Resp is a channel used to send response back to monitor
Resp chan interface{}
}
Msg is allows to control aleritfy bot behavior
type SpotifyAuth ¶
type SpotifyAuth struct {
// Spotify authenticator
*spotify.Authenticator
// State is OAuth state
State string
// RedirectURI is Spotify RedirectURI
RedirectURI string
}
SpotifyAuth allows to authenticate with Spotify API
func NewSpotifyAuth ¶
func NewSpotifyAuth(clientID, clientSecret, redirectURI, state string) *SpotifyAuth
NewSpotifyAuth returns SpotifyAuth which is used to authenticate with Spotify API
type SpotifyClient ¶
type SpotifyClient struct {
// Spotify client
*spotify.Client
// mutex
*sync.Mutex
// contains filtered or unexported fields
}
SpotifyClient implements Spotify client
func NewSpotifyClient ¶
func NewSpotifyClient(c *SpotifyConfig) (*SpotifyClient, error)
NewSpotifyClient authenticates with Spotify API and returns SpotifyClient It returns error if Spotify API authentication fails
func (*SpotifyClient) Device ¶
func (s *SpotifyClient) Device() *spotify.PlayerDevice
Device returns Spotify active playback device
func (*SpotifyClient) Pause ¶
func (s *SpotifyClient) Pause() error
Pause pauses active playback on a currently active Spotify device It returns error if the playback can't be paused
func (*SpotifyClient) PlaySong ¶
func (s *SpotifyClient) PlaySong(songURI string) error
PlaySong plays Spotify song passed in as songURI
func (*SpotifyClient) SetDevice ¶
func (s *SpotifyClient) SetDevice(deviceID, deviceName string) error
SetDevice allows to set Spotify player device on which you can play alert song If deviceID is empty string, it searches for device ID of the device specified by deviceName If both deviceID and deviceName are empty Spotify client will use the first active device it finds
type SpotifyConfig ¶
type SpotifyConfig struct {
// ClientID is Spotify Client ID
ClientID string
// ClientSecret is Spotify Client secret
ClientSecret string
// RedirectURI is Spotify app OAuth redirect URI
RedirectURI string
// DeviceID is Spotify device ID
DeviceID string
// DeviceName is Spotify device name
DeviceName string
// SongURI is Spotify song URI
SongURI string
}
SpotifyConfig configures Spotify API client