spotifySaver

package
v0.0.0-...-5782047 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2021 License: GPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TokenFileName is the standard file name to save the OAuth token to
	TokenFileName = "token.json"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FetchedSongs

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

FetchedSongs type will be used for inserting newly pulled Spotify history entries to the database.

func NewFetchedSongs

func NewFetchedSongs(d *pop.Connection, songs []spotify.RecentlyPlayedItem) FetchedSongs

NewFetchedSongs will create FetchedSongs struct.

func (*FetchedSongs) TransformAndInsertIntoDatabase

func (s *FetchedSongs) TransformAndInsertIntoDatabase(log *logrus.Entry) error

TransformAndInsertIntoDatabase will convert and insert recently played songs into database.

type InterfaceSpotifySaver

type InterfaceSpotifySaver interface {
	LoadToken(file string) error
	Authenticate(callbackURI, clientID, clientSecret string)
	StartLastSongsWorker(wg *sync.WaitGroup, stop chan bool)
}

InterfaceSpotifySaver is the interface SpotifySaver implements. It supports loading a token and authenticating with it. The main purpose is to start the StartLastSongsWorker to periodically save the history.

type MockedSpotifySaver

type MockedSpotifySaver struct {
	LError bool
}

MockedSpotifySaver implements the InterfaceSpotifySaver interface for tests.

func (*MockedSpotifySaver) Authenticate

func (s *MockedSpotifySaver) Authenticate(_, _, _ string)

Authenticate will create a new client from token.

func (*MockedSpotifySaver) LoadToken

func (s *MockedSpotifySaver) LoadToken(_ string) error

LoadToken will load the token from file "token.json" in exec directory. It will throw an error when the token is expired.

func (*MockedSpotifySaver) StartLastSongsWorker

func (s *MockedSpotifySaver) StartLastSongsWorker(wg *sync.WaitGroup, stop chan bool)

StartLastSongsWorker is a worker that will send history requests every 45 minutes. It is not async. It accepts a wait group and will send Done when stopped. It may be stopped with stop chan value.

type SpotifySaver

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

SpotifySaver will handle all the saving logic. It supports loading a token and authenticating with it. The main purpose is to start the StartLastSongsWorker to periodically save the history.

func NewSpotifySaver

func NewSpotifySaver(log *logrus.Entry, env string) (*SpotifySaver, error)

NewSpotifySaver will create a new SpotifySaver instance with database connection. It will throw an error when database connection fails.

func (*SpotifySaver) Authenticate

func (s *SpotifySaver) Authenticate(callbackURI, clientID, clientSecret string)

Authenticate will create a new client from token.

func (*SpotifySaver) LoadToken

func (s *SpotifySaver) LoadToken(file string) error

LoadToken will load the token from file "token.json" in exec directory. It will throw an error when the token is expired.

func (*SpotifySaver) StartLastSongsWorker

func (s *SpotifySaver) StartLastSongsWorker(wg *sync.WaitGroup, stop chan bool)

StartLastSongsWorker is a worker that will send history requests every 45 minutes. It is not async. It accepts a wait group and will send Done when stopped. It may be stopped with stop chan value.

Jump to

Keyboard shortcuts

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