mi-v1/pluralkit/switch.go

45 lines
1.1 KiB
Go

package pluralkit
import (
"net/http"
"time"
)
type SwitchResponse struct {
Timestamp time.Time `json:"timestamp"`
Members []Member `json:"members"`
}
// Switch tells the PluralKit API who is front.
func (c Client) Switch(memberIDs []string) error {
return c.Do(http.MethodPost, "s/switches", http.StatusNoContent, struct {
Members []string `json:"members"`
}{
Members: memberIDs,
}, nil)
}
// Switches gets a historical view of switches. For pagination see SwitchesBefore.
func (c Client) Switches(systemID string) ([]SwitchResponse, error) {
var result []SwitchResponse
err := c.Do(http.MethodGet, "s/"+systemID+"/switches", http.StatusOK, nil, &result)
if err != nil {
return nil, err
}
return result, nil
}
// SwitchesBefore shows paginated views of switches.
func (c Client) SwitchesBefore(systemID string, before time.Time) ([]SwitchResponse, error) {
var result []SwitchResponse
err := c.Do(http.MethodGet, "s/"+systemID+"/switches?before="+before.Format(time.RFC3339), http.StatusOK, nil, &result)
if err != nil {
return nil, err
}
return result, nil
}