lastfm

package module
v0.0.0-...-5fee3ad Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2020 License: MIT Imports: 12 Imported by: 1

Documentation

Overview

Package lastfm implements the LastFM API 2.0

This package is a wrapper for the LastFM API: https://www.last.fm/api

The wrapper is built to be modular, and each LastFM API endpoint method is a separate package. Following API methods are covered by the package:

album: https://godoc.org/git.maych.in/thunderbottom/lastfm-go/api/album

artist: https://godoc.org/git.maych.in/thunderbottom/lastfm-go/api/artist

chart: https://godoc.org/git.maych.in/thunderbottom/lastfm-go/api/chart

geo: https://godoc.org/git.maych.in/thunderbottom/lastfm-go/api/geo

library: https://godoc.org/git.maych.in/thunderbottom/lastfm-go/api/library

tag: https://godoc.org/git.maych.in/thunderbottom/lastfm-go/api/tag

track: https://godoc.org/git.maych.in/thunderbottom/lastfm-go/api/track

user: https://godoc.org/git.maych.in/thunderbottom/lastfm-go/api/user

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	Name       string `xml:"name"`
	Key        string `xml:"key"`
	Subscriber bool   `xml:"subscriber"`
}

Auth contains the response for the LastFM Login endpoint.

type Client

type Client struct {
	APIKey    string
	APISecret string
	// contains filtered or unexported fields
}

Client is the LastFM client.

func New

func New(apiKey, apiSecret string) (client Client)

New returns an instance of the LastFM Client. The instance also includes an HTTP client for querying the LastFM API, with timeout set to 10 seconds. The page limit for requests is set to 50 by default, which can be changed using SetLimit

func (*Client) Bool2strint

func (client *Client) Bool2strint(b bool) string

Bool2strint returns a string representation of the integer value for the provided boolean input.

func (*Client) GetLimit

func (client *Client) GetLimit() (limit string)

GetLimit returns a string representation of the current page limit set on the Client. This function is usually called from functions abstracting the LastFM API where page limits are required.

func (*Client) GetUserAgent

func (client *Client) GetUserAgent() string

GetUserAgent returns the currently set User-Agent header

func (*Client) Login

func (client *Client) Login(username string, password string) (err error)

Login creates a web service session for the LastFM user by authenticating using LastFM login credentials, and sets the session key within the LastFM Client.

username and password must be a valid LastFM user credentials.

This function must be called once before executing any function performing POST request on the LastFM API.

func (*Client) Logout

func (client *Client) Logout()

Logout clears the current web service session and logs the user out of LastFM

func (*Client) Request

func (client *Client) Request(provider *Provider) (err error)

Request uses an instance of Client to perform GET and POST requests on the LastFM API endpoints. provider must be an instance of Provider containing the API Method, parameters for the API call, and the request Type. Optionally, the provider should also include an interface to Unmarshal the request response.

This function is usually called from functions abstracting the LastFM API.

func (*Client) SetLimit

func (client *Client) SetLimit(limit int)

SetLimit sets the page limit on the Client for LastFM API requests. The limit defaults to 50 for new Client instances or when set to <= 0.

func (*Client) SetUserAgent

func (client *Client) SetUserAgent(useragent string)

SetUserAgent sets the User-Agent header to be used while querying the LastFM API.

type Error

type Error struct {
	ErrorCode int    `json:"error"`
	Message   string `json:"message"`
}

Error contains the error response generated by the LastFM API.

type Provider

type Provider struct {
	Method   string
	Params   map[string]string
	Response interface{}
	Type     string
}

Provider contains details about a LastFM API request.

This structure is usually used by functions abstracting the LastFM API.

type Scrobble

type Scrobble struct {
	Artist       string
	Track        string
	Timestamp    int64
	Album        string
	Context      string
	StreamID     string
	ChosenByUser bool
	TrackNumber  int
	MBID         string
	AlbumArtist  string
	Duration     int64
}

Scrobble contains the track scrobble data to be sent to LastFM.

Directories

Path Synopsis
api
geo
tag

Jump to

Keyboard shortcuts

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