Skip to content

Commit

Permalink
feat(lastfm): autocorrect artist and album name misspellings when fet…
Browse files Browse the repository at this point in the history
…ching info

closes #472
  • Loading branch information
sentriz committed Feb 20, 2024
1 parent 51fa0ba commit 2878b88
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lastfm/client.go
Expand Up @@ -52,6 +52,7 @@ func (c *Client) ArtistGetInfo(artistName string) (Artist, error) {
params.Add("method", "artist.getInfo")
params.Add("api_key", apiKey)
params.Add("artist", artistName)
params.Add("autocorrect", "1")

resp, err := c.makeRequest(http.MethodGet, params)
if err != nil {
Expand All @@ -72,6 +73,7 @@ func (c *Client) AlbumGetInfo(artistName, albumName string) (Album, error) {
params.Add("api_key", apiKey)
params.Add("artist", artistName)
params.Add("album", albumName)
params.Add("autocorrect", "1")

resp, err := c.makeRequest(http.MethodGet, params)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions lastfm/client_test.go
Expand Up @@ -23,7 +23,7 @@ func TestArtistGetInfo(t *testing.T) {
client := lastfm.NewClientCustom(
mockclient.New(t, func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, http.MethodGet, r.Method)
require.Equal(t, url.Values{"method": []string{"artist.getInfo"}, "api_key": []string{"apiKey1"}, "artist": []string{"Artist 1"}}, r.URL.Query())
require.Equal(t, url.Values{"method": []string{"artist.getInfo"}, "api_key": []string{"apiKey1"}, "artist": []string{"Artist 1"}, "autocorrect": []string{"1"}}, r.URL.Query())

require.Equal(t, "/2.0/", r.URL.Path)
require.Equal(t, lastfm.BaseURL, "https://"+r.Host+r.URL.Path)
Expand Down Expand Up @@ -103,9 +103,10 @@ func TestArtistGetInfoClientRequestFails(t *testing.T) {
mockclient.New(t, func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, http.MethodGet, r.Method)
require.Equal(t, url.Values{
"method": []string{"artist.getInfo"},
"api_key": []string{"apiKey1"},
"artist": []string{"Artist 1"},
"method": []string{"artist.getInfo"},
"api_key": []string{"apiKey1"},
"artist": []string{"Artist 1"},
"autocorrect": []string{"1"},
}, r.URL.Query())

require.Equal(t, "/2.0/", r.URL.Path)
Expand Down

0 comments on commit 2878b88

Please sign in to comment.