-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtrophy_group.go
73 lines (68 loc) · 2.13 KB
/
trophy_group.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package psn
import (
"context"
"fmt"
"time"
)
const trophyGroupApi = "-tpy.np.community.playstation.net/trophy/v1/trophyTitles/"
type TrophyGroupResponse struct {
TrophyTitleName string `json:"trophyTitleName"`
TrophyTitleDetail string `json:"trophyTitleDetail"`
TrophyTitleIconURL string `json:"trophyTitleIconUrl"`
TrophyTitlePlatfrom string `json:"trophyTitlePlatfrom"`
DefinedTrophies struct {
Bronze int `json:"bronze"`
Silver int `json:"silver"`
Gold int `json:"gold"`
Platinum int `json:"platinum"`
} `json:"definedTrophies"`
TrophyGroups []struct {
TrophyGroupID string `json:"trophyGroupId"`
TrophyGroupName string `json:"trophyGroupName"`
TrophyGroupDetail string `json:"trophyGroupDetail"`
TrophyGroupIconURL string `json:"trophyGroupIconUrl"`
TrophyGroupSmallIconURL string `json:"trophyGroupSmallIconUrl"`
DefinedTrophies struct {
Bronze int `json:"bronze"`
Silver int `json:"silver"`
Gold int `json:"gold"`
Platinum int `json:"platinum"`
} `json:"definedTrophies"`
ComparedUser struct {
OnlineID string `json:"onlineId"`
Progress int `json:"progress"`
EarnedTrophies struct {
Bronze int `json:"bronze"`
Silver int `json:"silver"`
Gold int `json:"gold"`
Platinum int `json:"platinum"`
} `json:"earnedTrophies"`
LastUpdateDate time.Time `json:"lastUpdateDate"`
} `json:"comparedUser"`
} `json:"trophyGroups"`
}
// Method retrieves user's trophy groups
func (p *psn) GetTrophyGroups(ctx context.Context, trophyTitleId, username string) (*TrophyGroupResponse, error) {
var h = headers{}
h["authorization"] = fmt.Sprintf("Bearer %s", p.accessToken)
h["Accept"] = "*/*"
h["Accept-Encoding"] = "gzip, deflate, br"
response := TrophyGroupResponse{}
err := p.get(
ctx,
fmt.Sprintf(
"https://%s%s%s/trophyGroups?fields=@default,trophyGroupSmallIconUrl&comparedUser=%s&npLanguage=%s",
p.region,
trophyGroupApi,
trophyTitleId,
username,
p.lang,
),
h,
&response,
)
if err != nil {
return nil, fmt.Errorf("can't do GET request: %w", err)
}
return &response, nil
}