-
Notifications
You must be signed in to change notification settings - Fork 29
/
BadgeStatus.go
94 lines (75 loc) · 2.53 KB
/
BadgeStatus.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
82
83
84
85
86
87
88
89
90
91
92
93
94
package connect
// BadgeStatus is the badge status for a Connect user.
type BadgeStatus struct {
ProfileID int `json:"userProfileId"`
Fullname string `json:"fullName"`
DisplayName string `json:"displayName"`
ProUser bool `json:"userPro"`
ProfileImageURLLarge string `json:"profileImageUrlLarge"`
ProfileImageURLMedium string `json:"profileImageUrlMedium"`
ProfileImageURLSmall string `json:"profileImageUrlSmall"`
Level int `json:"userLevel"`
LevelUpdateTime Time `json:"levelUpdateDate"`
Point int `json:"userPoint"`
Badges []Badge `json:"badges"`
}
// BadgeLeaderBoard returns the leaderboard for points for the currently
// authenticated user.
func (c *Client) BadgeLeaderBoard() ([]BadgeStatus, error) {
URL := "https://connect.garmin.com/modern/proxy/badge-service/badge/leaderboard"
if !c.authenticated() {
return nil, ErrNotAuthenticated
}
var proxy struct {
LeaderBoad []BadgeStatus `json:"connections"`
}
err := c.getJSON(URL, &proxy)
if err != nil {
return nil, err
}
return proxy.LeaderBoad, nil
}
// BadgeCompare will compare the earned badges of the currently authenticated user against displayName.
func (c *Client) BadgeCompare(displayName string) (*BadgeStatus, *BadgeStatus, error) {
URL := "https://connect.garmin.com/modern/proxy/badge-service/badge/compare/" + displayName
if !c.authenticated() {
return nil, nil, ErrNotAuthenticated
}
var proxy struct {
User *BadgeStatus `json:"user"`
Connection *BadgeStatus `json:"connection"`
}
err := c.getJSON(URL, &proxy)
if err != nil {
return nil, nil, err
}
return proxy.User, proxy.Connection, nil
}
// BadgesEarned will return the list of badges earned by the curently
// authenticated user.
func (c *Client) BadgesEarned() ([]Badge, error) {
URL := "https://connect.garmin.com/modern/proxy/badge-service/badge/earned"
if !c.authenticated() {
return nil, ErrNotAuthenticated
}
badges := make([]Badge, 0, 200)
err := c.getJSON(URL, &badges)
if err != nil {
return nil, err
}
return badges, nil
}
// BadgesAvailable will return the list of badges not yet earned by the curently
// authenticated user.
func (c *Client) BadgesAvailable() ([]Badge, error) {
URL := "https://connect.garmin.com/modern/proxy/badge-service/badge/available"
if !c.authenticated() {
return nil, ErrNotAuthenticated
}
badges := make([]Badge, 0, 200)
err := c.getJSON(URL, &badges)
if err != nil {
return nil, err
}
return badges, nil
}