Started work on returning structs instead of json strings
Lots of tests have been added to the main.go file. Several of the functions return structs now instead of json strings. I've added the initial structs for the remaining functions.
This commit is contained in:
parent
136d0df4c9
commit
a6028a69aa
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,6 +7,7 @@
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
_tmp
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
|
@ -2,7 +2,7 @@
|
||||
go-halo5-api is a wrapper around the Halo5 API as documented at https://developer.haloapi.com.
|
||||
|
||||
# Usage
|
||||
Set your API key as an environment variable
|
||||
Set your API key as an environment variable. Request and API key at https://developer.haloapi.com/products
|
||||
```go
|
||||
export HALO_API_KEY="123456789abcdefghi"
|
||||
```
|
||||
@ -23,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println(vehicles("https://www.haloapi.com", "h5"))
|
||||
fmt.Println(string(Vehicles("https://www.haloapi.com", "h5")))
|
||||
}
|
||||
```
|
||||
Results:
|
||||
|
@ -8,7 +8,6 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func checkErr(err error) {
|
||||
@ -17,243 +16,6 @@ func checkErr(err error) {
|
||||
}
|
||||
}
|
||||
|
||||
func EventsForMatch(baseurl, title, matchid string) []byte {
|
||||
verifyValidID(matchid, "Match ID")
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/matches/%s/events", baseurl, title, matchid))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func MatchesForPlayer(baseurl, title, player, modes string, start, count int) []byte {
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/players/%s/matches", baseurl, title, player))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
|
||||
if modes != "" {
|
||||
q.Set("modes", modes)
|
||||
}
|
||||
if start != 0 {
|
||||
q.Set("start", string(start))
|
||||
}
|
||||
if count != 0 {
|
||||
q.Set("count", string(count))
|
||||
}
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func PlayerLeaderboard(baseurl, title, seasonid, playlistid string, count int) []byte {
|
||||
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)
|
||||
q := url.Query()
|
||||
|
||||
if count != 0 {
|
||||
q.Set("count", string(count))
|
||||
}
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func CarnageReportArena(baseurl, title, matchid string) []byte {
|
||||
verifyValidID(matchid, "Match ID")
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/arena/matches/%s", baseurl, title, matchid))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func CarnageReportCampaign(baseurl, title, matchid string) []byte {
|
||||
verifyValidID(matchid, "Match ID")
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/campaign/matches/%s", baseurl, title, matchid))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func CarnageReportCustom(baseurl, title, matchid string) []byte {
|
||||
verifyValidID(matchid, "Match ID")
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/custom/matches/%s", baseurl, title, matchid))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func CarnageReportWarzone(baseurl, title, matchid string) []byte {
|
||||
verifyValidID(matchid, "Match ID")
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/warzone/matches/%s", baseurl, title, matchid))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func ServiceRecordArena(baseurl, title, players, seasonid string) []byte {
|
||||
verifyValidID(seasonid, "Season ID")
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/arena", baseurl, title))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
q.Set("players", players)
|
||||
if seasonid != "" {
|
||||
q.Set("seasonId", seasonid)
|
||||
}
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func ServiceRecordCampaign(baseurl, title, players string) []byte {
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/campaign", baseurl, title))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
q.Set("players", players)
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func ServiceRecordCustom(baseurl, title, players string) []byte {
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/custom", baseurl, title))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
q.Set("players", players)
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func ServiceRecordWarzone(baseurl, title, players string) []byte {
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/warzone", baseurl, title))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
q.Set("players", players)
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
// Begin profile section
|
||||
func EmblemImage(baseurl, title, player string, size int) []byte {
|
||||
url, err := url.Parse(fmt.Sprintf("%s/profile/%s/profiles/%s", baseurl, title, player))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
if (size == 95) || (size == 128) || (size == 190) || (size == 256) || (size == 512) {
|
||||
q.Set("size", string(size))
|
||||
}
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func SpartanImage(baseurl, title, player string, size int, crop string) []byte {
|
||||
url, err := url.Parse(fmt.Sprintf("%s/profile/%s/profiles/%s/spartan", baseurl, title, player))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
if (size == 95) || (size == 128) || (size == 190) || (size == 256) || (size == 512) {
|
||||
q.Set("size", string(size))
|
||||
}
|
||||
if (strings.ToLower(crop) == "full") || (strings.ToLower(crop) == "portrait") {
|
||||
q.Set("crop", crop)
|
||||
}
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
// Begin metadata section
|
||||
func CampaignMissions(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "campaign-missions", "")
|
||||
}
|
||||
|
||||
func Commendations(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "commendations", "")
|
||||
}
|
||||
|
||||
func CsrDesignations(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "csr-designations", "")
|
||||
}
|
||||
|
||||
func Enemies(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "enemies", "")
|
||||
}
|
||||
|
||||
func FlexibleStats(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "flexible-stats", "")
|
||||
}
|
||||
|
||||
func GameBaseVariants(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "game-base-variants", "")
|
||||
}
|
||||
|
||||
func GameVariants(baseurl, title, id string) []byte {
|
||||
return metadataRequest(baseurl, title, "game-variants", id)
|
||||
}
|
||||
|
||||
func Impulses(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "impulses", "")
|
||||
}
|
||||
|
||||
func MapVariants(baseurl, title, id string) []byte {
|
||||
return metadataRequest(baseurl, title, "map-variants", id)
|
||||
}
|
||||
|
||||
func Maps(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "maps", "")
|
||||
}
|
||||
|
||||
func Medals(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "medals", "")
|
||||
}
|
||||
|
||||
func Playlists(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "playlists", "")
|
||||
}
|
||||
|
||||
func RequisitionPacks(baseurl, title, id string) []byte {
|
||||
return metadataRequest(baseurl, title, "requisition-packs", id)
|
||||
}
|
||||
|
||||
func Requisitions(baseurl, title, id string) []byte {
|
||||
return metadataRequest(baseurl, title, "requisitions", id)
|
||||
}
|
||||
|
||||
func Seasons(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "seasons", "")
|
||||
}
|
||||
|
||||
func Skulls(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "skulls", "")
|
||||
}
|
||||
|
||||
func SpartanRanks(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "spartan-ranks", "")
|
||||
}
|
||||
|
||||
func TeamColors(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "team-colors", "")
|
||||
}
|
||||
|
||||
func Vehicles(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "vehicles", "")
|
||||
}
|
||||
|
||||
func Weapons(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "weapons", "")
|
||||
}
|
||||
|
||||
func metadataRequest(baseurl, title, datatype, id string) []byte {
|
||||
url, err := url.Parse(fmt.Sprintf("%s/metadata/%s/metadata/%s/%s", baseurl, title, datatype, id))
|
||||
checkErr(err)
|
||||
|
183
halo/metadata.go
Normal file
183
halo/metadata.go
Normal file
@ -0,0 +1,183 @@
|
||||
package halo
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// This one works!
|
||||
type CampaignMissionsStruct []struct {
|
||||
MissionNumber json.Number `json:"missionNumber"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
ImageURL string `json:"imageUrl"`
|
||||
Type string `json:"type"`
|
||||
ID string `json:"id"`
|
||||
ContentID string `json:"contentId"`
|
||||
}
|
||||
|
||||
// This one works!
|
||||
type CommendationsStruct []struct {
|
||||
Type string `json:"type"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
IconImageURL string `json:"iconImageUrl"`
|
||||
Levels []struct {
|
||||
Reward struct {
|
||||
Xp int `json:"xp"`
|
||||
RequisitionPacks []struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
LargeImageURL string `json:"largeImageUrl"`
|
||||
IsStack bool `json:"isStack"`
|
||||
IsFeatured bool `json:"isFeatured"`
|
||||
IsNew bool `json:"isNew"`
|
||||
CreditPrice int `json:"creditPrice"`
|
||||
IsPurchasableWithCredits bool `json:"isPurchasableWithCredits"`
|
||||
IsPurchasableFromMarketplace bool `json:"isPurchasableFromMarketplace"`
|
||||
XboxMarketplaceProductID interface{} `json:"xboxMarketplaceProductId"`
|
||||
XboxMarketplaceProductURL interface{} `json:"xboxMarketplaceProductUrl"`
|
||||
MerchandisingOrder int `json:"merchandisingOrder"`
|
||||
Flair interface{} `json:"flair"`
|
||||
StackedRequisitionPacks []interface{} `json:"stackedRequisitionPacks"`
|
||||
ID string `json:"id"`
|
||||
ContentID string `json:"contentId"`
|
||||
} `json:"requisitionPacks"`
|
||||
ID string `json:"id"`
|
||||
ContentID string `json:"contentId"`
|
||||
} `json:"reward"`
|
||||
Threshold int `json:"threshold"`
|
||||
ID string `json:"id"`
|
||||
ContentID string `json:"contentId"`
|
||||
} `json:"levels"`
|
||||
RequiredLevels []interface{} `json:"requiredLevels"`
|
||||
Reward interface{} `json:"reward"`
|
||||
Category struct {
|
||||
Name string `json:"name"`
|
||||
IconImageURL string `json:"iconImageUrl"`
|
||||
Order int `json:"order"`
|
||||
ID string `json:"id"`
|
||||
ContentID string `json:"contentId"`
|
||||
} `json:"category"`
|
||||
ID string `json:"id"`
|
||||
ContentID string `json:"contentId"`
|
||||
}
|
||||
|
||||
// This one works!
|
||||
type CsrDesignationsStruct []struct {
|
||||
Name string `json:"name"`
|
||||
BannerImageURL string `json:"bannerImageUrl"`
|
||||
Tiers []struct {
|
||||
IconImageURL string `json:"iconImageUrl"`
|
||||
ID string `json:"id"`
|
||||
ContentID string `json:"contentId"`
|
||||
} `json:"tiers"`
|
||||
ID string `json:"id"`
|
||||
ContentID string `json:"contentId"`
|
||||
}
|
||||
|
||||
type EnemiesStruct []struct {
|
||||
Faction string `json:"faction"`
|
||||
Name string `json:"name"`
|
||||
Description interface{} `json:"description"`
|
||||
LargeIconImageURL string `json:"largeIconImageUrl"`
|
||||
SmallIconImageURL string `json:"smallIconImageUrl"`
|
||||
ID string `json:"id"`
|
||||
ContentID string `json:"contentId"`
|
||||
}
|
||||
|
||||
type VehiclesStruct []struct {
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
LargeIconImageURL string `json:"largeIconImageUrl"`
|
||||
SmallIconImageURL string `json:"smallIconImageUrl"`
|
||||
IsUsableByPlayer bool `json:"isUsableByPlayer"`
|
||||
ID string `json:"id"`
|
||||
ContentID string `json:"contentId"`
|
||||
}
|
||||
|
||||
func CampaignMissions(baseurl, title string) CampaignMissionsStruct {
|
||||
var j CampaignMissionsStruct
|
||||
err := json.Unmarshal(metadataRequest(baseurl, title, "campaign-missions", ""), &j)
|
||||
checkErr(err)
|
||||
return j
|
||||
}
|
||||
|
||||
func Commendations(baseurl, title string) CommendationsStruct {
|
||||
var j CommendationsStruct
|
||||
err := json.Unmarshal(metadataRequest(baseurl, title, "commendations", ""), &j)
|
||||
checkErr(err)
|
||||
return j
|
||||
}
|
||||
|
||||
func CsrDesignations(baseurl, title string) CsrDesignationsStruct {
|
||||
var j CsrDesignationsStruct
|
||||
err := json.Unmarshal(metadataRequest(baseurl, title, "csr-designations", ""), &j)
|
||||
checkErr(err)
|
||||
return j
|
||||
}
|
||||
|
||||
func Enemies(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "enemies", "")
|
||||
}
|
||||
|
||||
func FlexibleStats(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "flexible-stats", "")
|
||||
}
|
||||
|
||||
func GameBaseVariants(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "game-base-variants", "")
|
||||
}
|
||||
|
||||
func GameVariants(baseurl, title, id string) []byte {
|
||||
return metadataRequest(baseurl, title, "game-variants", id)
|
||||
}
|
||||
|
||||
func Impulses(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "impulses", "")
|
||||
}
|
||||
|
||||
func MapVariants(baseurl, title, id string) []byte {
|
||||
return metadataRequest(baseurl, title, "map-variants", id)
|
||||
}
|
||||
|
||||
func Maps(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "maps", "")
|
||||
}
|
||||
|
||||
func Medals(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "medals", "")
|
||||
}
|
||||
|
||||
func Playlists(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "playlists", "")
|
||||
}
|
||||
|
||||
func RequisitionPacks(baseurl, title, id string) []byte {
|
||||
return metadataRequest(baseurl, title, "requisition-packs", id)
|
||||
}
|
||||
|
||||
func Requisitions(baseurl, title, id string) []byte {
|
||||
return metadataRequest(baseurl, title, "requisitions", id)
|
||||
}
|
||||
|
||||
func Seasons(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "seasons", "")
|
||||
}
|
||||
|
||||
func Skulls(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "skulls", "")
|
||||
}
|
||||
|
||||
func SpartanRanks(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "spartan-ranks", "")
|
||||
}
|
||||
|
||||
func TeamColors(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "team-colors", "")
|
||||
}
|
||||
|
||||
func Vehicles(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "vehicles", "")
|
||||
}
|
||||
|
||||
func Weapons(baseurl, title string) []byte {
|
||||
return metadataRequest(baseurl, title, "weapons", "")
|
||||
}
|
34
halo/profile.go
Normal file
34
halo/profile.go
Normal file
@ -0,0 +1,34 @@
|
||||
package halo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func EmblemImage(baseurl, title, player string, size int) []byte {
|
||||
url, err := url.Parse(fmt.Sprintf("%s/profile/%s/profiles/%s", baseurl, title, player))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
if (size == 95) || (size == 128) || (size == 190) || (size == 256) || (size == 512) {
|
||||
q.Set("size", string(size))
|
||||
}
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func SpartanImage(baseurl, title, player string, size int, crop string) []byte {
|
||||
url, err := url.Parse(fmt.Sprintf("%s/profile/%s/profiles/%s/spartan", baseurl, title, player))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
if (size == 95) || (size == 128) || (size == 190) || (size == 256) || (size == 512) {
|
||||
q.Set("size", string(size))
|
||||
}
|
||||
if (strings.ToLower(crop) == "full") || (strings.ToLower(crop) == "portrait") {
|
||||
q.Set("crop", crop)
|
||||
}
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
249
halo/stats.go
Normal file
249
halo/stats.go
Normal file
@ -0,0 +1,249 @@
|
||||
package halo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Stats Structs
|
||||
type EventsForMatchStruct struct {
|
||||
GameEvents []struct {
|
||||
EventName string `json:"EventName"`
|
||||
RoundIndex int `json:"RoundIndex"`
|
||||
TimeSinceStart string `json:"TimeSinceStart"`
|
||||
} `json:"GameEvents"`
|
||||
IsCompleteSetOfEvents bool `json:"IsCompleteSetOfEvents"`
|
||||
Links struct {
|
||||
StatsMatchDetails struct {
|
||||
AcknowledgementTypeID int `json:"AcknowledgementTypeId"`
|
||||
AuthenticationLifetimeExtensionSupported bool `json:"AuthenticationLifetimeExtensionSupported"`
|
||||
AuthorityID string `json:"AuthorityId"`
|
||||
Path string `json:"Path"`
|
||||
QueryString interface{} `json:"QueryString"`
|
||||
RetryPolicyID string `json:"RetryPolicyId"`
|
||||
TopicName string `json:"TopicName"`
|
||||
} `json:"StatsMatchDetails"`
|
||||
UgcFilmManifest struct {
|
||||
AcknowledgementTypeID int `json:"AcknowledgementTypeId"`
|
||||
AuthenticationLifetimeExtensionSupported bool `json:"AuthenticationLifetimeExtensionSupported"`
|
||||
AuthorityID string `json:"AuthorityId"`
|
||||
Path string `json:"Path"`
|
||||
QueryString string `json:"QueryString"`
|
||||
RetryPolicyID string `json:"RetryPolicyId"`
|
||||
TopicName string `json:"TopicName"`
|
||||
} `json:"UgcFilmManifest"`
|
||||
} `json:"Links"`
|
||||
}
|
||||
|
||||
type MatchesForPlayerStruct struct {
|
||||
Start int `json:"Start"`
|
||||
Count int `json:"Count"`
|
||||
ResultCount int `json:"ResultCount"`
|
||||
Results []struct {
|
||||
Links struct {
|
||||
StatsMatchDetails struct {
|
||||
AuthorityID string `json:"AuthorityId"`
|
||||
Path string `json:"Path"`
|
||||
QueryString interface{} `json:"QueryString"`
|
||||
RetryPolicyID string `json:"RetryPolicyId"`
|
||||
TopicName string `json:"TopicName"`
|
||||
AcknowledgementTypeID int `json:"AcknowledgementTypeId"`
|
||||
AuthenticationLifetimeExtensionSupported bool `json:"AuthenticationLifetimeExtensionSupported"`
|
||||
} `json:"StatsMatchDetails"`
|
||||
UgcFilmManifest struct {
|
||||
AuthorityID string `json:"AuthorityId"`
|
||||
Path string `json:"Path"`
|
||||
QueryString string `json:"QueryString"`
|
||||
RetryPolicyID string `json:"RetryPolicyId"`
|
||||
TopicName string `json:"TopicName"`
|
||||
AcknowledgementTypeID int `json:"AcknowledgementTypeId"`
|
||||
AuthenticationLifetimeExtensionSupported bool `json:"AuthenticationLifetimeExtensionSupported"`
|
||||
} `json:"UgcFilmManifest"`
|
||||
} `json:"Links"`
|
||||
ID struct {
|
||||
MatchID string `json:"MatchId"`
|
||||
GameMode int `json:"GameMode"`
|
||||
} `json:"Id"`
|
||||
HopperID string `json:"HopperId"`
|
||||
MapID string `json:"MapId"`
|
||||
MapVariant struct {
|
||||
ResourceType int `json:"ResourceType"`
|
||||
ResourceID string `json:"ResourceId"`
|
||||
OwnerType int `json:"OwnerType"`
|
||||
Owner string `json:"Owner"`
|
||||
} `json:"MapVariant"`
|
||||
GameBaseVariantID string `json:"GameBaseVariantId"`
|
||||
GameVariant struct {
|
||||
ResourceType int `json:"ResourceType"`
|
||||
ResourceID string `json:"ResourceId"`
|
||||
OwnerType int `json:"OwnerType"`
|
||||
Owner string `json:"Owner"`
|
||||
} `json:"GameVariant"`
|
||||
MatchDuration string `json:"MatchDuration"`
|
||||
MatchCompletedDate struct {
|
||||
ISO8601Date time.Time `json:"ISO8601Date"`
|
||||
} `json:"MatchCompletedDate"`
|
||||
Teams []struct {
|
||||
ID int `json:"Id"`
|
||||
Score int `json:"Score"`
|
||||
Rank int `json:"Rank"`
|
||||
} `json:"Teams"`
|
||||
Players []struct {
|
||||
Player struct {
|
||||
Gamertag string `json:"Gamertag"`
|
||||
Xuid interface{} `json:"Xuid"`
|
||||
} `json:"Player"`
|
||||
TeamID int `json:"TeamId"`
|
||||
Rank int `json:"Rank"`
|
||||
Result int `json:"Result"`
|
||||
TotalKills int `json:"TotalKills"`
|
||||
TotalDeaths int `json:"TotalDeaths"`
|
||||
TotalAssists int `json:"TotalAssists"`
|
||||
PreMatchRatings interface{} `json:"PreMatchRatings"`
|
||||
PostMatchRatings interface{} `json:"PostMatchRatings"`
|
||||
} `json:"Players"`
|
||||
IsTeamGame bool `json:"IsTeamGame"`
|
||||
SeasonID interface{} `json:"SeasonId"`
|
||||
MatchCompletedDateFidelity int `json:"MatchCompletedDateFidelity"`
|
||||
} `json:"Results"`
|
||||
Links struct {
|
||||
Self struct {
|
||||
AuthorityID string `json:"AuthorityId"`
|
||||
Path string `json:"Path"`
|
||||
QueryString string `json:"QueryString"`
|
||||
RetryPolicyID string `json:"RetryPolicyId"`
|
||||
TopicName string `json:"TopicName"`
|
||||
AcknowledgementTypeID int `json:"AcknowledgementTypeId"`
|
||||
AuthenticationLifetimeExtensionSupported bool `json:"AuthenticationLifetimeExtensionSupported"`
|
||||
} `json:"Self"`
|
||||
} `json:"Links"`
|
||||
}
|
||||
|
||||
func EventsForMatch(baseurl, title, matchid string) []byte {
|
||||
verifyValidID(matchid, "Match ID")
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/matches/%s/events", baseurl, title, matchid))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func MatchesForPlayer(baseurl, title, player, modes string, start, count int) []byte {
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/players/%s/matches", baseurl, title, player))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
|
||||
if modes != "" {
|
||||
q.Set("modes", modes)
|
||||
}
|
||||
if start != 0 {
|
||||
q.Set("start", string(start))
|
||||
}
|
||||
if count != 0 {
|
||||
q.Set("count", string(count))
|
||||
}
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func PlayerLeaderboard(baseurl, title, seasonid, playlistid string, count int) []byte {
|
||||
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)
|
||||
q := url.Query()
|
||||
|
||||
if count != 0 {
|
||||
q.Set("count", string(count))
|
||||
}
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func CarnageReportArena(baseurl, title, matchid string) []byte {
|
||||
verifyValidID(matchid, "Match ID")
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/arena/matches/%s", baseurl, title, matchid))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func CarnageReportCampaign(baseurl, title, matchid string) []byte {
|
||||
verifyValidID(matchid, "Match ID")
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/campaign/matches/%s", baseurl, title, matchid))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func CarnageReportCustom(baseurl, title, matchid string) []byte {
|
||||
verifyValidID(matchid, "Match ID")
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/custom/matches/%s", baseurl, title, matchid))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func CarnageReportWarzone(baseurl, title, matchid string) []byte {
|
||||
verifyValidID(matchid, "Match ID")
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/warzone/matches/%s", baseurl, title, matchid))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func ServiceRecordArena(baseurl, title, players, seasonid string) []byte {
|
||||
verifyValidID(seasonid, "Season ID")
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/arena", baseurl, title))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
q.Set("players", players)
|
||||
if seasonid != "" {
|
||||
q.Set("seasonId", seasonid)
|
||||
}
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func ServiceRecordCampaign(baseurl, title, players string) []byte {
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/campaign", baseurl, title))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
q.Set("players", players)
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func ServiceRecordCustom(baseurl, title, players string) []byte {
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/custom", baseurl, title))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
q.Set("players", players)
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
||||
|
||||
func ServiceRecordWarzone(baseurl, title, players string) []byte {
|
||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/warzone", baseurl, title))
|
||||
checkErr(err)
|
||||
q := url.Query()
|
||||
q.Set("players", players)
|
||||
url.RawQuery = q.Encode()
|
||||
response := sendRequest(url.String())
|
||||
return response
|
||||
}
|
1609
halo/structs.go
Normal file
1609
halo/structs.go
Normal file
File diff suppressed because it is too large
Load Diff
71
main.go
71
main.go
@ -6,19 +6,68 @@ 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 sampleArenaMatchID string = "f15986a8-1132-48d7-9194-e23388ec6084"
|
||||
var sampleCampaignMatchID string = "f9d5a884-68a5-4e01-a9cc-92239787559f"
|
||||
var sampleCustomMatchID string = "5e0985de-309c-4031-8133-fea03500fd1b"
|
||||
var sampleWarzoneMatchID 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 sampleGameVariantID string = "963ca478-369a-4a37-97e3-432fa13035e1" //Slayer
|
||||
var sampleMapVariantsID string = "a44373ee-9f63-4733-befd-5cd8fbb1b44a" //Truth
|
||||
var sampleRequisitionPacksID string = "d10141cb-68a5-4c6b-af38-4e4935f973f7"
|
||||
var sampleRequisitionID string = "e4f549b2-90af-4dab-b2bc-11a46ea44103"
|
||||
var samplePlayers string = "motta13,smoke721"
|
||||
|
||||
func main() {
|
||||
// Uncomment any of the below for sample output.
|
||||
|
||||
// Metadata
|
||||
//fmt.Println(halo.CampaignMissions(baseurl, title))
|
||||
//fmt.Println(halo.Commendations(baseurl, title))
|
||||
//fmt.Println(halo.CsrDesignations(baseurl, title))
|
||||
//fmt.Println(string(halo.Enemies(baseurl, title)))
|
||||
//fmt.Println(string(halo.FlexibleStats(baseurl, title)))
|
||||
//fmt.Println(string(halo.GameBaseVariants(baseurl, title)))
|
||||
//fmt.Println(string(halo.GameVariants(baseurl, title)))
|
||||
//fmt.Println(string(halo.Impulses(baseurl, title)))
|
||||
//fmt.Println(string(halo.MapVariants(baseurl, title)))
|
||||
//fmt.Println(string(halo.Maps(baseurl, title)))
|
||||
//fmt.Println(string(halo.Medals(baseurl, title)))
|
||||
//fmt.Println(string(halo.Playlists(baseurl, title)))
|
||||
//fmt.Println(string(halo.RequisitionPacks(baseurl, title)))
|
||||
//fmt.Println(string(halo.Requisitions(baseurl, title)))
|
||||
//fmt.Println(string(halo.Seasons(baseurl, title)))
|
||||
//fmt.Println(string(halo.Sculls(baseurl, title)))
|
||||
//fmt.Println(string(halo.SpartanRanks(baseurl, title)))
|
||||
//fmt.Println(string(halo.TeamColors(baseurl, title)))
|
||||
//fmt.Println(string(halo.Vehicles(baseurl, title)))
|
||||
//fmt.Println(string(halo.Weapons(baseurl, title)))
|
||||
|
||||
//ioutil.WriteFile("tmp/Enemies.txt", halo.Enemies(baseurl, title), 0755)
|
||||
//ioutil.WriteFile("tmp/FlexibleStats.txt", halo.FlexibleStats(baseurl, title), 0755)
|
||||
//ioutil.WriteFile("tmp/GameBaseVariants.txt", halo.GameBaseVariants(baseurl, title), 0755)
|
||||
//ioutil.WriteFile("tmp/GameVariants.txt", halo.GameVariants(baseurl, title, sampleGameVariantID), 0755)
|
||||
//ioutil.WriteFile("tmp/Impulses.txt", halo.Impulses(baseurl, title), 0755)
|
||||
//ioutil.WriteFile("tmp/MapVariants.txt", halo.MapVariants(baseurl, title, sampleMapVariantsID), 0755)
|
||||
//ioutil.WriteFile("tmp/Maps.txt", halo.Maps(baseurl, title), 0755)
|
||||
//ioutil.WriteFile("tmp/Medals.txt", halo.Medals(baseurl, title), 0755)
|
||||
//ioutil.WriteFile("tmp/Playlists.txt", halo.Playlists(baseurl, title), 0755)
|
||||
//fmt.Println("Sleeping")
|
||||
//time.Sleep(10 * time.Second)
|
||||
//ioutil.WriteFile("tmp/RequisitionPacks.txt", halo.RequisitionPacks(baseurl, title, sampleRequisitionPacksID), 0755)
|
||||
//ioutil.WriteFile("tmp/Requisitions.txt", halo.Requisitions(baseurl, title, sampleRequisitionID), 0755)
|
||||
//ioutil.WriteFile("tmp/Seasons.txt", halo.Seasons(baseurl, title), 0755)
|
||||
//ioutil.WriteFile("tmp/Skulls.txt", halo.Skulls(baseurl, title), 0755)
|
||||
//ioutil.WriteFile("tmp/SpartanRanks.txt", halo.SpartanRanks(baseurl, title), 0755)
|
||||
//ioutil.WriteFile("tmp/TeamColors.txt", halo.TeamColors(baseurl, title), 0755)
|
||||
//ioutil.WriteFile("tmp/Vehicles.txt", halo.Vehicles(baseurl, title), 0755)
|
||||
//ioutil.WriteFile("tmp/Weapons.txt", halo.Weapons(baseurl, title), 0755)
|
||||
|
||||
// Matches For Player
|
||||
//fmt.Println(string(halo.MatchesForPlayer(baseurl, title, sampleGamertag, "warzone", 0, 0)))
|
||||
|
||||
// Events For Match
|
||||
//fmt.Println(string(halo.EventsForMatch(baseurl, title, sampleMatchID)))
|
||||
//fmt.Println(string(halo.EventsForMatch(baseurl, title, sampleArenaMatchID)))
|
||||
|
||||
// Player Leaderboards
|
||||
//fmt.Println(string(halo.PlayerLeaderboard(baseurl, title, sampleSeasonID, samplePlaylistID, 0)))
|
||||
@ -26,9 +75,21 @@ func main() {
|
||||
// Service Record: Arena
|
||||
//fmt.Println(string(halo.ServiceRecordArena(baseurl, title, samplePlayers, sampleSeasonID)))
|
||||
|
||||
// Vehicles
|
||||
//fmt.Println(string(halo.Vehicles(baseurl, title)))
|
||||
|
||||
// Spartan Image
|
||||
//fmt.Println(string(halo.SpartanImage(baseurl, title, sampleGamertag, 0, "")))
|
||||
|
||||
// ioutil.WriteFile("tmp/EventsForMatch.txt", halo.EventsForMatch(baseurl, title, sampleArenaMatchID), 0755)
|
||||
// ioutil.WriteFile("tmp/MatchesForPlayer.txt", halo.MatchesForPlayer(baseurl, title, sampleGamertag, "", 0, 0), 0755)
|
||||
// ioutil.WriteFile("tmp/PlayerLeaderboard.txt", halo.PlayerLeaderboard(baseurl, title, sampleSeasonID, samplePlaylistID, 0), 0755)
|
||||
// ioutil.WriteFile("tmp/CarnageReportArena.txt", halo.CarnageReportArena(baseurl, title, sampleArenaMatchID), 0755)
|
||||
// ioutil.WriteFile("tmp/CarnageReportCampaign.txt", halo.CarnageReportCampaign(baseurl, title, sampleCampaignMatchID), 0755)
|
||||
// ioutil.WriteFile("tmp/CarnageReportCustom.txt", halo.CarnageReportCustom(baseurl, title, sampleCustomMatchID), 0755)
|
||||
// ioutil.WriteFile("tmp/CarnageReportWarzone.txt", halo.CarnageReportWarzone(baseurl, title, sampleWarzoneMatchID), 0755)
|
||||
// fmt.Println("Sleeping")
|
||||
// time.Sleep(10 * time.Second)
|
||||
// ioutil.WriteFile("tmp/ServiceRecordArena.txt", halo.ServiceRecordArena(baseurl, title, samplePlayers, sampleSeasonID), 0755)
|
||||
// ioutil.WriteFile("tmp/ServiceRecordCampaign.txt", halo.ServiceRecordCampaign(baseurl, title, samplePlayers), 0755)
|
||||
// ioutil.WriteFile("tmp/ServiceRecordCustom.txt", halo.ServiceRecordCustom(baseurl, title, samplePlayers), 0755)
|
||||
// ioutil.WriteFile("tmp/ServiceRecordWarzone.txt", halo.ServiceRecordWarzone(baseurl, title, samplePlayers), 0755)
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user