-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtrophy_title.go
81 lines (76 loc) · 2.43 KB
/
trophy_title.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
74
75
76
77
78
79
80
81
package psn
import (
"context"
"fmt"
"time"
)
const trophyTitleApi = "-tpy.np.community.playstation.net/trophy/v1/trophyTitles?"
type TrophyTitleResponse struct {
TotalResults int `json:"totalResults"`
Offset int `json:"offset"`
Limit int `json:"limit"`
TrophyTitles []struct {
NpCommunicationID string `json:"npCommunicationId"`
TrophyTitleName string `json:"trophyTitleName"`
TrophyTitleDetail string `json:"trophyTitleDetail"`
TrophyTitleIconURL string `json:"trophyTitleIconUrl"`
TrophyTitleSmallIconURL string `json:"trophyTitleSmallIconUrl"`
TrophyTitlePlatfrom string `json:"trophyTitlePlatfrom"` // typo in Sony's response
HasTrophyGroups bool `json:"hasTrophyGroups"`
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"`
FromUser 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"`
HiddenFlag bool `json:"hiddenFlag"`
LastUpdateDate time.Time `json:"lastUpdateDate"`
} `json:"fromUser,omitempty"`
} `json:"trophyTitles"`
}
// Method retrieves user's trophy titles
func (p *psn) GetTrophyTitles(ctx context.Context, username string, limit, offset int32) (*TrophyTitleResponse, error) {
var h = headers{}
h["authorization"] = fmt.Sprintf("Bearer %s", p.accessToken)
h["Accept"] = "*/*"
h["Accept-Encoding"] = "gzip, deflate, br"
response := TrophyTitleResponse{}
err := p.get(
ctx,
fmt.Sprintf(
"https://%s%sfields=@default,trophyTitleSmallIconUrl&platform=PS3,PS4,PSVITA&limit=%d&offset=%d&comparedUser=%s&npLanguage=%s",
p.region,
trophyTitleApi,
limit,
offset,
username,
p.lang,
),
h,
&response,
)
if err != nil {
return nil, fmt.Errorf("can't do GET request: %w", err)
}
return &response, nil
}