-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplayers.go
173 lines (158 loc) · 5.46 KB
/
players.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package smitego
import (
"encoding/json"
"io/ioutil"
"net/http"
)
// LeagueConquest is a struct that represents a player's status within
// the Conquest league in Smite.
type LeagueConquest struct {
Leaves int `json:"Leaves"`
Losses int `json:"Losses"`
Name string `json:"Name"`
Points int `json:"Points"`
PreviousRank int `json:"PrevRank"`
Rank int `json:"Rank"`
Season int `json:"Season"`
Tier int `json:"Tier"`
Trend int `json:"Trend"`
VictoryPoints int `json:"VictoryPoints"`
Wins int `json:"Wins"`
ReturnMessage string `json:"ret_msg"`
}
// LeagueJoust is a struct that represents a player's status within
// the Joust league in Smite.
type LeagueJoust struct {
Leaves int `json:"Leaves"`
Losses int `json:"Losses"`
Name string `json:"Name"`
Points int `json:"Points"`
PreviousRank int `json:"PrevRank"`
Rank int `json:"Rank"`
Season int `json:"Season"`
Tier int `json:"Tier"`
Trend int `json:"Trend"`
VictoryPoints int `json:"VictoryPoints"`
Wins int `json:"Wins"`
ReturnMessage string `json:"ret_msg"`
}
// Player is a struct that represents a Smite game player.
type Player struct {
ID int `json:"Id"`
CreatedDateTime string `json:"Created_Datetime"`
LastLoginDateTime string `json:"Last_Login_Datetime"`
Leaves int `json:"Leaves"`
Level int `json:"Level"`
LeagueConquest LeagueConquest `json:"LeagueConquest"`
LeagueJoust LeagueJoust `json:"LeagueJoust"`
Losses int `json:"Losses"`
MasteryLevel int `json:"MasteryLevel"`
Name string `json:"Name"`
RankStat float32 `json:"Rank_Stat"`
RankStatJoust float32 `json:"Rank_Stat_Joust"`
TeamID int `json:"TeamId"`
TeamName string `json:"Team_Name"`
TierConquest int `json:"Tier_Conquest"`
TierJoust int `json:"Tier_Joust"`
Wins int `json:"Wins"`
ReturnMessage string `json:"ret_msg"`
}
// GodRank is a struct that represents a player's god rank for the Gods
// in Smite.
type GodRank struct {
Rank int `json:"rank"`
Worshippers int `json:"worshippers"`
God string `json:"god"`
ReturnMessage string `json:"ret_msg"`
}
// Friend is a struct that represents a Smite player's friend.
type Friend struct {
Name string `json:"name"`
ReturnMessage string `json:"ret_msg"`
}
// GetPlayer returns a new Player instance with the fields filled with
// data from the json response.
func GetPlayer(playerName string) Player {
hash := getMD5Hash(DevID + "getplayer" + AuthKey + getTimestamp())
url := "http://api.smitegame.com/smiteapi.svc/getplayerJson/" + DevID + "/" + hash + "/" + SessionID + "/" + getTimestamp() + "/" + playerName
response, err := http.Get(url)
if err != nil {
perror(err)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
perror(err)
} else {
var players []Player
json.Unmarshal(contents, &players)
return players[0]
}
}
player := Player{ReturnMessage: "Not found"}
return player
}
// GetGodRanks returns a new GodRank array instance with a collection of a
// player's god rank for each God in Smite.
func GetGodRanks(playerName string) []GodRank {
hash := getMD5Hash(DevID + "getgodranks" + AuthKey + getTimestamp())
url := "http://api.smitegame.com/smiteapi.svc/getgodranksJson/" + DevID + "/" + hash + "/" + SessionID + "/" + getTimestamp() + "/" + playerName
response, err := http.Get(url)
if err != nil {
perror(err)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
perror(err)
} else {
var godRanks []GodRank
json.Unmarshal(contents, &godRanks)
return godRanks
}
}
godRanks := []GodRank{}
return godRanks
}
// GetFriends returns a new Friend array instance with a collection of a
// player's friends.
func GetFriends(playerName string) []Friend {
hash := getMD5Hash(DevID + "getfriends" + AuthKey + getTimestamp())
url := "http://api.smitegame.com/smiteapi.svc/getfriendsJson/" + DevID + "/" + hash + "/" + SessionID + "/" + getTimestamp() + "/" + playerName
response, err := http.Get(url)
if err != nil {
perror(err)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
perror(err)
} else {
var friends []Friend
json.Unmarshal(contents, &friends)
return friends
}
}
friends := []Friend{}
return friends
}
// GetLeagueLeaderBoard returns a JSON string of players for a given queue on
// a given tier grade for a given season. Currently this API endpoint is not
// working well on HiRez's end.
func GetLeagueLeaderBoard(queue string, tier string, season string) string {
hash := getMD5Hash(DevID + "getleagueleaderboard" + AuthKey + getTimestamp())
url := "http://api.smitegame.com/smiteapi.svc/getleagueleaderboardJson/" + DevID + "/" + hash + "/" + SessionID + "/" + getTimestamp() + "/" + queue + "/" + tier + "/" + season
response, err := http.Get(url)
if err != nil {
perror(err)
} else {
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
perror(err)
} else {
return string(contents)
}
}
return ""
}