lastfm

package
v0.0.0-...-d09ec23 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2017 License: MIT, MIT Imports: 10 Imported by: 0

README

#Lastfm-go Golang wrapper for the Last.fm API 2.0

http://www.lastfm.jp/api

#Setup

Get the source codes from github :

% go get github.com/shkh/lastfm-go/lastfm

Import the package :

import "github.com/shkh/lastfm-go/lastfm"

#Usage

First, create an API instance with your API KEY and API SECRET.

api := lastfm.New (ApiKey, ApiSecret)

Note that some API methods require your user's permission, so make sure that your requests are authenticated before calling these methods. See "Authentication" section.

API instances contain the structs which represent API classes, and each struct has methods corresponding to their API methods. So you can call user.getNeighbours for example as following:

result, _ := api.User.GetNeighbours (lastfm.P{"user": "shkh_"}) //discarding error
for _, u := range result.Users {
	fmt.Println (u.Name, u.Match)
}

Methods that fetch some data return their result as a struct named ClassMethod (e.g. api.User.GetInfo returns its result of type UserGetInfo). They can be found in class_result.go. Please look at the file to see which fileds are exported.

You can use lastfm.P for arguments. It's just an alias to map[string]interface{}, but values must be string, int, int64 (for unix timestamp) or []string. Slice of string, []string, can be used for passing multiple values for a key.

//album.addTags (auth required)
api.Album.AddTags(lastfm.P{ //discarding error
	"artist": "Kaene",
	"album":  "Strangeland",
	"tags":   []string{"britpop", "alternative rock", "2012"},
})

//library.addAlbum (auth required)
api.Library.AddAlbum(lastfm.P{ //discarding error
	"artist": []string{"Ellie Goulding", "Keane"},
	"album":  []string{"Goodness Gracious", "Higher Than The Sun"},
})

#Authentication There are three ways to authenticate your requests, which to choose depends on what kind of application you are making.

  • for Mobile Apps

      err = api.Login (username, password)
    
  • for Desktop Apps

      token, _ = api.GetToken () //discarding error
      authUrl = api.GetAuthTokenUrl (token)
      //Send your user to "authUrl"
      //Once the user grant permission, then authorize the token. 
      api.LoginWithToken (token) //discarding error
    
  • for Web Apps

      callback = "http://spam.hum"
      authUrl, _ = api.GetAuthRequestUrl (callback)
      //Send your user to "authUrl"
      //Get the token embeded in the redirected URL, then authorize the token.
      api.LoginWithToken (token) //discarding error
    

#Supported APIs

##Album

##Artist

##Auth

  • auth.getMobileSession
  • auth.getSession
  • auth.getToken

##Chart

##Event

##Geo

##Group

##Library

##Playlist

##Radio

Tag

Tasteometer

Track

User

##Venue

#Licence MIT Licenced. See LICENCE.

Documentation

Index

Constants

View Source
const (
	ApiResponseStatusFailed = "failed"
)
View Source
const UriApiSecBase = "https://ws.audioscrobbler.com/2.0/"

Variables

This section is empty.

Functions

This section is empty.

Types

type Api

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

func New

func New(key, secret, uriBase string) *Api

func (*Api) Login

func (api *Api) Login(username, password string) error

func (*Api) Scrobble

func (api *Api) Scrobble(args ScrobbleArgs) error

func (*Api) UpdateNowPlaying

func (api *Api) UpdateNowPlaying(args UpdateNowPlayingArgs) error

type ApiError

type ApiError struct {
	Code    int    `xml:"code,attr"`
	Message string `xml:",chardata"`
}

type Args

type Args interface {
	Format() map[string]string
}

type AuthGetMobileSession

type AuthGetMobileSession struct {
	Name       string `xml:"name"` //username
	Key        string `xml:"key"`  //session key
	Subscriber bool   `xml:"subscriber"`
}

type Base

type Base struct {
	XMLName xml.Name `xml:"lfm"`
	Status  string   `xml:"status,attr"`
	Inner   []byte   `xml:",innerxml"`
}

type Err

type Err struct {
	Code    int
	Message string
}

func (*Err) Error

func (e *Err) Error() string

type LoginArgs

type LoginArgs struct {
	Username string
	Password string
}

func (LoginArgs) Format

func (a LoginArgs) Format() map[string]string

type ScrobbleArgs

type ScrobbleArgs struct {
	Artist      string
	Track       string
	Album       string
	AlbumArtist string
	Timestamp   int64
}

func (ScrobbleArgs) Format

func (a ScrobbleArgs) Format() map[string]string

type UpdateNowPlayingArgs

type UpdateNowPlayingArgs struct {
	Artist      string
	Track       string
	Album       string
	AlbumArtist string
}

func (UpdateNowPlayingArgs) Format

func (a UpdateNowPlayingArgs) Format() map[string]string

Jump to

Keyboard shortcuts

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