-
Notifications
You must be signed in to change notification settings - Fork 0
/
achievement.go
35 lines (32 loc) · 1.01 KB
/
achievement.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package retroachievements
import (
"fmt"
"net/http"
raHttp "github.com/joshraphael/go-retroachievements/http"
"github.com/joshraphael/go-retroachievements/models"
)
// GetAchievementUnlocks gets a list of users who have earned an achievement.
func (c *Client) GetAchievementUnlocks(params models.GetAchievementUnlocksParameters) (*models.GetAchievementUnlocks, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetAchievementUnlocks.php"),
raHttp.APIToken(c.Secret),
raHttp.A(params.AchievementID),
}
if params.Count != nil {
details = append(details, raHttp.C(*params.Count))
}
if params.Offset != nil {
details = append(details, raHttp.O(*params.Offset))
}
r, err := c.do(details...)
if err != nil {
return nil, fmt.Errorf("calling endpoint: %w", err)
}
resp, err := raHttp.ResponseObject[models.GetAchievementUnlocks](r)
if err != nil {
return nil, fmt.Errorf("parsing response object: %w", err)
}
return resp, nil
}