finished converting functions to methods in the stats file

This commit is contained in:
Thomas Bennett 2016-05-11 09:22:53 -07:00
parent 5400089684
commit 76531a8dcb
2 changed files with 138 additions and 46 deletions

View File

@ -56,101 +56,191 @@ func (h *Halo) MatchesForPlayer(player, modes string, start, count int) MatchesF
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(seasonid, "Season ID")
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/player-leaderboards/csr/%s/%s", baseurl, title, seasonid, playlistid))
checkErr(err)
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/player-leaderboards/csr/%s/%s", h.baseurl, h.title, seasonid, playlistid))
if err != nil {
log.Fatal("PlayerLeaderboard URL Parse Failed: ", err)
}
q := url.Query()
if count != 0 {
q.Set("count", string(count))
}
url.RawQuery = q.Encode()
response := sendRequest(url.String())
return response
jsonObject, err := h.sendRequest(url.String())
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")
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/arena/matches/%s", baseurl, title, matchid))
checkErr(err)
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/arena/matches/%s", h.baseurl, h.title, matchid))
if err != nil {
log.Fatal("CarnageReportArena URL Parse Failed: ", err)
}
q := url.Query()
url.RawQuery = q.Encode()
response := sendRequest(url.String())
return response
jsonObject, err := h.sendRequest(url.String())
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")
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/campaign/matches/%s", baseurl, title, matchid))
checkErr(err)
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/campaign/matches/%s", h.baseurl, h.title, matchid))
if err != nil {
log.Fatal("CarnageReportCampaign URL Parse Failed: ", err)
}
q := url.Query()
url.RawQuery = q.Encode()
response := sendRequest(url.String())
return response
jsonObject, err := h.sendRequest(url.String())
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")
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/custom/matches/%s", baseurl, title, matchid))
checkErr(err)
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/custom/matches/%s", h.baseurl, h.title, matchid))
if err != nil {
log.Fatal("CarnageReportCustom URL Parse Failed: ", err)
}
q := url.Query()
url.RawQuery = q.Encode()
response := sendRequest(url.String())
return response
jsonObject, err := h.sendRequest(url.String())
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")
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/warzone/matches/%s", baseurl, title, matchid))
checkErr(err)
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/warzone/matches/%s", h.baseurl, h.title, matchid))
if err != nil {
log.Fatal("CarnageReportWarzone URL Parse Failed: ", err)
}
q := url.Query()
url.RawQuery = q.Encode()
response := sendRequest(url.String())
return response
jsonObject, err := h.sendRequest(url.String())
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")
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/arena", baseurl, title))
checkErr(err)
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/arena", h.baseurl, h.title))
if err != nil {
log.Fatal("CarnageReportWarzone URL Parse Failed: ", err)
}
q := url.Query()
q.Set("players", players)
if seasonid != "" {
q.Set("seasonId", seasonid)
}
url.RawQuery = q.Encode()
response := sendRequest(url.String())
return response
jsonObject, err := h.sendRequest(url.String())
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 {
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/campaign", baseurl, title))
checkErr(err)
func (h *Halo) ServiceRecordCampaign(players string) ServiceRecordCampaignStruct {
var j ServiceRecordCampaignStruct
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.Set("players", players)
url.RawQuery = q.Encode()
response := sendRequest(url.String())
return response
jsonObject, err := h.sendRequest(url.String())
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 {
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/custom", baseurl, title))
checkErr(err)
func (h *Halo) ServiceRecordCustom(players string) ServiceRecordCustomStruct {
var j ServiceRecordCustomStruct
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.Set("players", players)
url.RawQuery = q.Encode()
response := sendRequest(url.String())
return response
jsonObject, err := h.sendRequest(url.String())
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 {
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/warzone", baseurl, title))
checkErr(err)
func (h *Halo) ServiceRecordWarzone(players string) ServiceRecordWarzoneStruct {
var j ServiceRecordWarzoneStruct
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.Set("players", players)
url.RawQuery = q.Encode()
response := sendRequest(url.String())
return response
jsonObject, err := h.sendRequest(url.String())
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
}

View File

@ -54,7 +54,9 @@ func main() {
//fmt.Println(h.GameVariants(sampleGameVariantID))
//fmt.Println(h.MapVariants(sampleMapVariantsID))
//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.
// Metadata