Discman
Loading...
Searching...
No Matches
Spotify Class Reference

An interface to Spotify for retrieving album art. More...

#include <spotify.h>

Inheritance diagram for Spotify:
Collaboration diagram for Spotify:

Public Types

enum  Method { SearchForItem }
 Spotify API methods. More...
 

Public Member Functions

 Spotify ()
 Spotify constructor.
 
void init () override
 Retrieves the Spotify client ID and secret as environment variables.
 
std::vector< AlbumArtalbum_art (const std::string &artist, const std::string &title, const int width, const int height) override
 Retrieves all album art matching the artist and title.
 
- Public Member Functions inherited from AlbumArtProvider
AlbumArt album_art (const std::string &url, const int width, const int height)
 Retrieves the album art image at a given URL.
 

Static Public Attributes

static constexpr const char * BASE_URL = "https://api.spotify.com/v1/"
 The Spotify API base URL.
 

Static Private Member Functions

static std::string method_name (const Method method)
 Conversion method to convert a Spotify::Method to a string.
 
static std::string base64_encode (const std::string &input)
 Encodes a string into base64. Used to encode an HTTP authorization header.
 
static std::string url (const Method method, const std::map< std::string, std::string > &params)
 Calls url_with_params() with the Spotify API method URL.
 

Static Private Attributes

static std::string _accessToken
 The Spotify API key retrieved.
 

Additional Inherited Members

- Static Public Member Functions inherited from AlbumArtProvider
static AlbumArtProviderinstance ()
 Factory method to return the album art provider. It may be called one or more times. Be sure to destroy() the instance in order to avoid leaks. It is suggested to do so in the teardown of the first caller.
 
static void destroy ()
 Destroys the AlbumArtProvider.
 
static std::string url_with_params (const std::string &url, const std::map< std::string, std::string > &params)
 Returns the URL of the API endpoint with the given parameters encoded as query parameters.
 
static std::string url_encode (const std::string &input)
 Encodes an arbitrary string into a query parameter value.
 
- Protected Member Functions inherited from AlbumArtProvider
 AlbumArtProvider ()
 AlbumArtProvider constructor.
 
virtual ~AlbumArtProvider ()
 AlbumArtProvider destructor.
 

Detailed Description

An interface to Spotify for retrieving album art.

Definition at line 31 of file spotify.h.

Member Enumeration Documentation

◆ Method

Spotify API methods.

Enumerator
SearchForItem 

Definition at line 35 of file spotify.h.

Constructor & Destructor Documentation

◆ Spotify()

Spotify::Spotify ( )

Spotify constructor.

Definition at line 11 of file spotify.cc.

Member Function Documentation

◆ album_art()

std::vector< AlbumArtProvider::AlbumArt > Spotify::album_art ( const std::string & artist,
const std::string & title,
const int width,
const int height )
overridevirtual

Retrieves all album art matching the artist and title.

Parameters
[in]artistAlbum artist.
[in]titleAlbum title.
[in]widthWidth of the returned images.
[in]heightHeight of the returned images.
Returns
List of album art images.

Implements AlbumArtProvider.

Definition at line 46 of file spotify.cc.

◆ base64_encode()

std::string Spotify::base64_encode ( const std::string & input)
staticprivate

Encodes a string into base64. Used to encode an HTTP authorization header.

Parameters
[in]inputAn arbitrary string.
Returns
The base64-encoded input.

Definition at line 127 of file spotify.cc.

◆ init()

void Spotify::init ( )
overridevirtual

Retrieves the Spotify client ID and secret as environment variables.

Reimplemented from AlbumArtProvider.

Definition at line 17 of file spotify.cc.

◆ method_name()

std::string Spotify::method_name ( const Method method)
staticprivate

Conversion method to convert a Spotify::Method to a string.

Parameters
[in]methodSpotify method.
Returns
method as a string.

Definition at line 147 of file spotify.cc.

◆ url()

std::string Spotify::url ( const Method method,
const std::map< std::string, std::string > & params )
staticprivate

Calls url_with_params() with the Spotify API method URL.

Parameters
[in]methodSpotify method.
[in]paramsMethod parameters only.
Returns
Spotify API endpoint URL.

Definition at line 155 of file spotify.cc.

Member Data Documentation

◆ _accessToken

std::string Spotify::_accessToken
staticprivate

The Spotify API key retrieved.

Definition at line 59 of file spotify.h.

◆ BASE_URL

const char* Spotify::BASE_URL = "https://api.spotify.com/v1/"
staticconstexpr

The Spotify API base URL.

Definition at line 40 of file spotify.h.


The documentation for this class was generated from the following files: