myradio

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

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

Go to latest
Published: Sep 23, 2022 License: MIT Imports: 10 Imported by: 12

README

MyRadio.go

Build Status Coverage Status

A go wrapper for the MyRadio API. Incomplete. Quick and dirty. Originally for the go rewrite of aliasgen.

Usage

import "github.com/UniversityRadioYork/myradio-go"

...

session, _ := myradio.NewSession("your_api_key")

lists := session.GetAllLists()

Testing

$ go test

Documentation

Index

Constants

View Source
const (
	// Values for the current selection/where it was selected from
	SelectorStudio1 = 1
	SelectorStudio2 = 2
	SelectorJukebox = 3
	SelectorOffAir  = 8
	SelectorOB      = 4
	SelectorAux     = 0
	SelectorHub     = 3
	// Values for the selector lock
	LockOff = 0
	LockAux = 1
	LockKey = 2
	// Values for studio power
	OnNone = 0
	OnS1   = 1
	OnS2   = 2
	OnBoth = 3
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Album

type Album struct {
	// ID is the unique database ID of the album.
	ID uint64 `json:"recordid"`

	// Title is the title of the track.
	Title string `json:"title"`
	// Artist is the primary credited artist of the track.
	Artist string `json:"artist"`

	// DateAdded is the date on which the album entered the MyRadio library.
	DateAdded string `json:"date_added"`
	// DateReleased is the date on which the album was released.
	DateReleased string `json:"date_released"`
	// LastModified is the date on which the album was last modified.
	LastModified string `json:"last_modified"`

	// CDID is the ID of the CD, if this track comes from one.
	CDID string `json:"cdid"`

	// Location is the location of the physical copy of this album, if any.
	Location string `json:"location"`
	// ShelfLetter is the shelf on which the physical copy resides, if any.
	ShelfLetter string `json:"shelf_letter"`
	// ShelfNumber is the position on the shelf on which the physical copy resides, if any.
	ShelfNumber uint64 `json:"shelf_number"`

	// Format is a single-character code identifying the physical format.
	Format string `json:"format"`
	// Medium is a single-character code identifying the physical medium.
	Medium string `json:"media"`

	// AddingMember is the ID of the member who added this album.
	AddingMember uint64 `json:"member_add"`
	// EditingMember is the ID of the member who last modified this album.
	EditingMember uint64 `json:"member_edit"`

	// RecordLabel is the record label responsible for this album.
	RecordLabel string `json:"record_label"`

	// Status is the digitisation status code for this album.
	Status string `json:"status"`
}

Album contains information about an album in the URY track database.

type Alias

type Alias struct {
	Id           int `json:"alias_id"`
	Source       string
	Destinations []struct {
		Atype string `json:"type"`
		Value *json.RawMessage
	}
}

Alias represents a mail alias.

type Banner struct {
	BannerID int    `json:"banner_id"`
	Alt      string `json:"alt"`
	Target   string `json:"target"`
	URL      string `json:"url"`
}

Banner represents the key information about banners

type College

type College struct {
	CollegeId   int    `json:"value,string"`
	CollegeName string `json:"text"`
}

College represents a college.

type Credit

type Credit struct {
	Type     int  `json:"type"`
	MemberID int  `json:"memberid"`
	User     User `json:"User"`
}

Credit represents a show credit associating a user with a show.

type CurrentAndNext

type CurrentAndNext struct {
	Next    Show `json:"next"`
	Current Show `json:"current"`
}

CurrentAndNext stores a pair of current and next show.

type Link struct {
	Display string      `json:"display"`
	Value   interface{} `json:"value"`
	Title   string      `json:"title,omitempty"`
	URL     string      `json:"url"`
}

Link represents a MyRadio action link.

type List

type List struct {
	Listid     int
	Name       string
	Address    string
	Recipients int `json:"recipient_count"`
}

List represents a mailing list.

type Officer

type Officer struct {
	User            User `json:"user"`
	From            time.Time
	FromRaw         int64           `json:"from"`
	MemberOfficerID uint            `json:"memberofficerid"`
	Position        OfficerPosition `json:"position"`
}

Officer represents information about an officership inside a Team.

type OfficerPosition

type OfficerPosition struct {
	OfficerID   int
	Name        string
	Alias       string
	Team        Team
	Ordering    int
	Description string
	Status      string
	Type        string
	Current     []User `json:"current,omitempty"`
	History     []struct {
		User            User
		From            time.Time
		FromRaw         int64 `json:"from"`
		To              time.Time
		ToRaw           int64 `json:"to"`
		MemberOfficerID int
	} `json:"history,omitempty"`
}

OfficerPosition represents a specific station officer position.

type Officership

type Officership struct {
	OfficerId   uint   `json:"officerid,string"`
	OfficerName string `json:"officer_name"`
	TeamId      uint   `json:"teamid,string"`
	FromDateRaw string `json:"from_date,omitempty"`
	FromDate    time.Time
	TillDateRaw string `json:"till_date,omitempty"`
	TillDate    time.Time
}

Officership represents an officership a user holds.

type Photo

type Photo struct {
	PhotoId      uint   `json:"photoid"`
	DateAddedRaw string `json:"date_added"`
	DateAdded    time.Time
	Format       string `json:"format"`
	Owner        uint   `json:"owner"`
	Url          string `json:"url"`
}

Photo represents a photo of a user.

type Podcast

type Podcast struct {
	PodcastID     int `json:"podcast_id"`
	Title         string
	Description   string
	Status        string
	Time          Time
	Photo         string
	File          string `json:"uri"`
	EditLink      Link   `json:"editlink"`
	MicrositeLink Link   `json:"micrositelink"`
	Show          *ShowMeta
}

Podcast represents a podcast media item.

type Season

type Season struct {
	ShowMeta
	SeasonID      int    `json:"season_id"`
	SeasonNum     int    `json:"season_num"`
	SubmittedRaw  string `json:"submitted"`
	Submitted     time.Time
	RequestedTime string `json:"requested_time"`
	FirstTimeRaw  string `json:"first_time"`
	FirstTime     time.Time
	NumEpisodes   Link              `json:"num_episodes"`
	AllocateLink  Link              `json:"allocatelink"`
	RejectLink    Link              `json:"rejectlink"`
	Subtype       ShowSeasonSubtype `json:"subtype"`
}

Season represents a season in the MyRadio schedule. A MyRadio season contains timeslots.

type SelectorInfo

type SelectorInfo struct {
	Studio       int `json:"studio"`
	Lock         int `json:"lock"`
	SelectedFrom int `json:"selectedfrom"`
	Power        int `json:"power"`
}

SelectorInfo holds data from the /selector/query endpoint

type Session

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

Session represents an open API session.

func MockSession

func MockSession(message []byte) (*Session, error)

MockSession creates a new mocked API session returning the JSON message stored in message.

func NewSession

func NewSession(apikey string) (*Session, error)

NewSession constructs a new Session with the given API key.

func NewSessionForServer

func NewSessionForServer(apikey, server string) (*Session, error)

NewSessionForServer constructs a new Session with the given API key for a non-standard server URL.

func NewSessionFromKeyFile

func NewSessionFromKeyFile() (*Session, error)

NewSessionFromKeyFile tries to open a Session with the key from an API key file.

func NewSessionFromKeyFileForServer

func NewSessionFromKeyFileForServer(server string) (*Session, error)

NewSessionFromKeyFileForServer tries to open a Session with the key from an API key file, with a non-standard server.

func (*Session) CreateOrActivateUser

func (s *Session) CreateOrActivateUser(formParams map[string][]string) (user *User, err error)

CreateOrActivateUser creates oir activates a new myradio user with the given parameters This consumes one API request.

func (*Session) Get

func (s *Session) Get(id int) (podcast *Podcast, err error)

Get retrieves the data for a single podcast from MyRadio given it's ID. This consumes one API request.

func (*Session) GetAllAliases

func (s *Session) GetAllAliases(mixins []string) (aliases []Alias, err error)

GetAllAliases retrieves all aliases in use. It takes a list of additional MyRadio API mixins to use when retrieving the aliases. This consumes one API request.

func (*Session) GetAllLists

func (s *Session) GetAllLists() (lists []List, err error)

GetAllLists retrieves all mailing lists in the MyRadio system. This consumes one API request.

func (*Session) GetAllOfficerPositions

func (s *Session) GetAllOfficerPositions(mixins []string) (positions []OfficerPosition, err error)

GetAllOfficerPositions retrieves all officer positions in MyRadio. The amount of detail can be controlled by adding MyRadio mixins. This consumes one API request.

func (*Session) GetAllPodcasts

func (s *Session) GetAllPodcasts(numResults int, page int, includeSuspended bool) (podcasts []Podcast, err error)

GetAllPodcasts retrieves the latest podcasts from MyRadio. This consumes one API request.

func (*Session) GetAllSeasonsInLatestTerm

func (s *Session) GetAllSeasonsInLatestTerm() (seasons []Season, err error)

GetAllSeasonsInLatestTerm gets all seasons in the most recent term. This consumes one API request.

func (*Session) GetAllShortURLs

func (s *Session) GetAllShortURLs() (urls []ShortURL, err error)

func (*Session) GetAllShowPodcasts

func (s *Session) GetAllShowPodcasts(id int) (result []Podcast, err error)

GetAllShowPodcasts returns all podcasts linked to the given show.

func (*Session) GetAllShowSubtypes

func (s *Session) GetAllShowSubtypes() (subtypes []ShowSeasonSubtype, err error)

GetAllShowSubtypes returns an array of all ShowSeasonSubtypes

func (*Session) GetColleges

func (s *Session) GetColleges() (colleges []College, err error)

GetColleges retrieves a list of all current colleges This consumes one API request.

func (*Session) GetCreditsToUsers

func (s *Session) GetCreditsToUsers(id int, isTimeslot bool) (creditsToUsers map[string][]User, err error)

GetCreditsToUsers retrieves a map of credit names to users. This consumes two API request.

func (*Session) GetCurrentAndNext

func (s *Session) GetCurrentAndNext() (can *CurrentAndNext, err error)

GetCurrentAndNext gets the current and next shows at the time of the call. This consumes one API request.

func (*Session) GetCurrentTeams

func (s *Session) GetCurrentTeams() (teams []Team, err error)

GetCurrentTeams retrieves all teams inside the station committee. This consumes one API request.

func (*Session) GetCurrentTimeslot

func (s *Session) GetCurrentTimeslot() (timeslot Timeslot, err error)

GetCurrentTimeslot retrieves the current timeslot. This consumes one API request.

func (*Session) GetCurrentTimeslotAtTime

func (s *Session) GetCurrentTimeslotAtTime(time int) (timeslot Timeslot, err error)

GetCurrentTimeslotAtTime retrieves the current timeslot. This consumes one API request.

func (*Session) GetLiveBanners

func (s *Session) GetLiveBanners() (banners []Banner, err error)

GetLiveBanners gets the current live banners and returns a slice of banners

func (*Session) GetNowPlaying

func (s *Session) GetNowPlaying(allowOffAir bool) (Track, error)

GetNowPlaying returns a Track struct of the currently playing track allowOffAir is for if jukebox should be included even if it is off air This consumes one API request

func (*Session) GetPodcastRSS

func (s *Session) GetPodcastRSS(id int) (result string, err error)

func (*Session) GetPodcastWithShow

func (s *Session) GetPodcastWithShow(id int) (podcast *Podcast, err error)

Get retrieves the data for a single podcast, and its associated show. This only consumes one API request.

func (*Session) GetPreviousTimeslots

func (s *Session) GetPreviousTimeslots(numOfTimeslots int) (timeslots []Timeslot, err error)

GetPreviousTimeslots gets the previous shows at the time of the call. This consumes one API request.

func (*Session) GetSearchMeta

func (s *Session) GetSearchMeta(term string) (shows []ShowMeta, err error)

GetSearchMeta retrieves all shows whose metadata matches a given search term. This consumes one API request.

func (*Session) GetSeason

func (s *Session) GetSeason(id int) (season Season, err error)

GetSeason retrieves the season with the given ID. This consumes one API request.

func (*Session) GetSeasons

func (s *Session) GetSeasons(id int) (seasons []Season, err error)

GetSeasons retrieves the seasons of the show with the given ID. This consumes one API request.

func (*Session) GetSelectorInfo

func (s *Session) GetSelectorInfo() (info *SelectorInfo, err error)

GetSelectorInfo retrieves the current status of the selector This consumes one API request.

func (*Session) GetShow

func (s *Session) GetShow(id int) (show *ShowMeta, err error)

GetShow retrieves the show with the given ID. This consumes one API request.

func (*Session) GetShowSubtypeByClass

func (s *Session) GetShowSubtypeByClass(class string) (subtype *ShowSeasonSubtype, err error)

GetShowSubtypeByClass returns a ShowSeasonSubtype based on a given class Can return nil pointer if no subtype found for given class

func (*Session) GetTeamAssistantHeadPositions

func (s *Session) GetTeamAssistantHeadPositions(id int, mixins []string) (assHead []Officer, err error)

GetTeamAssistantHeadPositions retrieves all assistant-head-of-team positions for a given team ID. The amount of detail can be controlled using MyRadio mixins. This consumes one API request.

func (*Session) GetTeamHeadPositions

func (s *Session) GetTeamHeadPositions(id int, mixins []string) (head []Officer, err error)

GetTeamHeadPositions retrieves all head-of-team positions for a given team ID. The amount of detail can be controlled using MyRadio mixins. This consumes one API request.

func (*Session) GetTeamOfficerPositions

func (s *Session) GetTeamOfficerPositions(id int, mixins []string) (officer []Officer, err error)

GetTeamOfficerPositions retrieves all the other officer positions for a given team ID. The amount of detail can be controlled using MyRadio mixins. This consumes one API request.

func (*Session) GetTeamWithOfficers

func (s *Session) GetTeamWithOfficers(teamName string) (team Team, err error)

GetTeamWithOfficers retrieves a team record with officer information for the given team name. This consumes one API request.

func (*Session) GetTimeslot

func (s *Session) GetTimeslot(id int) (timeslot Timeslot, err error)

GetTimeslot retrieves the timeslot with the given ID. This consumes one API request.

func (*Session) GetTimeslotMetadata

func (s *Session) GetTimeslotMetadata(timeslotId uint64, key string) (value string, err error)

GetTimeslotMetadata gets a metadata key for the timeslot. Be careful. Returns nil err and an empty string if the key does not exist, err if something went wrong.

func (*Session) GetTimeslotsForSeason

func (s *Session) GetTimeslotsForSeason(id int) (timeslots []Timeslot, err error)

GetTimeslotsForSeason retrieves all timeslots for the season with the given ID. This consumes one API request.

func (*Session) GetTrack

func (s *Session) GetTrack(trackid uint64) (track *Track, err error)

GetTrack tries to get the Track with the given ID. Track IDs are unique, so we do not need the record ID. This consumes one API request.

func (*Session) GetTrackAlbum

func (s *Session) GetTrackAlbum(trackid uint64) (album *Album, err error)

GetTrackAlbum tries to get the Album of the track with the given ID. This consumes one API request.

func (*Session) GetTrackListForTimeslot

func (s *Session) GetTrackListForTimeslot(id int) (tracklist []TracklistItem, err error)

GetTrackListForTimeslot retrieves the tracklist for the timeslot with the given ID. This consumes one API request.

func (*Session) GetTrackTitle

func (s *Session) GetTrackTitle(trackid uint64) (title string, err error)

GetTrackTitle tries to get the title of the track with the given ID. This consumes one API request.

func (*Session) GetUser

func (s *Session) GetUser(id int) (user *User, err error)

GetUser retrieves the User with the given ID. This consumes one API request.

func (*Session) GetUserAliases

func (s *Session) GetUserAliases() ([]UserAlias, error)

GetUserAliases retrieves all aliases associated with the user with the given ID. This consumes one API request.

func (*Session) GetUserBio

func (s *Session) GetUserBio(id int) (bio string, err error)

GetUserBio retrieves the biography of the user with the given ID. This consumes one API request.

func (*Session) GetUserName

func (s *Session) GetUserName(id int) (name string, err error)

GetUserName retrieves the name of the user with the given ID. This consumes one API request.

func (*Session) GetUserOfficerships

func (s *Session) GetUserOfficerships(id int) (officerships []Officership, err error)

GetUserOfficerships retrieves all officerships held by the user with the given ID. This consumes one API request.

func (*Session) GetUserProfilePhoto

func (s *Session) GetUserProfilePhoto(id int) (profilephoto Photo, err error)

GetUserProfilePhoto retrieves the profile photo of the user with the given ID. This consumes one API request.

func (*Session) GetUserShowCredits

func (s *Session) GetUserShowCredits(id int) (shows []ShowMeta, err error)

GetUserShowCredits retrieves all show credits associated with the user with the given ID. This consumes one API request.

func (*Session) GetUsers

func (s *Session) GetUsers(l *List) (users []User, err error)

GetUsers retrieves all users subscribed to a given mailing list. This consumes one API request.

func (*Session) GetWeekSchedule

func (s *Session) GetWeekSchedule(year, week int) (map[int][]Timeslot, error)

GetWeekSchedule gets the weekly schedule for ISO 8601 week week of year year. If such a schedule exists, it returns the result as an map from ISO 8601 weekdays to timeslot slices. Thus, 1 maps to Monday's timeslots; 2 to Tuesday; and so on. Each slice progresses chronologically from start of URY day to finish of URY day. If no such schedule exists, it returns a map of empty slices. If an error occurred, this is returned in error, and the timeslot map is undefined. This consumes one API request.

func (*Session) LogShortURLClick

func (s *Session) LogShortURLClick(id uint, userAgent, ipAddress string) error

func (*Session) OptIn

func (s *Session) OptIn(UserID int, ListID int) (err error)

OptIn subscribes the given user to the given list This consumes one API request.

func (*Session) PutMessage

func (s *Session) PutMessage(id uint64, msg string) (err error)

PutMessage sends a message to the given timeslot. This consumes one API request.

type ShortURL

type ShortURL struct {
	ShortURLID uint   `json:"short_url_id"`
	Slug       string `json:"slug"`
	RedirectTo string `json:"redirect_to"`
}

ShortURL represents the key information of a short URL.

type Show

type Show struct {
	Title      string `json:"title"`
	Desc       string `json:"desc"`
	Photo      string `json:"photo"`
	StartTime  Time   `json:"start_time"`
	EndTime    Time   `json:"end_time"` // Sometimes "The End of Time"
	Presenters string `json:"presenters,omitempty"`
	Url        string `json:"url,omitempty"`
	Id         uint64 `json:"id,omitempty"`
}

Show contains a summary of information about a URY schedule timeslot.

func (*Show) Ends

func (s *Show) Ends() bool

Ends determines whether the Show has a defined end time.

type ShowMeta

type ShowMeta struct {
	ShowID        int               `json:"show_id"`
	Title         string            `json:"title"`
	CreditsString string            `json:"credits_string"`
	Credits       []Credit          `json:"credits"`
	Description   string            `json:"description"`
	ShowTypeID    int               `json:"show_type_id"`
	Season        Link              `json:"seasons"`
	EditLink      Link              `json:"editlink"`
	ApplyLink     Link              `json:"applylink"`
	MicroSiteLink Link              `json:"micrositelink"`
	Photo         string            `json:"photo"`
	Subtype       ShowSeasonSubtype `json:"subtype"`
}

ShowMeta represents a show in the MyRadio schedule. A MyRadio show contains seasons, each containing timeslots. @TODO: Refactor this to something better named

type ShowSeasonSubtype

type ShowSeasonSubtype struct {
	SubtypeID   string `json:"id"`
	Name        string `json:"name"`
	Class       string `json:"class"`
	Description string `json:"description"`
}

ShowSeasonSubtype gives information about an available show subtype

type Team

type Team struct {
	TeamID      uint      `json:"teamid"`
	Name        string    `json:"name"`
	Alias       string    `json:"alias"`
	Ordering    uint      `json:"ordering"`
	Description string    `json:"description"`
	Status      string    `json:"status"`
	Officers    []Officer `json:"officers"`
}

Team represents a station committee team.

type Time

type Time struct {
	time.Time
}

Time is a custom time wrapper

func (*Time) UnmarshalJSON

func (t *Time) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON a method to convert myradio times to unit time stamps

type Timeslot

type Timeslot struct {
	Season
	TimeslotID     uint64   `json:"timeslot_id"`
	TimeslotNum    int      `json:"timeslot_num"`
	Tags           []string `json:"tags"`
	Time           Time     `json:"time"`
	StartTime      time.Time
	StartTimeRaw   string `json:"start_time"`
	Duration       time.Duration
	DurationRaw    string `json:"duration"`
	MixcloudStatus string `json:"mixcloud_status"`
}

Timeslot contains information about a single timeslot in the URY schedule. A timeslot is a single slice of time on the schedule, typically one hour long.

type Track

type Track struct {
	// ID is the unique database ID of the track.
	ID uint64 `json:"trackid"`

	// Title is the title of the track.
	Title string `json:"title"`
	// Artist is the primary credited artist of the track.
	Artist string `json:"artist"`
	// Type is the type ('central' etc.) of the track.
	Type string `json:"type"`
	// Length is the length of the track, in hours:minutes:seconds.
	Length string `json:"length"`
	// Intro is length of the track's intro, in seconds.
	Intro uint64 `json:"intro"`
	// IsClean is true if this track is clean (no expletives).
	IsClean bool `json:"clean"`
	// IsDigitised is true if this track is available in the playout system.
	IsDigitised bool `json:"digitised"`
}

Track contains information about a track in the URY track database.

func (*Track) GetAlbum

func (t *Track) GetAlbum(s *Session) (*Album, error)

GetAlbum tries to get the Album for the given Track. This consumes one API request.

func (*Track) IntroUsec

func (t *Track) IntroUsec() uint64

IntroUsec returns the track's intro in microseconds. This consumes no API requests.

func (*Track) LengthSec

func (t *Track) LengthSec() (uint64, error)

LengthSec returns the track's length in seconds. Returns an error if the track's length is ill-formed. This consumes no API requests.

func (*Track) LengthUsec

func (t *Track) LengthUsec() (uint64, error)

LengthUsec returns the track's length in microseconds. This is not precise, as it is derived from the length in seconds. Consider estimating the correct length from the track file itself. Returns an error if the track's length is ill-formed. This consumes no API requests.

type TracklistItem

type TracklistItem struct {
	Track
	Album        Album `json:"album"`
	EditLink     Link  `json:"editlink"`
	DeleteLink   Link  `json:"deletelink"`
	Time         time.Time
	TimeRaw      int64 `json:"time"`
	StartTime    time.Time
	StartTimeRaw string `json:"starttime"`
	AudioLogID   uint   `json:"audiologid"`
}

TracklistItem represents a single item in a show tracklist.

type User

type User struct {
	MemberID     int
	Fname, Sname string
	Email        string `json:"public_email"`
	Receiveemail bool   `json:"receive_email"`
	//@TODO: fix the api and make it return a photo object
	Photo string
	Bio   string
}

User represents a MyRadio user.

type UserAlias

type UserAlias struct {
	Source      string
	Destination string
}

UserAlias represents a user alias.

Directories

Path Synopsis
Package api exposes a low-level interface to the MyRadio API.
Package api exposes a low-level interface to the MyRadio API.

Jump to

Keyboard shortcuts

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