-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerSearch.go
76 lines (62 loc) · 1.75 KB
/
PlayerSearch.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
package goBungieNet
import (
"fmt"
"errors"
"strings"
)
type BungieMembershipType int
const (
NetworkNone BungieMembershipType = 0
NetworkXbox = 1
NetworkPsn = 2
NetworkBlizzard = 4
NetworkDemon = 10
NetworkBungieNext = 254
NetworkAll = -1
)
func (atype BungieMembershipType)String() string {
switch(atype) {
case NetworkNone: return "None"
case NetworkXbox: return "Xbox Live"
case NetworkPsn: return "Playstation Network"
case NetworkBlizzard: return "Battle.Net"
case NetworkAll: return "All Networks"
}
return "Unknown"
}
func StringToBungieMembershipType(text string) BungieMembershipType {
accountTypeString := strings.ToLower(text)
if strings.HasPrefix(accountTypeString, "ps") {
return NetworkPsn
} else if strings.HasPrefix(accountTypeString, "xbox") {
return NetworkXbox
} else if strings.HasPrefix(accountTypeString, "battle") {
return NetworkBlizzard
} else if strings.HasPrefix(accountTypeString, "all") {
return NetworkAll
}
return NetworkNone
}
type UserInfo struct {
IconPath string
SupplementalDisplayName string
MembershipType BungieMembershipType
MembershipID int64
DisplayName string
}
func FindDestinyUser(displayName string, networkType BungieMembershipType) (*[]UserInfo, error) {
url := fmt.Sprintf("/Destiny2/SearchDestinyPlayer/%d/%s/", networkType, displayName)
response, err := get(url)
if (err != nil) {
return nil, errors.New("Get Error: " + err.Error())
}
if response.ErrorCode.isError() {
return nil, errors.New("Response Error: " + string(response.ErrorCode))
}
var info []UserInfo
err = decode(response.Response, &info)
if err != nil {
return nil, errors.New("Could not decode response: " + err.Error())
}
return &info, err
}