Make private methods unpublished

This commit is contained in:
Deluan
2023-01-19 09:34:39 -05:00
parent 7fc964aec5
commit 7073d18b54
15 changed files with 97 additions and 96 deletions
+15 -15
View File
@@ -34,18 +34,18 @@ type httpDoer interface {
Do(req *http.Request) (*http.Response, error)
}
func NewClient(apiKey string, secret string, lang string, hc httpDoer) *Client {
return &Client{apiKey, secret, lang, hc}
func newClient(apiKey string, secret string, lang string, hc httpDoer) *client {
return &client{apiKey, secret, lang, hc}
}
type Client struct {
type client struct {
apiKey string
secret string
lang string
hc httpDoer
}
func (c *Client) AlbumGetInfo(ctx context.Context, name string, artist string, mbid string) (*Album, error) {
func (c *client) albumGetInfo(ctx context.Context, name string, artist string, mbid string) (*Album, error) {
params := url.Values{}
params.Add("method", "album.getInfo")
params.Add("album", name)
@@ -59,7 +59,7 @@ func (c *Client) AlbumGetInfo(ctx context.Context, name string, artist string, m
return &response.Album, nil
}
func (c *Client) ArtistGetInfo(ctx context.Context, name string, mbid string) (*Artist, error) {
func (c *client) artistGetInfo(ctx context.Context, name string, mbid string) (*Artist, error) {
params := url.Values{}
params.Add("method", "artist.getInfo")
params.Add("artist", name)
@@ -72,7 +72,7 @@ func (c *Client) ArtistGetInfo(ctx context.Context, name string, mbid string) (*
return &response.Artist, nil
}
func (c *Client) ArtistGetSimilar(ctx context.Context, name string, mbid string, limit int) (*SimilarArtists, error) {
func (c *client) artistGetSimilar(ctx context.Context, name string, mbid string, limit int) (*SimilarArtists, error) {
params := url.Values{}
params.Add("method", "artist.getSimilar")
params.Add("artist", name)
@@ -85,7 +85,7 @@ func (c *Client) ArtistGetSimilar(ctx context.Context, name string, mbid string,
return &response.SimilarArtists, nil
}
func (c *Client) ArtistGetTopTracks(ctx context.Context, name string, mbid string, limit int) (*TopTracks, error) {
func (c *client) artistGetTopTracks(ctx context.Context, name string, mbid string, limit int) (*TopTracks, error) {
params := url.Values{}
params.Add("method", "artist.getTopTracks")
params.Add("artist", name)
@@ -98,7 +98,7 @@ func (c *Client) ArtistGetTopTracks(ctx context.Context, name string, mbid strin
return &response.TopTracks, nil
}
func (c *Client) GetToken(ctx context.Context) (string, error) {
func (c *client) GetToken(ctx context.Context) (string, error) {
params := url.Values{}
params.Add("method", "auth.getToken")
c.sign(params)
@@ -109,7 +109,7 @@ func (c *Client) GetToken(ctx context.Context) (string, error) {
return response.Token, nil
}
func (c *Client) GetSession(ctx context.Context, token string) (string, error) {
func (c *client) getSession(ctx context.Context, token string) (string, error) {
params := url.Values{}
params.Add("method", "auth.getSession")
params.Add("token", token)
@@ -131,7 +131,7 @@ type ScrobbleInfo struct {
timestamp time.Time
}
func (c *Client) UpdateNowPlaying(ctx context.Context, sessionKey string, info ScrobbleInfo) error {
func (c *client) updateNowPlaying(ctx context.Context, sessionKey string, info ScrobbleInfo) error {
params := url.Values{}
params.Add("method", "track.updateNowPlaying")
params.Add("artist", info.artist)
@@ -153,7 +153,7 @@ func (c *Client) UpdateNowPlaying(ctx context.Context, sessionKey string, info S
return nil
}
func (c *Client) Scrobble(ctx context.Context, sessionKey string, info ScrobbleInfo) error {
func (c *client) scrobble(ctx context.Context, sessionKey string, info ScrobbleInfo) error {
params := url.Values{}
params.Add("method", "track.scrobble")
params.Add("timestamp", strconv.FormatInt(info.timestamp.Unix(), 10))
@@ -170,17 +170,17 @@ func (c *Client) Scrobble(ctx context.Context, sessionKey string, info ScrobbleI
return err
}
if resp.Scrobbles.Scrobble.IgnoredMessage.Code != "0" {
log.Warn(ctx, "LastFM: Scrobble was ignored", "code", resp.Scrobbles.Scrobble.IgnoredMessage.Code,
log.Warn(ctx, "LastFM: scrobble was ignored", "code", resp.Scrobbles.Scrobble.IgnoredMessage.Code,
"text", resp.Scrobbles.Scrobble.IgnoredMessage.Text, "info", info)
}
if resp.Scrobbles.Attr.Accepted != 1 {
log.Warn(ctx, "LastFM: Scrobble was not accepted", "code", resp.Scrobbles.Scrobble.IgnoredMessage.Code,
log.Warn(ctx, "LastFM: scrobble was not accepted", "code", resp.Scrobbles.Scrobble.IgnoredMessage.Code,
"text", resp.Scrobbles.Scrobble.IgnoredMessage.Text, "info", info)
}
return nil
}
func (c *Client) makeRequest(ctx context.Context, method string, params url.Values, signed bool) (*Response, error) {
func (c *client) makeRequest(ctx context.Context, method string, params url.Values, signed bool) (*Response, error) {
params.Add("format", "json")
params.Add("api_key", c.apiKey)
@@ -214,7 +214,7 @@ func (c *Client) makeRequest(ctx context.Context, method string, params url.Valu
return &response, nil
}
func (c *Client) sign(params url.Values) {
func (c *client) sign(params url.Values) {
// the parameters must be in order before hashing
keys := make([]string, 0, len(params))
for k := range params {