plugapi

package module
v0.0.0-...-2559a60 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2016 License: MIT Imports: 18 Imported by: 0

README

go-plugapi

GoDoc Go Report Card

go-plugapi is a Go client library for the Plug.dj API.

This library is being developed for a bot I am running at just-a-chill-room, so API methods will likely be implemented in the order that they are needed by that application. You can track the status of implementation in this Google spreadsheet (not ready yet). Eventually, I would like to cover the entire Plug.dj API, so contributions are of course always welcome.

The calling pattern and structure or this library is subject to change at any time, so all suggestions for API improvements are welcome and encouraged.

Projects currently being referred to for style (this is my first time writing a framework in Go) and implementation:

Documentation

Index

Constants

View Source
const (
	RegularChatMessage chatMessageType = iota
	EmoteChatMessage
)
View Source
const (
	AuthLoginEndpoint string = "/auth/login"

	ChatDeleteEndpoint string = "/chat/"
	HistoryEndpoint    string = "/rooms/history"
	PlaylistEndpoint   string = "/playlists"

	ModerateAddDJEndpoint       string = "/booth/add"
	ModerateBanEndpoint         string = "/bans/add"
	ModerateBoothEndpoint       string = "/booth"
	ModerateMoveDJEndpoint      string = "/booth/move"
	ModerateMuteEndpoint        string = "/mutes"
	ModeratePermissionsEndpoint string = "/staff/update"
	ModerateRemoveDJEndpoint    string = "/booth/remove/"
	ModerateSkipEndpoint        string = "/booth/skip"
	ModerateStaffEndpoint       string = "/staff/"
	ModerateUnbanEndpoint       string = "/bans/"
	ModerateUnmuteEndpoint      string = "/mutes/"

	SkipMeEndpoint         string = "/booth/skip/me"
	RoomCycleBoothEndpoint string = "/booth/cycle"
	RoomLockBoothEndpoint  string = "/booth/lock"
	RoomInfoEndpoint       string = "/rooms/update"
	RoomJoinEndpoint       string = "/rooms/join"
	RoomStateEndpoint      string = "/rooms/state"

	UserInfoEndpoint       string = "/users/me"
	UserGetAvatarsEndpoint string = "/store/inventory/avatars"
	UserSetAvatarEndpoint  string = "/users/avatar"
)

List of individual REST endpoints

Variables

View Source
var (
	ErrAuthentication         = errors.New("plugapi: authentication failed")
	ErrAuthenticationRequired = errors.New("plugapi: authentication details required")
	ErrUnknownData            = errors.New("plugapi: cannot structify request")
)

General API errors

Functions

func ErrIsDataRequestError

func ErrIsDataRequestError(err error) bool

func ErrIsUnknownResponse

func ErrIsUnknownResponse(err error) bool

Types

type AdvancePayload

type AdvancePayload struct {
	CurrentDJ *User `json:"c"` // TODO: Write unmarshaler for User, with reference to original plug obj??
	DJs       []User
	LastPlay  *struct {
		DJ    *User
		Media Media
		Score PlayScore
	}
	Playback *Playback
}

type Booth

type Booth struct {
	CurrentDJ   int   `json:"currentDJ"`
	IsLocked    bool  `json:"isLocked"`    // Can users join?
	ShouldCycle bool  `json:"shouldCycle"` // Will the queue progress automatically?
	WaitingDJs  []int `json:"waitingDJs"`
}

Booth is the data about the current queue

type ChatPayload

type ChatPayload struct {
	Message   string // The chat message
	MessageID string
	User      *User // Who it came from
	Type      chatMessageType
}

type Config

type Config struct {
	Email     string
	Password  string
	BaseURL   string
	SocketURL string
	Log       *log.Logger
}

Config is the configuration for logging into plug

type ErrDataRequestError

type ErrDataRequestError struct {
	Data     interface{}
	Endpoint string
}

func (ErrDataRequestError) Error

func (e ErrDataRequestError) Error() string

type ErrUnknownResponse

