-
Notifications
You must be signed in to change notification settings - Fork 0
/
comment.go
47 lines (44 loc) · 1.48 KB
/
comment.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
36
37
38
39
40
41
42
43
44
45
46
47
package retroachievements
import (
"fmt"
"net/http"
"strconv"
raHttp "github.com/joshraphael/go-retroachievements/http"
"github.com/joshraphael/go-retroachievements/models"
)
// GetComments gets comments of a specified kind: game, achievement, or user.
func (c *Client) GetComments(params models.GetCommentsParameters) (*models.GetComments, error) {
details := []raHttp.RequestDetail{
raHttp.Method(http.MethodGet),
raHttp.UserAgent(c.UserAgent),
raHttp.Path("/API/API_GetComments.php"),
raHttp.APIToken(c.Secret),
raHttp.T(params.Type.GetCommentsType()),
}
switch params.Type.(type) {
case models.GetCommentsGame:
game := params.Type.(models.GetCommentsGame)
details = append(details, raHttp.I([]string{strconv.Itoa(game.GameID)}))
case models.GetCommentsAchievement:
achievement := params.Type.(models.GetCommentsAchievement)
details = append(details, raHttp.I([]string{strconv.Itoa(achievement.AchievementID)}))
case models.GetCommentsUser:
user := params.Type.(models.GetCommentsUser)
details = append(details, raHttp.I([]string{user.Username}))
}
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.GetComments](r)
if err != nil {
return nil, fmt.Errorf("parsing response object: %w", err)
}
return resp, nil
}