forked from credondocr/dota2api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvanityUrl.go
65 lines (54 loc) · 1.29 KB
/
vanityUrl.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
package dota2api
import (
"encoding/json"
"fmt"
"strconv"
)
func (api Dota2) getResolveVanityUrl() string {
return fmt.Sprintf("%s/%s/%s/", api.steamUserUrl, "ResolveVanityURL", api.steamApiVersion)
}
type Vanity struct {
Response VanityResp `json:"response"`
}
type VanityResp struct {
SteamId string `json:"steamid"`
Success int `json:"success"`
}
//Get steamId by username
func (api Dota2) ResolveVanityUrl(params ...Parameter) (SteamId, error) {
var steamId SteamId
param, err := getParameterMap([]parameterKind{parameterVanityUrl}, nil, params)
if err != nil {
return steamId, err
}
param["key"] = api.steamApiKey
url, err := parseUrl(api.getResolveVanityUrl(), param)
if err != nil {
return steamId, err
}
resp, err := api.Get(url)
if err != nil {
return steamId, err
}
vanity := Vanity{}
err = json.Unmarshal(resp, &vanity)
if err != nil {
return steamId, err
}
if vanity.Response.Success != 1 {
return steamId, statusCodeError(vanity.Response.Success, 1)
}
steamId.id, err = strconv.ParseUint(vanity.Response.SteamId, 10, 64)
if err != nil {
return steamId, err
}
steamId.isId64 = true
return steamId, nil
}
func VanityUrl(url string) ParameterString {
return ParameterString{
k: "vanityurl",
v: url,
kindInt: parameterVanityUrl,
}
}