-
Notifications
You must be signed in to change notification settings - Fork 4
/
badges.go
60 lines (54 loc) · 2.2 KB
/
badges.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
package fitbit
import (
"encoding/json"
"fmt"
"strconv"
)
// BadgesList contains a list of badges
type BadgesList struct {
Badges []Badge `json:"badges"`
}
// Badge contains information about a badge
type Badge struct {
BadgeGradientEndColor string `json:"badgeGradientEndColor"`
BadgeGradientStartColor string `json:"badgeGradientStartColor"`
BadgeType string `json:"badgeType"`
Category string `json:"category"`
Cheers []interface{} `json:"cheers"` // FIXME: unknown data
DateTime string `json:"dateTime"`
Description string `json:"description"`
EarnedMessage string `json:"earnedMessage,omitempty"`
EncodedID string `json:"encodedId"`
Image100Px string `json:"image100px"`
Image125Px string `json:"image125px"`
Image300Px string `json:"image300px"`
Image50Px string `json:"image50px"`
Image75Px string `json:"image75px"`
MarketingDescription string `json:"marketingDescription"`
MobileDescription string `json:"mobileDescription"`
Name string `json:"name"`
ShareImage640Px string `json:"shareImage640px"`
ShareText string `json:"shareText"`
ShortDescription string `json:"shortDescription"`
ShortName string `json:"shortName"`
TimesAchieved int `json:"timesAchieved"`
Value int `json:"value,omitempty"`
Unit string `json:"unit,omitempty"`
}
// Badges returns a list of user badges
func (m *Session) Badges(userID uint64) (BadgesList, error) {
// Default "-" is current logged in user
requestID := "-"
if userID > 0 {
requestID = strconv.FormatUint(userID, 10)
}
contents, err := m.makeRequest(fmt.Sprintf("https://api.fitbit.com/1/user/%s/badges.json", requestID))
if err != nil {
return BadgesList{}, err
}
badgeList := BadgesList{}
if err := json.Unmarshal(contents, &badgeList); err != nil {
return BadgesList{}, err
}
return badgeList, nil
}