Unified code for backend clients and tests

This commit is contained in:
Philipp Wolfer 2023-11-12 16:28:23 +01:00
parent 9316838d59
commit aa01ae1342
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
11 changed files with 220 additions and 42 deletions

View file

@ -22,6 +22,7 @@ THE SOFTWARE.
package listenbrainz
import (
"errors"
"strconv"
"time"
@ -52,17 +53,21 @@ func NewClient(token string) Client {
return client
}
func (c Client) GetListens(user string, maxTime time.Time, minTime time.Time) (GetListensResult, error) {
func (c Client) GetListens(user string, maxTime time.Time, minTime time.Time) (result GetListensResult, err error) {
const path = "/user/{username}/listens"
result := &GetListensResult{}
_, err := c.HttpClient.R().
response, err := c.HttpClient.R().
SetPathParam("username", user).
SetQueryParams(map[string]string{
"max_ts": strconv.FormatInt(maxTime.Unix(), 10),
"min_ts": strconv.FormatInt(minTime.Unix(), 10),
"count": strconv.FormatInt(int64(c.MaxResults), 10),
}).
SetResult(result).
SetResult(&result).
Get(path)
return *result, err
if response.StatusCode() != 200 {
err = errors.New(response.String())
return
}
return
}