Documentation
¶
Overview ¶
Package session provides functionality for managing authenticated sessions with the Last.fm API. It includes methods for setting session keys, verifying credentials, and making authenticated API requests.
The Session struct is the core of this package, encapsulating the API client and session key required for authenticated requests. It provides methods for sending GET and POST requests, as well as a general-purpose Request method for handling different HTTP methods.
The Client struct extends the Session functionality by embedding it and providing access to various API routes such as Album, Artist, User, and more. It serves as a central point for interacting with the Last.fm API.
Key Features:
- Create and manage authenticated sessions with the Last.fm API.
- Manage Last.fm user authentication and session keys.
- Send authenticated HTTP GET and POST requests.
- Access different API routes through the Client struct.
Usage:
- Create a new Session or Client instance using the provided constructors.
- Set the session key using SetSessionKey or through the Login method.
- Use the Get, Post, or Request methods to interact with the Last.fm API.
Index ¶
- type Album
- func (a Album) AddTags(artist, album string, tags []string) error
- func (a Album) RemoveTag(artist, album, tag string) error
- func (a Album) SelfTags(params lastfm.AlbumSelfTagsParams) (*lastfm.AlbumTags, error)
- func (a Album) SelfTagsByMBID(params lastfm.AlbumSelfTagsMBIDParams) (*lastfm.AlbumTags, error)
- type Artist
- func (a Artist) AddTags(artist string, tags []string) error
- func (a Artist) RemoveTag(artist string, tag string) error
- func (a Artist) SelfTags(params lastfm.ArtistSelfTagsParams) (*lastfm.ArtistTags, error)
- func (a Artist) SelfTagsByMBID(params lastfm.ArtistSelfTagsMBIDParams) (*lastfm.ArtistTags, error)
- type Auth
- type Chart
- type Client
- type Geo
- type Library
- type Session
- func (s *Session) CheckCredentials(level api.RequestLevel) error
- func (s *Session) Get(dest any, method api.APIMethod, params any) error
- func (s *Session) Post(dest any, method api.APIMethod, params any) error
- func (s *Session) Request(dest any, httpMethod string, method api.APIMethod, params any) error
- func (s *Session) SetSessionKey(key string)
- type Tag
- type Track
- func (t Track) AddTags(artist, track string, tags []string) error
- func (t Track) Love(artist, track string) error
- func (t Track) RemoveTag(artist, track, tag string) error
- func (t Track) Scrobble(params lastfm.ScrobbleParams) (*lastfm.ScrobbleResult, error)
- func (t Track) ScrobbleMulti(params lastfm.ScrobbleMultiParams) (*lastfm.ScrobbleMultiResult, error)
- func (t Track) SelfTags(params lastfm.TrackSelfTagsParams) (*lastfm.TrackTags, error)
- func (t Track) SelfTagsByMBID(params lastfm.TrackSelfTagsMBIDParams) (*lastfm.TrackTags, error)
- func (t Track) Unlove(artist, track string) error
- func (t Track) UpdateNowPlaying(params lastfm.UpdateNowPlayingParams) (*lastfm.NowPlayingUpdate, error)
- type User
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Album ¶
func (Album) SelfTags ¶
SelfTags returns the tags of an album for the authenticated user by artist and album name.
func (Album) SelfTagsByMBID ¶
SelfTagsByMBID returns the tags of an album for the authenticated user by MBID.
type Artist ¶
func (Artist) SelfTags ¶
func (a Artist) SelfTags(params lastfm.ArtistSelfTagsParams) (*lastfm.ArtistTags, error)
SelfTags returns the tags of an artist for the authenticated user by artist name.
func (Artist) SelfTagsByMBID ¶
func (a Artist) SelfTagsByMBID(params lastfm.ArtistSelfTagsMBIDParams) (*lastfm.ArtistTags, error)
SelfTagsByMBID returns the tags of an artist for the authenticated user by MBID.
type Client ¶
type Client struct {
*Session
Album *Album
Artist *Artist
Auth *Auth
Chart *Chart
Geo *Geo
Library *Library
Tag *Tag
Track *Track
User *User
}
Client is a struct that serves as a central point for making authenticated API calls. It embeds a Session and provides fields for interacting with different API routes such as Album, Artist, User, etc.
func NewClientWithTimeout ¶
NewClientWithTimeout returns a new instance of Client with the given API key, secret, and timeout settings. The timeout is specified in seconds and is used to configure the HTTP client for making API requests. This allows for better control over network timeouts when interacting with the API.
func (*Client) Login ¶
Login authenticates a user using their username and password credentials. Calls the AuthGetMobileSession method of the Last.fm API and sets the session key in the Client.
func (*Client) TokenLogin ¶
TokenLogin authenticates a user using an authorized token obtained from the AuthGetToken method of the Last.fm API. The user must have authorised the token via the URL returned by AuthTokenURL. The token is used to create a session key, which is then set in the Client. If the token cannot be used, an error is returned.
type Library ¶
func NewLibrary ¶
NewLibrary creates and returns a new Library API route.
type Session ¶
type Session struct {
*api.API
// SessionKey is the session key for the Last.fm API session. This key is
// used to authenticate requests made to the API. Last.fm session keys have
// infinite lifetime, so you can store it and reuse it for future requests
// without needing to re-authenticate the user.
SessionKey string
}
func NewWithTimeout ¶
NewWithTimeout returns a new instance of Session with the given API key, secret, and timeout settings. The timeout is specified in seconds.
func (*Session) CheckCredentials ¶
func (s *Session) CheckCredentials(level api.RequestLevel) error
CheckCredentials verifies the authentication level required for an API request and ensures the necessary credentials are present. It checks the presence of the Last.fm API session key for requests requiring a session, the secret for requests requiring a secret, and the API key for requests requiring an API key. Returns an error if required credentials are missing.
Parameters:
- level: The RequestLevel indicating the level of authorization required.
Returns:
- An error if the required authentication credentials are not present.
func (*Session) Get ¶
Get sends an authenticated HTTP GET request to the API using the specified method and parameters, and decodes the response into the provided destination.
Parameters:
- dest: A pointer to the variable where the response will be unmarshaled.
- method: The APIMethod representing the endpoint to call.
- params: The parameters to include in the request.
Returns:
- An error if the request fails or the response cannot be decoded.
func (*Session) Post ¶
Post sends an authenticated HTTP POST request to the API with the specified method and parameters. The response is unmarshaled into the provided destination.
Parameters:
- dest: A pointer to the variable where the response will be unmarshaled.
- method: The APIMethod representing the API endpoint to call.
- params: The parameters to include in the POST request.
Returns:
- An error if the request fails or the response cannot be unmarshaled.
func (*Session) Request ¶
Request sends an authenticated HTTP request to the API using the specified parameters and unmarshals the response into the provided destination.
Parameters:
- dest: A pointer to the variable where the response will be unmarshaled.
- httpMethod: The HTTP method to use for the request (e.g., "GET", "POST").
- method: The APIMethod representing the endpoint to call.
- params: The parameters to include in the request.
Returns:
- An error if the request fails or the response cannot be unmarshaled.
func (*Session) SetSessionKey ¶
SetSessionKey sets the session key for the Last.fm API session. This key is used to authenticate requests made to the API. The session key is typically obtained after a user has logged in and authorized the application.
Use this method to set the session key manually if you have obtained it through other means, such as a login process or an authentication flow, or a stored session key from a previous session.
type Track ¶
func (Track) Scrobble ¶
func (t Track) Scrobble(params lastfm.ScrobbleParams) (*lastfm.ScrobbleResult, error)
Scrobble scrobbles a track for the authenticated user.
func (Track) ScrobbleMulti ¶
func (t Track) ScrobbleMulti( params lastfm.ScrobbleMultiParams) (*lastfm.ScrobbleMultiResult, error)
ScrobbleMulti scrobbles multiple tracks for the authenticated user.
func (Track) SelfTags ¶
SelfTags returns the tags of a track for the authenticated user by artist and track name.
func (Track) SelfTagsByMBID ¶
SelfTagsByMBID returns the tags of a track for the authenticated user by MBID.
func (Track) UpdateNowPlaying ¶
func (t Track) UpdateNowPlaying( params lastfm.UpdateNowPlayingParams) (*lastfm.NowPlayingUpdate, error)
UpdateNowPlaying updates the now playing track for the authenticated user.