type ErrUnknownResponse struct {
	Response *http.Response
	Endpoint string
}

func (ErrUnknownResponse) Error

func (e ErrUnknownResponse) Error() string

type Event

type Event int

Event defines a Plug Event type

const (
	AdvanceEvent                Event = iota // = "advance"
	BanEvent                                 // = "ban"
	BoothLockedEvent                         // = "boothLocked"
	ChatEvent                                // = "chat"
	ChatCommandEvent                         // = "command"
	ChatDeleteEvent                          // = "chatDelete"
	ChatLevelUpdateEvent                     // = "roomMinChatLevelUpdate"
	CommandEvent                             // = "command"
	DJListCycleEvent                         // = "djListCycle"
	DJListUpdateEvent                        // = "djListUpdate"
	DJListLockedEvent                        // = "djListLocked"
	EarnEvent                                // = "earn"
	FollowJoinEvent                          // = "followJoin"
	FloodChatEvent                           // = "floodChat"
	FriendRequestEvent                       // = "friendRequest"
	GiftedEvent                              // = "gifted"
	GrabEvent                                // = "grab"
	KillSessionEvent                         // = "killSession"
	MaintModeEvent                           // = "plugMaintenance"
	MaintModeAlertEvent                      // = "plugMaintenanceAlert"
	ModerateAddDjEvent                       // = "modAddDJ"
	ModerateAddWaitlistEvent                 // = "modAddWaitList"
	ModerateAmbassadorEvent                  // = "modAmbassador"
	ModerateBanEvent                         // = "modBan"
	ModerateMoveDjEvent                      // = "modMoveDJ"
	ModerateMuteEvent                        // = "modMute"
	ModerateRemoveDjEvent                    // = "modRemoveDJ"
	ModerateRemoveWaitlistEvent              // = "modRemoveWaitList"
	ModerateSkipEvent                        // = "modSkip"
	ModerateStaffEvent                       // = "modStaff"
	NotifyEvent                              // = "notify"
	PdjMessageEvent                          // = "pdjMessage"
	PdjUpdateEvent                           // = "pdjUpdate"
	PingEvent                                // = "ping"
	PlaylistCycleEvent                       // = "playlistCycle"
	RequestDurationEvent                     // = "requestDuration"
	RequestDurationRetryEvent                // = "requestDurationRetry"
	RoomChangeEvent                          // = "roomChanged"
	RoomDescriptionUpdateEvent               // = "roomDescriptionUpdate"
	RoomJoinEvent                            // = "roomJoin"
	RoomNameUpdateEvent                      // = "roomNameUpdate"
	RoomVoteSkipEvent                        // = "roomVoteSkip"
	RoomWelcomeUpdateEvent                   // = "roomWelcomeUpdate"
	SessionCloseEvent                        // = "sessionClose"
	SkipEvent                                // = "skip"
	StrobeToggleEvent                        // = "strobeToggle"
	UserCounterUpdateEvent                   // = "userCounterUpdate"
	UserFollowEvent                          // = "userFollow"
	UserJoinEvent                            // = "userJoin"
	UserLeaveEvent                           // = "userLeave"
	UserUpdateEvent                          // = "userUpdate"
	VoteEvent                                // = "vote"
)

List of Event types

type HistoryItem

type HistoryItem struct {
	ID    string `json:"id"`
	Media Media  `json:"media"`
	Room  struct {
		Name string `json:"name"`
		Slug string `json:"slug"`
	} `json:"room"`
	Score     PlayScore `json:"score"`
	Timestamp string    `json:"timestamp"` // Format: xx-xx-xx
	User      struct {
		ID       int    `json:"id"`
		Username string `json:"username"`
	}
}

HistoryItem is an individual item in the room history

type IntBool

type IntBool bool

func (*IntBool) UnmarshalJSON

func (b *IntBool) UnmarshalJSON(data []byte) error

type Media

type Media struct {
	Author   string `json:"author"`
	CID      string `json:"cid"`
	Duration int    `json:"duration"` // default: -1
	Format   int    `json:"format"`   // default: -1
	ID       int    `json:"id"`       // default: -1
	Image    string `json:"image"`
	Title    string `json:"title"`
}

type PlayScore

type PlayScore struct {
	Grabs     int `json:"grabs"`
	Listeners int `json:"listeners"`
	Negative  int `json:"negative"`
	Positive  int `json:"positive"`
	Skipped   int `json:"skipped"`
}

PlayScore is the score of an individual song

type Playback

type Playback struct {
	HistoryID  string `json:"historyID"`
	Media      Media  `json:"media"`
	PlaylistID int    `json:"playlistID"` // default: -1
	StartTime  string `json:"startTime"`
}

Playback metadata about an existing play (note, not the song)

type PlugDJ

type PlugDJ struct {
	Room    *Room
	History []HistoryItem
	User    *User
	Log     *log.Logger
	// contains filtered or unexported fields
}

PlugDJ is the individual user connected to plug

func New

func New(config Config) (*PlugDJ, error)

New returns an authenticated User

func (*PlugDJ) Close

func (plug *PlugDJ) Close()

func (*PlugDJ) Get

func (plug *PlugDJ) Get(endpoint string) (*http.Response, error)

Get makes a get request to the plug API

func (*PlugDJ) GetData

func (plug *PlugDJ) GetData(endpoint string, data interface{}, meta interface{}) error

GetData allows you to receive info as a struct

func (*PlugDJ) JoinRoom

func (plug *PlugDJ) JoinRoom(slug string) error

func (*PlugDJ) ModerateDeleteMessage

func (plug *PlugDJ) ModerateDeleteMessage(messageID string) error

func (*PlugDJ) Post

func (plug *PlugDJ) Post(endpoint string, data map[string]string) (*http.Response, error)

Post makes a post request with the map provided as json to the plug API

func (*PlugDJ) RegisterEvents

func (plug *PlugDJ) RegisterEvents(fn ProcessPayloadFunc, events ...Event)

RegisterEvents registers the function to call when the specified event(s) are encountered Note: only one function can be registered to a single event - it will replace any existing handler.

func (*PlugDJ) SendChat

func (plug *PlugDJ) SendChat(msg string) error

type ProcessPayloadFunc

type ProcessPayloadFunc func(plug *PlugDJ, payload interface{})

ProcessPayloadFunc is a common function for payload return values

type Room

type Room struct {
	sync.RWMutex
	Booth Booth `json:"booth"`
	// FX interface{} `json:"fx"`
	// Grabs interface{} `json:"grabs"`
	Meta struct {
		Description      string `json:"description"`
		Favorite         bool   `json:"favorite"`       // Does the logged in user love this room?
		Guests           int    `json:"guests"`         // Number of guests connected
		HostID           int    `json:"hostID"`         // User ID of the room owner. default: -1
		HostName         string `json:"hostName"`       // Username of the room owner
		ID               int    `json:"id"`             // unique room identifier. default: -1
		MinimumChatLevel int    `json:"minChatLevel"`   // power required to speak. default: 1 (POSITIVE 1)
		Name             string `json:"name"`           // name of the room
		Population       int    `json:"population"`     // Number of real users in the room (guests excluded)
		Slug             string `json:"slug"`           // string shortname
		WelcomeMessage   string `json:"welcomemessage"` // the welcome message on entering
	} `json:"meta"`
	// Mutes interface{} `json:"mutes"`
	Playback *Playback `json:"playback"`
	// contains filtered or unexported fields
}

Room contains metadata about the room TODO: Unexport this.

func (*Room) GetUsers

func (r *Room) GetUsers() (u []User)

func (*Room) SetUsers

func (r *Room) SetUsers(u []User)

Warning: This isn't copied

type User

type User struct {
	ID       int    `json:"id"`
	Role     int    `json:"role"`
	Username string `json:"username"`
}

type UserJoinPayload

type UserJoinPayload struct{ User }

type UserLeavePayload

type UserLeavePayload struct{ User }

Jump to

Keyboard shortcuts

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