finished converting functions to methods in the stats file
This commit is contained in:
parent
5400089684
commit
76531a8dcb
180
halo/stats.go
180
halo/stats.go
@ -56,101 +56,191 @@ func (h *Halo) MatchesForPlayer(player, modes string, start, count int) MatchesF
|
|||||||
return j
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func PlayerLeaderboard(baseurl, title, seasonid, playlistid string, count int) []byte {
|
func (h *Halo) PlayerLeaderboard(seasonid, playlistid string, count int) PlayerLeaderboardStruct {
|
||||||
|
var j PlayerLeaderboardStruct
|
||||||
verifyValidID(playlistid, "Playlist ID")
|
verifyValidID(playlistid, "Playlist ID")
|
||||||
verifyValidID(seasonid, "Season ID")
|
verifyValidID(seasonid, "Season ID")
|
||||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/player-leaderboards/csr/%s/%s", baseurl, title, seasonid, playlistid))
|
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/player-leaderboards/csr/%s/%s", h.baseurl, h.title, seasonid, playlistid))
|
||||||
checkErr(err)
|
if err != nil {
|
||||||
|
log.Fatal("PlayerLeaderboard URL Parse Failed: ", err)
|
||||||
|
}
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
|
|
||||||
if count != 0 {
|
if count != 0 {
|
||||||
q.Set("count", string(count))
|
q.Set("count", string(count))
|
||||||
}
|
}
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
response := sendRequest(url.String())
|
jsonObject, err := h.sendRequest(url.String())
|
||||||
return response
|
if err != nil {
|
||||||
|
log.Fatal("PlayerLeaderboard Failed: ", err)
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
|
}
|
||||||
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func CarnageReportArena(baseurl, title, matchid string) []byte {
|
func (h *Halo) CarnageReportArena(matchid string) CarnageReportArenaStruct {
|
||||||
|
var j CarnageReportArenaStruct
|
||||||
verifyValidID(matchid, "Match ID")
|
verifyValidID(matchid, "Match ID")
|
||||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/arena/matches/%s", baseurl, title, matchid))
|
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/arena/matches/%s", h.baseurl, h.title, matchid))
|
||||||
checkErr(err)
|
if err != nil {
|
||||||
|
log.Fatal("CarnageReportArena URL Parse Failed: ", err)
|
||||||
|
}
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
response := sendRequest(url.String())
|
jsonObject, err := h.sendRequest(url.String())
|
||||||
return response
|
if err != nil {
|
||||||
|
log.Fatal("CarnageReportArena Failed: ", err)
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
|
}
|
||||||
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func CarnageReportCampaign(baseurl, title, matchid string) []byte {
|
func (h *Halo) CarnageReportCampaign(matchid string) CarnageReportCampaignStruct {
|
||||||
|
var j CarnageReportCampaignStruct
|
||||||
verifyValidID(matchid, "Match ID")
|
verifyValidID(matchid, "Match ID")
|
||||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/campaign/matches/%s", baseurl, title, matchid))
|
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/campaign/matches/%s", h.baseurl, h.title, matchid))
|
||||||
checkErr(err)
|
if err != nil {
|
||||||
|
log.Fatal("CarnageReportCampaign URL Parse Failed: ", err)
|
||||||
|
}
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
response := sendRequest(url.String())
|
jsonObject, err := h.sendRequest(url.String())
|
||||||
return response
|
if err != nil {
|
||||||
|
log.Fatal("CarnageReportCampaign Failed: ", err)
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
|
}
|
||||||
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func CarnageReportCustom(baseurl, title, matchid string) []byte {
|
func (h *Halo) CarnageReportCustom(matchid string) CarnageReportCustomStruct {
|
||||||
|
var j CarnageReportCustomStruct
|
||||||
verifyValidID(matchid, "Match ID")
|
verifyValidID(matchid, "Match ID")
|
||||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/custom/matches/%s", baseurl, title, matchid))
|
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/custom/matches/%s", h.baseurl, h.title, matchid))
|
||||||
checkErr(err)
|
if err != nil {
|
||||||
|
log.Fatal("CarnageReportCustom URL Parse Failed: ", err)
|
||||||
|
}
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
response := sendRequest(url.String())
|
jsonObject, err := h.sendRequest(url.String())
|
||||||
return response
|
if err != nil {
|
||||||
|
log.Fatal("CarnageReportCustom Failed: ", err)
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
|
}
|
||||||
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func CarnageReportWarzone(baseurl, title, matchid string) []byte {
|
func (h *Halo) CarnageReportWarzone(matchid string) CarnageReportWarzoneStruct {
|
||||||
|
var j CarnageReportWarzoneStruct
|
||||||
verifyValidID(matchid, "Match ID")
|
verifyValidID(matchid, "Match ID")
|
||||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/warzone/matches/%s", baseurl, title, matchid))
|
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/warzone/matches/%s", h.baseurl, h.title, matchid))
|
||||||
checkErr(err)
|
if err != nil {
|
||||||
|
log.Fatal("CarnageReportWarzone URL Parse Failed: ", err)
|
||||||
|
}
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
response := sendRequest(url.String())
|
jsonObject, err := h.sendRequest(url.String())
|
||||||
return response
|
if err != nil {
|
||||||
|
log.Fatal("CarnageReportWarzone Failed: ", err)
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
|
}
|
||||||
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func ServiceRecordArena(baseurl, title, players, seasonid string) []byte {
|
func (h *Halo) ServiceRecordArena(players, seasonid string) ServiceRecordArenaStruct {
|
||||||
|
var j ServiceRecordArenaStruct
|
||||||
verifyValidID(seasonid, "Season ID")
|
verifyValidID(seasonid, "Season ID")
|
||||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/arena", baseurl, title))
|
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/arena", h.baseurl, h.title))
|
||||||
checkErr(err)
|
if err != nil {
|
||||||
|
log.Fatal("CarnageReportWarzone URL Parse Failed: ", err)
|
||||||
|
}
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
q.Set("players", players)
|
q.Set("players", players)
|
||||||
if seasonid != "" {
|
if seasonid != "" {
|
||||||
q.Set("seasonId", seasonid)
|
q.Set("seasonId", seasonid)
|
||||||
}
|
}
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
response := sendRequest(url.String())
|
jsonObject, err := h.sendRequest(url.String())
|
||||||
return response
|
if err != nil {
|
||||||
|
log.Fatal("ServiceRecordArena Failed: ", err)
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
|
}
|
||||||
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func ServiceRecordCampaign(baseurl, title, players string) []byte {
|
func (h *Halo) ServiceRecordCampaign(players string) ServiceRecordCampaignStruct {
|
||||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/campaign", baseurl, title))
|
var j ServiceRecordCampaignStruct
|
||||||
checkErr(err)
|
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/campaign", h.baseurl, h.title))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("ServiceRecordCampaign URL Parse Failed: ", err)
|
||||||
|
}
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
q.Set("players", players)
|
q.Set("players", players)
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
response := sendRequest(url.String())
|
jsonObject, err := h.sendRequest(url.String())
|
||||||
return response
|
if err != nil {
|
||||||
|
log.Fatal("ServiceRecordCampaign Failed: ", err)
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
|
}
|
||||||
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func ServiceRecordCustom(baseurl, title, players string) []byte {
|
func (h *Halo) ServiceRecordCustom(players string) ServiceRecordCustomStruct {
|
||||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/custom", baseurl, title))
|
var j ServiceRecordCustomStruct
|
||||||
checkErr(err)
|
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/custom", h.baseurl, h.title))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("ServiceRecordCampaign URL Parse Failed: ", err)
|
||||||
|
}
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
q.Set("players", players)
|
q.Set("players", players)
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
response := sendRequest(url.String())
|
jsonObject, err := h.sendRequest(url.String())
|
||||||
return response
|
if err != nil {
|
||||||
|
log.Fatal("ServiceRecordCustom Failed: ", err)
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
|
}
|
||||||
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func ServiceRecordWarzone(baseurl, title, players string) []byte {
|
func (h *Halo) ServiceRecordWarzone(players string) ServiceRecordWarzoneStruct {
|
||||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/warzone", baseurl, title))
|
var j ServiceRecordWarzoneStruct
|
||||||
checkErr(err)
|
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/warzone", h.baseurl, h.title))
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("ServiceRecordCampaign URL Parse Failed: ", err)
|
||||||
|
}
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
q.Set("players", players)
|
q.Set("players", players)
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
response := sendRequest(url.String())
|
jsonObject, err := h.sendRequest(url.String())
|
||||||
return response
|
if err != nil {
|
||||||
|
log.Fatal("ServiceRecordWarzone Failed: ", err)
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
|
}
|
||||||
|
return j
|
||||||
}
|
}
|
||||||
|
4
main.go
4
main.go
@ -54,7 +54,9 @@ func main() {
|
|||||||
//fmt.Println(h.GameVariants(sampleGameVariantID))
|
//fmt.Println(h.GameVariants(sampleGameVariantID))
|
||||||
//fmt.Println(h.MapVariants(sampleMapVariantsID))
|
//fmt.Println(h.MapVariants(sampleMapVariantsID))
|
||||||
//fmt.Println(h.Requisitions(sampleRequisitionID))
|
//fmt.Println(h.Requisitions(sampleRequisitionID))
|
||||||
fmt.Println(h.MatchesForPlayer(sampleGamertag, "", 0, 0))
|
//fmt.Println(h.MatchesForPlayer(sampleGamertag, "", 0, 0))
|
||||||
|
//fmt.Println(h.PlayerLeaderboard(sampleSeasonID, samplePlaylistID, 0))
|
||||||
|
fmt.Println(h.CarnageReportArena(sampleArenaMatchID))
|
||||||
// Uncomment any of the below for sample output.
|
// Uncomment any of the below for sample output.
|
||||||
|
|
||||||
// Metadata
|
// Metadata
|
||||||
|
Loading…
Reference in New Issue
Block a user