Merge pull request #4 from dmmcquay/master

Created halo pkg and fixed naming of funcs
This commit is contained in:
Thomas Bennett 2016-05-05 14:50:17 -07:00
commit 6d4ae9303c
3 changed files with 125 additions and 73 deletions

27
.gitignore vendored Normal file
View File

@ -0,0 +1,27 @@
# ---> Go
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof
*.swp

View File

@ -1,4 +1,4 @@
package main package halo
import ( import (
"fmt" "fmt"
@ -10,25 +10,22 @@ import (
"strings" "strings"
) )
var baseurl string = "https://www.haloapi.com"
var title string = "h5"
func checkErr(err error) { func checkErr(err error) {
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }
func events_for_match(baseurl, title, matchid string) string { func EventsForMatch(baseurl, title, matchid string) string {
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/matches/%s/events", baseurl, title, matchid)) url, err := url.Parse(fmt.Sprintf("%s/stats/%s/matches/%s/events", baseurl, title, matchid))
checkErr(err) checkErr(err)
q := url.Query() q := url.Query()
url.RawQuery = q.Encode() url.RawQuery = q.Encode()
response := send_request(url.String()) response := sendRequest(url.String())
return response return response
} }
func matches_for_player(baseurl, title, player, modes string, start, count int) string { func MatchesForPlayer(baseurl, title, player, modes string, start, count int) string {
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/players/%s/matches", baseurl, title, player)) url, err := url.Parse(fmt.Sprintf("%s/stats/%s/players/%s/matches", baseurl, title, player))
checkErr(err) checkErr(err)
q := url.Query() q := url.Query()
@ -43,11 +40,11 @@ func matches_for_player(baseurl, title, player, modes string, start, count int)
q.Set("count", string(count)) q.Set("count", string(count))
} }
url.RawQuery = q.Encode() url.RawQuery = q.Encode()
response := send_request(url.String()) response := sendRequest(url.String())
return response return response
} }
func player_leaderboard(baseurl, title, seasonid, playlistid string, count int) string { func PlayerLeaderboard(baseurl, title, seasonid, playlistid string, count int) string {
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", baseurl, title, seasonid, playlistid))
checkErr(err) checkErr(err)
q := url.Query() q := url.Query()
@ -56,47 +53,47 @@ func player_leaderboard(baseurl, title, seasonid, playlistid string, count int)
q.Set("count", string(count)) q.Set("count", string(count))
} }
url.RawQuery = q.Encode() url.RawQuery = q.Encode()
response := send_request(url.String()) response := sendRequest(url.String())
return response return response
} }
func carnage_report_arena(baseurl, title, matchid string) string { func CarnageReportArena(baseurl, title, matchid string) string {
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", baseurl, title, matchid))
checkErr(err) checkErr(err)
q := url.Query() q := url.Query()
url.RawQuery = q.Encode() url.RawQuery = q.Encode()
response := send_request(url.String()) response := sendRequest(url.String())
return response return response
} }
func carnage_report_campaign(baseurl, title, matchid string) string { func CarnageReportCampaign(baseurl, title, matchid string) string {
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", baseurl, title, matchid))
checkErr(err) checkErr(err)
q := url.Query() q := url.Query()
url.RawQuery = q.Encode() url.RawQuery = q.Encode()
response := send_request(url.String()) response := sendRequest(url.String())
return response return response
} }
func carnage_report_custom(baseurl, title, matchid string) string { func CarnageReportCustom(baseurl, title, matchid string) string {
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", baseurl, title, matchid))
checkErr(err) checkErr(err)
q := url.Query() q := url.Query()
url.RawQuery = q.Encode() url.RawQuery = q.Encode()
response := send_request(url.String()) response := sendRequest(url.String())
return response return response
} }
func carnage_report_warzone(baseurl, title, matchid string) string { func CarnageReportWarzone(baseurl, title, matchid string) string {
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", baseurl, title, matchid))
checkErr(err) checkErr(err)
q := url.Query() q := url.Query()
url.RawQuery = q.Encode() url.RawQuery = q.Encode()
response := send_request(url.String()) response := sendRequest(url.String())
return response return response
} }
func service_record_arena(baseurl, title, players, seasonid string) string { func ServiceRecordArena(baseurl, title, players, seasonid string) string {
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/arena/", baseurl, title)) url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/arena/", baseurl, title))
checkErr(err) checkErr(err)
q := url.Query() q := url.Query()
@ -105,42 +102,42 @@ func service_record_arena(baseurl, title, players, seasonid string) string {
q.Set("seasonId", seasonid) q.Set("seasonId", seasonid)
} }
url.RawQuery = q.Encode() url.RawQuery = q.Encode()
response := send_request(url.String()) response := sendRequest(url.String())
return response return response
} }
func service_record_campaign(baseurl, title, players string) string { func ServiceRecordCampaign(baseurl, title, players string) string {
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/campaign/", baseurl, title)) url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/campaign/", baseurl, title))
checkErr(err) checkErr(err)
q := url.Query() q := url.Query()
q.Set("players", players) q.Set("players", players)
url.RawQuery = q.Encode() url.RawQuery = q.Encode()
response := send_request(url.String()) response := sendRequest(url.String())
return response return response
} }
func service_record_custom(baseurl, title, players string) string { func ServiceRecordCustom(baseurl, title, players string) string {
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/custom/", baseurl, title)) url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/custom/", baseurl, title))
checkErr(err) checkErr(err)
q := url.Query() q := url.Query()
q.Set("players", players) q.Set("players", players)
url.RawQuery = q.Encode() url.RawQuery = q.Encode()
response := send_request(url.String()) response := sendRequest(url.String())
return response return response
} }
func service_record_warzone(baseurl, title, players string) string { func ServiceRecordWarzone(baseurl, title, players string) string {
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/warzone/", baseurl, title)) url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/warzone/", baseurl, title))
checkErr(err) checkErr(err)
q := url.Query() q := url.Query()
q.Set("players", players) q.Set("players", players)
url.RawQuery = q.Encode() url.RawQuery = q.Encode()
response := send_request(url.String()) response := sendRequest(url.String())
return response return response
} }
// Begin profile section // Begin profile section
func emblem_image(baseurl, title, player string, size int) string { func EmblemImage(baseurl, title, player string, size int) string {
url, err := url.Parse(fmt.Sprintf("%s/profile/%s/profiles/%s/", baseurl, title, player)) url, err := url.Parse(fmt.Sprintf("%s/profile/%s/profiles/%s/", baseurl, title, player))
checkErr(err) checkErr(err)
q := url.Query() q := url.Query()
@ -148,11 +145,11 @@ func emblem_image(baseurl, title, player string, size int) string {
q.Set("size", string(size)) q.Set("size", string(size))
} }
url.RawQuery = q.Encode() url.RawQuery = q.Encode()
response := send_request(url.String()) response := sendRequest(url.String())
return response return response
} }
func spartan_image(baseurl, title, player string, size int, crop string) string { func SpartanImage(baseurl, title, player string, size int, crop string) string {
url, err := url.Parse(fmt.Sprintf("%s/profile/%s/profiles/%s/spartan/", baseurl, title, player)) url, err := url.Parse(fmt.Sprintf("%s/profile/%s/profiles/%s/spartan/", baseurl, title, player))
checkErr(err) checkErr(err)
q := url.Query() q := url.Query()
@ -163,101 +160,101 @@ func spartan_image(baseurl, title, player string, size int, crop string) string
q.Set("crop", crop) q.Set("crop", crop)
} }
url.RawQuery = q.Encode() url.RawQuery = q.Encode()
response := send_request(url.String()) response := sendRequest(url.String())
return response return response
} }
// Begin metadata section // Begin metadata section
func campaign_missions(baseurl, title string) string { func CampaignMissions(baseurl, title string) string {
return metadata_request(baseurl, title, "campaign-missions", "") return metadataRequest(baseurl, title, "campaign-missions", "")
} }
func commendations(baseurl, title string) string { func Commendations(baseurl, title string) string {
return metadata_request(baseurl, title, "commendations", "") return metadataRequest(baseurl, title, "commendations", "")
} }
func csr_designations(baseurl, title string) string { func CsrDesignations(baseurl, title string) string {
return metadata_request(baseurl, title, "csr-designations", "") return metadataRequest(baseurl, title, "csr-designations", "")
} }
func enemies(baseurl, title string) string { func Enemies(baseurl, title string) string {
return metadata_request(baseurl, title, "enemies", "") return metadataRequest(baseurl, title, "enemies", "")
} }
func flexible_stats(baseurl, title string) string { func FlexibleStats(baseurl, title string) string {
return metadata_request(baseurl, title, "flexible-stats", "") return metadataRequest(baseurl, title, "flexible-stats", "")
} }
func game_base_variants(baseurl, title string) string { func GameBaseVariants(baseurl, title string) string {
return metadata_request(baseurl, title, "game-base-variants", "") return metadataRequest(baseurl, title, "game-base-variants", "")
} }
func game_variants(baseurl, title, id string) string { func GameVariants(baseurl, title, id string) string {
return metadata_request(baseurl, title, "game-variants", id) return metadataRequest(baseurl, title, "game-variants", id)
} }
func impulses(baseurl, title string) string { func Impulses(baseurl, title string) string {
return metadata_request(baseurl, title, "impulses", "") return metadataRequest(baseurl, title, "impulses", "")
} }
func map_variants(baseurl, title, id string) string { func MapVariants(baseurl, title, id string) string {
return metadata_request(baseurl, title, "map-variants", id) return metadataRequest(baseurl, title, "map-variants", id)
} }
func maps(baseurl, title string) string { func Maps(baseurl, title string) string {
return metadata_request(baseurl, title, "maps", "") return metadataRequest(baseurl, title, "maps", "")
} }
func medals(baseurl, title string) string { func Medals(baseurl, title string) string {
return metadata_request(baseurl, title, "medals", "") return metadataRequest(baseurl, title, "medals", "")
} }
func playlists(baseurl, title string) string { func Playlists(baseurl, title string) string {
return metadata_request(baseurl, title, "playlists", "") return metadataRequest(baseurl, title, "playlists", "")
} }
func requisition_packs(baseurl, title, id string) string { func RequisitionPacks(baseurl, title, id string) string {
return metadata_request(baseurl, title, "requisition-packs", id) return metadataRequest(baseurl, title, "requisition-packs", id)
} }
func requisitions(baseurl, title, id string) string { func Requisitions(baseurl, title, id string) string {
return metadata_request(baseurl, title, "requisitions", id) return metadataRequest(baseurl, title, "requisitions", id)
} }
func seasons(baseurl, title string) string { func Seasons(baseurl, title string) string {
return metadata_request(baseurl, title, "seasons", "") return metadataRequest(baseurl, title, "seasons", "")
} }
func skulls(baseurl, title string) string { func Skulls(baseurl, title string) string {
return metadata_request(baseurl, title, "skulls", "") return metadataRequest(baseurl, title, "skulls", "")
} }
func spartan_ranks(baseurl, title string) string { func SpartanRanks(baseurl, title string) string {
return metadata_request(baseurl, title, "spartan-ranks", "") return metadataRequest(baseurl, title, "spartan-ranks", "")
} }
func team_colors(baseurl, title string) string { func TeamColors(baseurl, title string) string {
return metadata_request(baseurl, title, "team-colors", "") return metadataRequest(baseurl, title, "team-colors", "")
} }
func vehicles(baseurl, title string) string { func Vehicles(baseurl, title string) string {
return metadata_request(baseurl, title, "vehicles", "") return metadataRequest(baseurl, title, "vehicles", "")
} }
func weapons(baseurl, title string) string { func Weapons(baseurl, title string) string {
return metadata_request(baseurl, title, "weapons", "") return metadataRequest(baseurl, title, "weapons", "")
} }
func metadata_request(baseurl, title, datatype, id string) string { func metadataRequest(baseurl, title, datatype, id string) string {
url, err := url.Parse(fmt.Sprintf("%s/metadata/%s/metadata/%s/%s", baseurl, title, datatype, id)) url, err := url.Parse(fmt.Sprintf("%s/metadata/%s/metadata/%s/%s", baseurl, title, datatype, id))
checkErr(err) checkErr(err)
q := url.Query() q := url.Query()
url.RawQuery = q.Encode() url.RawQuery = q.Encode()
response := send_request(url.String()) response := sendRequest(url.String())
return response return response
} }
func send_request(url string) string { func sendRequest(url string) string {
request, err := http.NewRequest("GET", url, nil) request, err := http.NewRequest("GET", url, nil)
checkErr(err) checkErr(err)
apikey := os.Getenv("HALO_API_KEY") apikey := os.Getenv("HALO_API_KEY")

28
main.go Normal file
View File

@ -0,0 +1,28 @@
package main
import (
"fmt"
"github.com/dmmcquay/go-halo5-api/halo"
)
var baseurl string = "https://www.haloapi.com"
var title string = "h5"
// Sample values for testing
var sampleGamertag string = "motta13"
var sampleMode string = "warzone"
var sampleMatchID string = "c35a35f8-f450-4836-a4c2-65100a7acb79"
var sampleSeasonID string = "b46c2095-4ca6-4f4b-a565-4702d7cfe586" //February 2016 Season
var samplePlaylistID string = "2323b76a-db98-4e03-aa37-e171cfbdd1a4" //SWAT gametype 2016 Season
var samplePlayers string = "motta13,smoke721"
func main() {
// Uncomment any of the below for sample output.
fmt.Println(halo.MatchesForPlayer(baseurl, title, sampleGamertag, "warzone", 0, 0))
//fmt.Println(events_for_match(baseurl, title, sampleMatchID))
//fmt.Println(player_leaderboard(baseurl, title, sampleSeasonID, samplePlaylistID, 0))
//fmt.Println(service_record_arena(baseurl, title, samplePlayers, sampleSeasonID))
//fmt.Println(vehicles(baseurl, title))
//fmt.Println(spartan_image(baseurl, title, gamertag, 0, ""))
}