From 1c339ec1a0daf3539a7a540bc240639233541780 Mon Sep 17 00:00:00 2001 From: derek mcquay Date: Tue, 10 May 2016 21:30:18 -0700 Subject: [PATCH] code reorg to leverage methods instead of function moved all metadata.go function calls into method calls for the Halo struct. This will make it easier to encapsulate baseurl, apikey, blah blah, and also makes the code a little bit more readable. Stats.go and profile.go are to follow. Still need to implement http.Client interface and look over the code in go-halo5-api.go. Most likely needs to break out and be cleaned up --- halo/go-halo5-api.go | 33 +++- halo/halo.go | 16 ++ halo/metadata.go | 355 +++++++++++++++++++++++++++---------------- halo/stats.go | 115 -------------- halo/structs.go | 76 ++++++++- main.go | 36 +++++ 6 files changed, 373 insertions(+), 258 deletions(-) create mode 100644 halo/halo.go diff --git a/halo/go-halo5-api.go b/halo/go-halo5-api.go index 2468f7f..0898e3e 100644 --- a/halo/go-halo5-api.go +++ b/halo/go-halo5-api.go @@ -16,13 +16,36 @@ func checkErr(err error) { } } -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) +func (h *Halo) metadataRequest(datatype, id string) ([]byte, error) { + url, err := url.Parse(fmt.Sprintf("%s/metadata/%s/metadata/%s/%s", h.baseurl, h.title, datatype, id)) + if err != nil { + return nil, err + } q := url.Query() url.RawQuery = q.Encode() - response := sendRequest(url.String()) - return response + response := h.sendRequest(url.String()) + return response, nil +} + +func (h *Halo) sendRequest(url string) []byte { + request, err := http.NewRequest("GET", url, nil) + checkErr(err) + request.Header.Set("Ocp-Apim-Subscription-Key", h.apikey) + + response, err := http.DefaultClient.Do(request) + checkErr(err) + defer response.Body.Close() + + // Return the URL of the image for SpartanImage and EmblemImage + if url != response.Request.URL.String() { + return []byte(response.Request.URL.String()) + } + + // If its not SpartanImage or EmblemImage return the body + contents, err := ioutil.ReadAll(response.Body) + checkErr(err) + + return contents } func sendRequest(url string) []byte { diff --git a/halo/halo.go b/halo/halo.go new file mode 100644 index 0000000..235f73f --- /dev/null +++ b/halo/halo.go @@ -0,0 +1,16 @@ +package halo + +type Halo struct { + baseurl string + title string + apikey string +} + +func NewHalo(baseurl, title, apikey string) *Halo { + h := &Halo{ + baseurl: baseurl, + title: title, + apikey: apikey, + } + return h +} diff --git a/halo/metadata.go b/halo/metadata.go index eeee237..17dac41 100644 --- a/halo/metadata.go +++ b/halo/metadata.go @@ -1,183 +1,268 @@ package halo -import "encoding/json" +import ( + "encoding/json" + "fmt" + "log" +) -// 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 { +func (h *Halo) CampaignMissions() CampaignMissionsStruct { var j CampaignMissionsStruct - err := json.Unmarshal(metadataRequest(baseurl, title, "campaign-missions", ""), &j) - checkErr(err) + jsonObject, err := h.metadataRequest("campaign-missions", "") + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } return j } -func Commendations(baseurl, title string) CommendationsStruct { +func (h *Halo) Commendations() CommendationsStruct { var j CommendationsStruct - err := json.Unmarshal(metadataRequest(baseurl, title, "commendations", ""), &j) - checkErr(err) + jsonObject, err := h.metadataRequest("commendations", "") + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } return j } -func CsrDesignations(baseurl, title string) CsrDesignationsStruct { +func (h *Halo) CsrDesignations() CsrDesignationsStruct { var j CsrDesignationsStruct - err := json.Unmarshal(metadataRequest(baseurl, title, "csr-designations", ""), &j) - checkErr(err) + jsonObject, err := h.metadataRequest("csr-designations", "") + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } return j } -func Enemies(baseurl, title string) []byte { - return metadataRequest(baseurl, title, "enemies", "") +func (h *Halo) Enemies() EnemiesStruct { + var j EnemiesStruct + jsonObject, err := h.metadataRequest("enemies", "") + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } + return j } -func FlexibleStats(baseurl, title string) []byte { - return metadataRequest(baseurl, title, "flexible-stats", "") +func (h *Halo) FlexibleStats() FlexibleStatsStruct { + var j FlexibleStatsStruct + jsonObject, err := h.metadataRequest("flexible-stats", "") + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + fmt.Println("hjere") + log.Fatal("Failure to unmarshal json: ", err) + } + return j } -func GameBaseVariants(baseurl, title string) []byte { - return metadataRequest(baseurl, title, "game-base-variants", "") +func (h *Halo) GameBaseVariants() GameBaseVariantsStruct { + var j GameBaseVariantsStruct + jsonObject, err := h.metadataRequest("game-base-variants", "") + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } + return j } -func GameVariants(baseurl, title, id string) []byte { - return metadataRequest(baseurl, title, "game-variants", id) +func (h *Halo) GameVariants(id string) GameVariantsStruct { + var j GameVariantsStruct + jsonObject, err := h.metadataRequest("game-variants", id) + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } + return j } -func Impulses(baseurl, title string) []byte { - return metadataRequest(baseurl, title, "impulses", "") +func (h *Halo) Impulses() ImpulsesStruct { + var j ImpulsesStruct + jsonObject, err := h.metadataRequest("impulses", "") + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } + return j } -func MapVariants(baseurl, title, id string) []byte { - return metadataRequest(baseurl, title, "map-variants", id) +func (h *Halo) MapVariants(id string) MapVariantsStruct { + var j MapVariantsStruct + jsonObject, err := h.metadataRequest("map-variants", id) + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } + return j } -func Maps(baseurl, title string) []byte { - return metadataRequest(baseurl, title, "maps", "") +func (h *Halo) Maps() MapsStruct { + var j MapsStruct + jsonObject, err := h.metadataRequest("maps", "") + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } + return j } -func Medals(baseurl, title string) []byte { - return metadataRequest(baseurl, title, "medals", "") +func (h *Halo) Medals() MedalsStruct { + var j MedalsStruct + jsonObject, err := h.metadataRequest("medals", "") + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } + return j } -func Playlists(baseurl, title string) []byte { - return metadataRequest(baseurl, title, "playlists", "") +func (h *Halo) Playlists() PlaylistsStruct { + var j PlaylistsStruct + jsonObject, err := h.metadataRequest("playlists", "") + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } + return j } -func RequisitionPacks(baseurl, title, id string) []byte { - return metadataRequest(baseurl, title, "requisition-packs", id) +func (h *Halo) RequisitionPacks(id string) RequisitionPacksStruct { + var j RequisitionPacksStruct + jsonObject, err := h.metadataRequest("requisitions-packs", id) + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } + return j } -func Requisitions(baseurl, title, id string) []byte { - return metadataRequest(baseurl, title, "requisitions", id) +func (h *Halo) Requisitions(id string) RequisitionsStruct { + var j RequisitionsStruct + jsonObject, err := h.metadataRequest("requisitions", id) + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } + return j } -func Seasons(baseurl, title string) []byte { - return metadataRequest(baseurl, title, "seasons", "") +func (h *Halo) Seasons() SeasonsStruct { + var j SeasonsStruct + jsonObject, err := h.metadataRequest("seasons", "") + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } + return j } -func Skulls(baseurl, title string) []byte { - return metadataRequest(baseurl, title, "skulls", "") +func (h *Halo) Skulls() SkullsStruct { + var j SkullsStruct + jsonObject, err := h.metadataRequest("skulls", "") + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } + return j } -func SpartanRanks(baseurl, title string) []byte { - return metadataRequest(baseurl, title, "spartan-ranks", "") +func (h *Halo) SpartanRanks() SpartanRanksStruct { + var j SpartanRanksStruct + jsonObject, err := h.metadataRequest("spartan-ranks", "") + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } + return j } -func TeamColors(baseurl, title string) []byte { - return metadataRequest(baseurl, title, "team-colors", "") +func (h *Halo) TeamColors() TeamColorsStruct { + var j TeamColorsStruct + jsonObject, err := h.metadataRequest("team-colors", "") + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } + return j } -func Vehicles(baseurl, title string) []byte { - return metadataRequest(baseurl, title, "vehicles", "") +func (h *Halo) Vehicles() VehiclesStruct { + var j VehiclesStruct + jsonObject, err := h.metadataRequest("vehicles", "") + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } + return j } -func Weapons(baseurl, title string) []byte { - return metadataRequest(baseurl, title, "weapons", "") +func (h *Halo) Weapons() WeaponsStruct { + var j WeaponsStruct + jsonObject, err := h.metadataRequest("weapons", "") + if err != nil { + log.Fatal("MetadataRequest Failed: ", err) + } + err = json.Unmarshal(jsonObject, &j) + if err != nil { + log.Fatal("Failure to unmarshal json: ", err) + } + return j } diff --git a/halo/stats.go b/halo/stats.go index fc0d1d1..adcee53 100644 --- a/halo/stats.go +++ b/halo/stats.go @@ -3,123 +3,8 @@ 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)) diff --git a/halo/structs.go b/halo/structs.go index 5e3ef45..1f450dc 100644 --- a/halo/structs.go +++ b/halo/structs.go @@ -1,4 +1,76 @@ +package halo +import "encoding/json" + +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 CarnageReportArenaStruct struct { GameBaseVariantID string `json:"GameBaseVariantId"` @@ -615,7 +687,7 @@ type EventsForMatchStruct struct { } `json:"Links"` } -type FlexibleStatsStruct struct { +type FlexibleStatsStruct []struct { ContentID string `json:"contentId"` ID string `json:"id"` Name string `json:"name"` @@ -1722,5 +1794,3 @@ type WeaponsStruct []struct { SmallIconImageURL string `json:"smallIconImageUrl"` Type string `json:"type"` } - - diff --git a/main.go b/main.go index c982dd4..60fa7be 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,12 @@ package main +import ( + "fmt" + "os" + + "github.com/tbenz9/go-halo5-api/halo" +) + var baseurl string = "https://www.haloapi.com" var title string = "h5" @@ -18,7 +25,36 @@ var sampleRequisitionPacksID string = "d10141cb-68a5-4c6b-af38-4e4935f973f7" var sampleRequisitionID string = "e4f549b2-90af-4dab-b2bc-11a46ea44103" var samplePlayers string = "motta13,smoke721" +func getAPIKey() string { + apikey := os.Getenv("HALO_API_KEY") + if len(apikey) != 32 { + fmt.Println("Invalid API Key") + } + return apikey +} + func main() { + + h := halo.NewHalo(baseurl, title, getAPIKey()) + //fmt.Println(h.Enemies()) + //fmt.Println(h.FlexibleStats()) + //fmt.Println(h.GameBaseVariants()) + //fmt.Println(h.Impulses()) + //fmt.Println(h.Maps()) + //fmt.Println(h.Medals()) + //fmt.Println(h.Playlists()) + //fmt.Println(h.Seasons()) + //fmt.Println(h.Skulls()) + //fmt.Println(h.SpartanRanks()) + //time.Sleep(time.Second * 10) + //fmt.Println(h.TeamColors()) + //fmt.Println(h.Vehicles()) + //fmt.Println(h.Weapons()) + + //fmt.Println(h.GameVariants(sampleGameVariantID)) + //fmt.Println(h.MapVariants(sampleMapVariantsID)) + //fmt.Println(h.Requisitions(sampleRequisitionID)) + fmt.Println(h.RequisitionPacks(sampleRequisitionPacksID)) // Uncomment any of the below for sample output. // Metadata