Compare commits
No commits in common. "master" and "rename" have entirely different histories.
@ -3,11 +3,19 @@ package halo
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func checkErr(err error) {
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Halo) metadataRequest(datatype, id string) ([]byte, error) {
|
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))
|
url, err := url.Parse(fmt.Sprintf("%s/metadata/%s/metadata/%s/%s", h.baseurl, h.title, datatype, id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -15,10 +23,7 @@ func (h *Halo) metadataRequest(datatype, id string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
response, err := h.sendRequest(url.String())
|
response, _ := h.sendRequest(url.String())
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,11 +39,6 @@ func (h *Halo) sendRequest(url string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
defer response.Body.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
//check for response code
|
|
||||||
if response.StatusCode != http.StatusOK {
|
|
||||||
return nil, fmt.Errorf(response.Status)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the URL of the image for SpartanImage and EmblemImage
|
// Return the URL of the image for SpartanImage and EmblemImage
|
||||||
if url != response.Request.URL.String() {
|
if url != response.Request.URL.String() {
|
||||||
return []byte(response.Request.URL.String()), nil
|
return []byte(response.Request.URL.String()), nil
|
||||||
@ -53,10 +53,39 @@ func (h *Halo) sendRequest(url string) ([]byte, error) {
|
|||||||
return contents, nil
|
return contents, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyValidID(id string) error {
|
func sendRequest(url string) []byte {
|
||||||
re, _ := regexp.Compile("^\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}$")
|
request, err := http.NewRequest("GET", url, nil)
|
||||||
if !re.MatchString(id) {
|
checkErr(err)
|
||||||
return fmt.Errorf("Not a Valid id: ", id)
|
request.Header.Set("Ocp-Apim-Subscription-Key", getAPIKey())
|
||||||
|
|
||||||
|
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 getAPIKey() string {
|
||||||
|
apikey := os.Getenv("HALO_API_KEY")
|
||||||
|
if len(apikey) != 32 {
|
||||||
|
fmt.Println("Invalid API Key")
|
||||||
|
}
|
||||||
|
return apikey
|
||||||
|
}
|
||||||
|
|
||||||
|
func verifyValidID(ID, name string) {
|
||||||
|
re, _ := regexp.Compile("^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$")
|
||||||
|
valid := re.MatchString(ID)
|
||||||
|
if valid == false {
|
||||||
|
log.Fatal("%s is not a valid %s", ID, name)
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
}
|
}
|
222
halo/metadata.go
222
halo/metadata.go
@ -3,324 +3,266 @@ package halo
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *Halo) CampaignMissions() (CampaignMissionsStruct, error) {
|
func (h *Halo) CampaignMissions() CampaignMissionsStruct {
|
||||||
var j CampaignMissionsStruct
|
var j CampaignMissionsStruct
|
||||||
jsonObject, err := h.metadataRequest("campaign-missions", "")
|
jsonObject, err := h.metadataRequest("campaign-missions", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return CampaignMissionsStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest campaign-missions Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return CampaignMissionsStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) Commendations() (CommendationsStruct, error) {
|
func (h *Halo) Commendations() CommendationsStruct {
|
||||||
var j CommendationsStruct
|
var j CommendationsStruct
|
||||||
jsonObject, err := h.metadataRequest("commendations", "")
|
jsonObject, err := h.metadataRequest("commendations", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return CommendationsStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest commendations Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return CommendationsStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) CsrDesignations() (CsrDesignationsStruct, error) {
|
func (h *Halo) CsrDesignations() CsrDesignationsStruct {
|
||||||
var j CsrDesignationsStruct
|
var j CsrDesignationsStruct
|
||||||
jsonObject, err := h.metadataRequest("csr-designations", "")
|
jsonObject, err := h.metadataRequest("csr-designations", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return CsrDesignationsStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest csr-designations Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return CsrDesignationsStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) Enemies() (EnemiesStruct, error) {
|
func (h *Halo) Enemies() EnemiesStruct {
|
||||||
var j EnemiesStruct
|
var j EnemiesStruct
|
||||||
jsonObject, err := h.metadataRequest("enemies", "")
|
jsonObject, err := h.metadataRequest("enemies", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return EnemiesStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest enemies Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return EnemiesStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) FlexibleStats() (FlexibleStatsStruct, error) {
|
func (h *Halo) FlexibleStats() FlexibleStatsStruct {
|
||||||
var j FlexibleStatsStruct
|
var j FlexibleStatsStruct
|
||||||
jsonObject, err := h.metadataRequest("flexible-stats", "")
|
jsonObject, err := h.metadataRequest("flexible-stats", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return FlexibleStatsStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest flexible-stats Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return FlexibleStatsStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
fmt.Println("hjere")
|
||||||
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) GameBaseVariants() (GameBaseVariantsStruct, error) {
|
func (h *Halo) GameBaseVariants() GameBaseVariantsStruct {
|
||||||
var j GameBaseVariantsStruct
|
var j GameBaseVariantsStruct
|
||||||
jsonObject, err := h.metadataRequest("game-base-variants", "")
|
jsonObject, err := h.metadataRequest("game-base-variants", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return GameBaseVariantsStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest game-base-variants Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return GameBaseVariantsStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) GameVariants(id string) (GameVariantsStruct, error) {
|
func (h *Halo) GameVariants(id string) GameVariantsStruct {
|
||||||
var j GameVariantsStruct
|
var j GameVariantsStruct
|
||||||
jsonObject, err := h.metadataRequest("game-variants", id)
|
jsonObject, err := h.metadataRequest("game-variants", id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return GameVariantsStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest game-variants Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return GameVariantsStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) Impulses() (ImpulsesStruct, error) {
|
func (h *Halo) Impulses() ImpulsesStruct {
|
||||||
var j ImpulsesStruct
|
var j ImpulsesStruct
|
||||||
jsonObject, err := h.metadataRequest("impulses", "")
|
jsonObject, err := h.metadataRequest("impulses", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ImpulsesStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest impulses Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ImpulsesStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) MapVariants(id string) (MapVariantsStruct, error) {
|
func (h *Halo) MapVariants(id string) MapVariantsStruct {
|
||||||
var j MapVariantsStruct
|
var j MapVariantsStruct
|
||||||
jsonObject, err := h.metadataRequest("map-variants", id)
|
jsonObject, err := h.metadataRequest("map-variants", id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MapVariantsStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest map-variants Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MapVariantsStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) Maps() (MapsStruct, error) {
|
func (h *Halo) Maps() MapsStruct {
|
||||||
var j MapsStruct
|
var j MapsStruct
|
||||||
jsonObject, err := h.metadataRequest("maps", "")
|
jsonObject, err := h.metadataRequest("maps", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MapsStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest maps Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MapsStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) Medals() (MedalsStruct, error) {
|
func (h *Halo) Medals() MedalsStruct {
|
||||||
var j MedalsStruct
|
var j MedalsStruct
|
||||||
jsonObject, err := h.metadataRequest("medals", "")
|
jsonObject, err := h.metadataRequest("medals", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MedalsStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest medals Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MedalsStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) Playlists() (PlaylistsStruct, error) {
|
func (h *Halo) Playlists() PlaylistsStruct {
|
||||||
var j PlaylistsStruct
|
var j PlaylistsStruct
|
||||||
jsonObject, err := h.metadataRequest("playlists", "")
|
jsonObject, err := h.metadataRequest("playlists", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return PlaylistsStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest playlists Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return PlaylistsStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) RequisitionPacks(id string) (RequisitionPacksStruct, error) {
|
func (h *Halo) RequisitionPacks(id string) RequisitionPacksStruct {
|
||||||
var j RequisitionPacksStruct
|
var j RequisitionPacksStruct
|
||||||
jsonObject, err := h.metadataRequest("requisition-packs", id)
|
jsonObject, err := h.metadataRequest("requisition-packs", id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return RequisitionPacksStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest requisition-packs Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return RequisitionPacksStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) Requisitions(id string) (RequisitionsStruct, error) {
|
func (h *Halo) Requisitions(id string) RequisitionsStruct {
|
||||||
var j RequisitionsStruct
|
var j RequisitionsStruct
|
||||||
jsonObject, err := h.metadataRequest("requisitions", id)
|
jsonObject, err := h.metadataRequest("requisitions", id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return RequisitionsStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest requisitions Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return RequisitionsStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) Seasons() (SeasonsStruct, error) {
|
func (h *Halo) Seasons() SeasonsStruct {
|
||||||
var j SeasonsStruct
|
var j SeasonsStruct
|
||||||
jsonObject, err := h.metadataRequest("seasons", "")
|
jsonObject, err := h.metadataRequest("seasons", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return SeasonsStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest seasons Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return SeasonsStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) Skulls() (SkullsStruct, error) {
|
func (h *Halo) Skulls() SkullsStruct {
|
||||||
var j SkullsStruct
|
var j SkullsStruct
|
||||||
jsonObject, err := h.metadataRequest("skulls", "")
|
jsonObject, err := h.metadataRequest("skulls", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return SkullsStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest skulls Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return SkullsStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) SpartanRanks() (SpartanRanksStruct, error) {
|
func (h *Halo) SpartanRanks() SpartanRanksStruct {
|
||||||
var j SpartanRanksStruct
|
var j SpartanRanksStruct
|
||||||
jsonObject, err := h.metadataRequest("spartan-ranks", "")
|
jsonObject, err := h.metadataRequest("spartan-ranks", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return SpartanRanksStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest spartan-ranks Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return SpartanRanksStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) TeamColors() (TeamColorsStruct, error) {
|
func (h *Halo) TeamColors() TeamColorsStruct {
|
||||||
var j TeamColorsStruct
|
var j TeamColorsStruct
|
||||||
jsonObject, err := h.metadataRequest("team-colors", "")
|
jsonObject, err := h.metadataRequest("team-colors", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return TeamColorsStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest team-colors Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return TeamColorsStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) Vehicles() (VehiclesStruct, error) {
|
func (h *Halo) Vehicles() VehiclesStruct {
|
||||||
var j VehiclesStruct
|
var j VehiclesStruct
|
||||||
jsonObject, err := h.metadataRequest("vehicles", "")
|
jsonObject, err := h.metadataRequest("vehicles", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return VehiclesStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest vehicles Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return VehiclesStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) Weapons() (WeaponsStruct, error) {
|
func (h *Halo) Weapons() WeaponsStruct {
|
||||||
var j WeaponsStruct
|
var j WeaponsStruct
|
||||||
jsonObject, err := h.metadataRequest("weapons", "")
|
jsonObject, err := h.metadataRequest("weapons", "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return WeaponsStruct{}, fmt.Errorf(
|
log.Fatal("MetadataRequest Failed: ", err)
|
||||||
"MetadataRequest weapons Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return WeaponsStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
@ -3,48 +3,32 @@ package halo
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *Halo) EmblemImage(player string, size int) (string, error) {
|
func EmblemImage(baseurl, title, player string, size int) []byte {
|
||||||
url, err := url.Parse(
|
url, err := url.Parse(fmt.Sprintf("%s/profile/%s/profiles/%s", baseurl, title, player))
|
||||||
fmt.Sprintf("%s/profile/%s/profiles/%s/emblem",
|
checkErr(err)
|
||||||
h.baseurl,
|
|
||||||
h.title,
|
|
||||||
player,
|
|
||||||
))
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
if (size == 95) || (size == 128) || (size == 190) || (size == 256) || (size == 512) {
|
if (size == 95) || (size == 128) || (size == 190) || (size == 256) || (size == 512) {
|
||||||
q.Set("size", strconv.Itoa(size))
|
q.Set("size", string(size))
|
||||||
}
|
}
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
response, err := h.sendRequest(url.String())
|
response := sendRequest(url.String())
|
||||||
if err != nil {
|
return response
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return string(response), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) SpartanImage(player string, size int, crop string) (string, error) {
|
func SpartanImage(baseurl, title, player string, size int, crop string) []byte {
|
||||||
url, err := url.Parse(fmt.Sprintf("%s/profile/%s/profiles/%s/spartan", h.baseurl, h.title, player))
|
url, err := url.Parse(fmt.Sprintf("%s/profile/%s/profiles/%s/spartan", baseurl, title, player))
|
||||||
if err != nil {
|
checkErr(err)
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
if (size == 95) || (size == 128) || (size == 190) || (size == 256) || (size == 512) {
|
if (size == 95) || (size == 128) || (size == 190) || (size == 256) || (size == 512) {
|
||||||
q.Set("size", strconv.Itoa(size))
|
q.Set("size", string(size))
|
||||||
}
|
}
|
||||||
if (strings.ToLower(crop) == "full") || (strings.ToLower(crop) == "portrait") {
|
if (strings.ToLower(crop) == "full") || (strings.ToLower(crop) == "portrait") {
|
||||||
q.Set("crop", crop)
|
q.Set("crop", crop)
|
||||||
}
|
}
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
response, err := h.sendRequest(url.String())
|
response := sendRequest(url.String())
|
||||||
if err != nil {
|
return response
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return string(response), nil
|
|
||||||
}
|
}
|
||||||
|
257
halo/stats.go
257
halo/stats.go
@ -3,38 +3,35 @@ package halo
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *Halo) EventsForMatch(matchid string) (EventsForMatchStruct, error) {
|
func (h *Halo) EventsForMatch(matchid string) EventsForMatchStruct {
|
||||||
err := verifyValidID(matchid)
|
verifyValidID(matchid, "Match ID")
|
||||||
var j EventsForMatchStruct
|
var j EventsForMatchStruct
|
||||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/matches/%s/events", h.baseurl, h.title, matchid))
|
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/matches/%s/events", h.baseurl, h.title, matchid))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return EventsForMatchStruct{}, err
|
log.Fatal("EventsForMatch URL Parse Failed: ", err)
|
||||||
}
|
}
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
jsonObject, err := h.sendRequest(url.String())
|
jsonObject, err := h.sendRequest(url.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return EventsForMatchStruct{}, fmt.Errorf(
|
log.Fatal("EventsForMatch Failed: ", err)
|
||||||
"EventsForMatch request Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return EventsForMatchStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) MatchesForPlayer(player, modes string, start, count int) (MatchesForPlayerStruct, error) {
|
func (h *Halo) MatchesForPlayer(player, modes string, start, count int) MatchesForPlayerStruct {
|
||||||
var j MatchesForPlayerStruct
|
var j MatchesForPlayerStruct
|
||||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/players/%s/matches", h.baseurl, h.title, player))
|
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/players/%s/matches", h.baseurl, h.title, player))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MatchesForPlayerStruct{}, err
|
log.Fatal("MatchesForPlayer URL Parse Failed: ", err)
|
||||||
}
|
}
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
|
|
||||||
@ -42,238 +39,118 @@ func (h *Halo) MatchesForPlayer(player, modes string, start, count int) (Matches
|
|||||||
q.Set("modes", modes)
|
q.Set("modes", modes)
|
||||||
}
|
}
|
||||||
if start != 0 {
|
if start != 0 {
|
||||||
q.Set("start", strconv.Itoa(start))
|
q.Set("start", string(start))
|
||||||
}
|
}
|
||||||
if count != 0 {
|
if count != 0 {
|
||||||
q.Set("count", strconv.Itoa(count))
|
q.Set("count", string(count))
|
||||||
}
|
}
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
jsonObject, err := h.sendRequest(url.String())
|
jsonObject, err := h.sendRequest(url.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MatchesForPlayerStruct{}, fmt.Errorf(
|
log.Fatal("MatchesForPlayer Failed: ", err)
|
||||||
"MatchesForPlayer request Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
err = json.Unmarshal(jsonObject, &j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return MatchesForPlayerStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
log.Fatal("Failure to unmarshal json: ", err)
|
||||||
}
|
}
|
||||||
return j, nil
|
return j
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) PlayerLeaderboard(seasonid, playlistid string, count int) (PlayerLeaderboardStruct, error) {
|
func PlayerLeaderboard(baseurl, title, seasonid, playlistid string, count int) []byte {
|
||||||
var j PlayerLeaderboardStruct
|
verifyValidID(playlistid, "Playlist ID")
|
||||||
err := verifyValidID(playlistid)
|
verifyValidID(seasonid, "Season ID")
|
||||||
err = verifyValidID(seasonid)
|
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 {
|
|
||||||
return PlayerLeaderboardStruct{}, err
|
|
||||||
}
|
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
|
|
||||||
if count != 0 {
|
if count != 0 {
|
||||||
q.Set("count", strconv.Itoa(count))
|
q.Set("count", string(count))
|
||||||
}
|
}
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
jsonObject, err := h.sendRequest(url.String())
|
response := sendRequest(url.String())
|
||||||
if err != nil {
|
return response
|
||||||
return PlayerLeaderboardStruct{}, fmt.Errorf(
|
|
||||||
"PlayerLeaderboard request Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
|
||||||
if err != nil {
|
|
||||||
return PlayerLeaderboardStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
|
||||||
}
|
|
||||||
return j, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) CarnageReportArena(matchid string) (CarnageReportArenaStruct, error) {
|
func CarnageReportArena(baseurl, title, matchid string) []byte {
|
||||||
var j CarnageReportArenaStruct
|
verifyValidID(matchid, "Match ID")
|
||||||
err := verifyValidID(matchid)
|
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 {
|
|
||||||
return CarnageReportArenaStruct{}, err
|
|
||||||
}
|
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
jsonObject, err := h.sendRequest(url.String())
|
response := sendRequest(url.String())
|
||||||
if err != nil {
|
return response
|
||||||
return CarnageReportArenaStruct{}, fmt.Errorf(
|
|
||||||
"CarnageReportArena request Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
|
||||||
if err != nil {
|
|
||||||
return CarnageReportArenaStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
|
||||||
}
|
|
||||||
return j, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) CarnageReportCampaign(matchid string) (CarnageReportCampaignStruct, error) {
|
func CarnageReportCampaign(baseurl, title, matchid string) []byte {
|
||||||
var j CarnageReportCampaignStruct
|
verifyValidID(matchid, "Match ID")
|
||||||
err := verifyValidID(matchid)
|
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 {
|
|
||||||
return CarnageReportCampaignStruct{}, err
|
|
||||||
}
|
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
jsonObject, err := h.sendRequest(url.String())
|
response := sendRequest(url.String())
|
||||||
if err != nil {
|
return response
|
||||||
return CarnageReportCampaignStruct{}, fmt.Errorf(
|
|
||||||
"CarnageReportCampaign request Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
|
||||||
if err != nil {
|
|
||||||
return CarnageReportCampaignStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
|
||||||
}
|
|
||||||
return j, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) CarnageReportCustom(matchid string) (CarnageReportCustomStruct, error) {
|
func CarnageReportCustom(baseurl, title, matchid string) []byte {
|
||||||
var j CarnageReportCustomStruct
|
verifyValidID(matchid, "Match ID")
|
||||||
err := verifyValidID(matchid)
|
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 {
|
|
||||||
return CarnageReportCustomStruct{}, err
|
|
||||||
}
|
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
jsonObject, err := h.sendRequest(url.String())
|
response := sendRequest(url.String())
|
||||||
if err != nil {
|
return response
|
||||||
return CarnageReportCustomStruct{}, fmt.Errorf(
|
|
||||||
"CarnageReportCustom request Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
|
||||||
if err != nil {
|
|
||||||
return CarnageReportCustomStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
|
||||||
}
|
|
||||||
return j, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) CarnageReportWarzone(matchid string) (CarnageReportWarzoneStruct, error) {
|
func CarnageReportWarzone(baseurl, title, matchid string) []byte {
|
||||||
var j CarnageReportWarzoneStruct
|
verifyValidID(matchid, "Match ID")
|
||||||
err := verifyValidID(matchid)
|
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 {
|
|
||||||
return CarnageReportWarzoneStruct{}, err
|
|
||||||
}
|
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
jsonObject, err := h.sendRequest(url.String())
|
response := sendRequest(url.String())
|
||||||
if err != nil {
|
return response
|
||||||
return CarnageReportWarzoneStruct{}, fmt.Errorf(
|
|
||||||
"CarnageReportWarzone request Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
|
||||||
if err != nil {
|
|
||||||
return CarnageReportWarzoneStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
|
||||||
}
|
|
||||||
return j, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) ServiceRecordArena(players, seasonid string) (ServiceRecordArenaStruct, error) {
|
func ServiceRecordArena(baseurl, title, players, seasonid string) []byte {
|
||||||
var j ServiceRecordArenaStruct
|
verifyValidID(seasonid, "Season ID")
|
||||||
err := verifyValidID(seasonid)
|
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 {
|
|
||||||
return ServiceRecordArenaStruct{}, 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()
|
||||||
jsonObject, err := h.sendRequest(url.String())
|
response := sendRequest(url.String())
|
||||||
if err != nil {
|
return response
|
||||||
return ServiceRecordArenaStruct{}, fmt.Errorf(
|
|
||||||
"ServiceRecordArena request Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
|
||||||
if err != nil {
|
|
||||||
return ServiceRecordArenaStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
|
||||||
}
|
|
||||||
return j, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) ServiceRecordCampaign(players string) (ServiceRecordCampaignStruct, error) {
|
func ServiceRecordCampaign(baseurl, title, players string) []byte {
|
||||||
var j ServiceRecordCampaignStruct
|
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/campaign", baseurl, title))
|
||||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/campaign", h.baseurl, h.title))
|
checkErr(err)
|
||||||
if err != nil {
|
|
||||||
return ServiceRecordCampaignStruct{}, err
|
|
||||||
}
|
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
q.Set("players", players)
|
q.Set("players", players)
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
jsonObject, err := h.sendRequest(url.String())
|
response := sendRequest(url.String())
|
||||||
if err != nil {
|
return response
|
||||||
return ServiceRecordCampaignStruct{}, fmt.Errorf(
|
|
||||||
"ServiceRecordCampaign request Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
|
||||||
if err != nil {
|
|
||||||
return ServiceRecordCampaignStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
|
||||||
}
|
|
||||||
return j, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) ServiceRecordCustom(players string) (ServiceRecordCustomStruct, error) {
|
func ServiceRecordCustom(baseurl, title, players string) []byte {
|
||||||
var j ServiceRecordCustomStruct
|
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/custom", baseurl, title))
|
||||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/custom", h.baseurl, h.title))
|
checkErr(err)
|
||||||
if err != nil {
|
|
||||||
return ServiceRecordCustomStruct{}, err
|
|
||||||
}
|
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
q.Set("players", players)
|
q.Set("players", players)
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
jsonObject, err := h.sendRequest(url.String())
|
response := sendRequest(url.String())
|
||||||
if err != nil {
|
return response
|
||||||
return ServiceRecordCustomStruct{}, fmt.Errorf(
|
|
||||||
"ServiceRecordCustom request Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
|
||||||
if err != nil {
|
|
||||||
return ServiceRecordCustomStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
|
||||||
}
|
|
||||||
return j, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Halo) ServiceRecordWarzone(players string) (ServiceRecordWarzoneStruct, error) {
|
func ServiceRecordWarzone(baseurl, title, players string) []byte {
|
||||||
var j ServiceRecordWarzoneStruct
|
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/warzone", baseurl, title))
|
||||||
url, err := url.Parse(fmt.Sprintf("%s/stats/%s/servicerecords/warzone", h.baseurl, h.title))
|
checkErr(err)
|
||||||
if err != nil {
|
|
||||||
return ServiceRecordWarzoneStruct{}, err
|
|
||||||
}
|
|
||||||
q := url.Query()
|
q := url.Query()
|
||||||
q.Set("players", players)
|
q.Set("players", players)
|
||||||
url.RawQuery = q.Encode()
|
url.RawQuery = q.Encode()
|
||||||
jsonObject, err := h.sendRequest(url.String())
|
response := sendRequest(url.String())
|
||||||
if err != nil {
|
return response
|
||||||
return ServiceRecordWarzoneStruct{}, fmt.Errorf(
|
|
||||||
"ServiceRecordWarzone request Failed: %v",
|
|
||||||
err,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
err = json.Unmarshal(jsonObject, &j)
|
|
||||||
if err != nil {
|
|
||||||
return ServiceRecordWarzoneStruct{}, fmt.Errorf("Failure to unmarshal json: %v", err)
|
|
||||||
}
|
|
||||||
return j, nil
|
|
||||||
}
|
}
|
||||||
|
2604
halo/structs.go
2604
halo/structs.go
File diff suppressed because it is too large
Load Diff
@ -2,10 +2,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/dmmcquay/go-halo5-api/halo"
|
"github.com/tbenz9/go-halo5-api/halo"
|
||||||
)
|
)
|
||||||
|
|
||||||
var baseurl string = "https://www.haloapi.com"
|
var baseurl string = "https://www.haloapi.com"
|
||||||
@ -21,7 +20,6 @@ var sampleWarzoneMatchID string = "c35a35f8-f450-4836-a4c2-65100a7acb79"
|
|||||||
var sampleSeasonID string = "b46c2095-4ca6-4f4b-a565-4702d7cfe586" //February 2016 Season
|
var sampleSeasonID string = "b46c2095-4ca6-4f4b-a565-4702d7cfe586" //February 2016 Season
|
||||||
var samplePlaylistID string = "2323b76a-db98-4e03-aa37-e171cfbdd1a4" //SWAT gametype 2016 Season
|
var samplePlaylistID string = "2323b76a-db98-4e03-aa37-e171cfbdd1a4" //SWAT gametype 2016 Season
|
||||||
var sampleGameVariantID string = "963ca478-369a-4a37-97e3-432fa13035e1" //Slayer
|
var sampleGameVariantID string = "963ca478-369a-4a37-97e3-432fa13035e1" //Slayer
|
||||||
var badGameVariantID string = "9aaaaaaa-369a-4a37-97e3-432fa13035e1" //Slayer
|
|
||||||
var sampleMapVariantsID string = "a44373ee-9f63-4733-befd-5cd8fbb1b44a" //Truth
|
var sampleMapVariantsID string = "a44373ee-9f63-4733-befd-5cd8fbb1b44a" //Truth
|
||||||
var sampleRequisitionPacksID string = "d10141cb-68a5-4c6b-af38-4e4935f973f7"
|
var sampleRequisitionPacksID string = "d10141cb-68a5-4c6b-af38-4e4935f973f7"
|
||||||
var sampleRequisitionID string = "e4f549b2-90af-4dab-b2bc-11a46ea44103"
|
var sampleRequisitionID string = "e4f549b2-90af-4dab-b2bc-11a46ea44103"
|
||||||
@ -38,21 +36,6 @@ func getAPIKey() string {
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
h := halo.NewHalo(baseurl, title, getAPIKey())
|
h := halo.NewHalo(baseurl, title, getAPIKey())
|
||||||
a, err := h.EmblemImage("smoke721", 512)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
fmt.Println(a)
|
|
||||||
b, err := h.SpartanImage("smoke721", 512, "full")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
fmt.Println(b)
|
|
||||||
c, err := h.SpartanImage("thisplayerdoesnotexist", 512, "full")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
fmt.Println(c)
|
|
||||||
//fmt.Println(h.Enemies())
|
//fmt.Println(h.Enemies())
|
||||||
//fmt.Println(h.FlexibleStats())
|
//fmt.Println(h.FlexibleStats())
|
||||||
//fmt.Println(h.GameBaseVariants())
|
//fmt.Println(h.GameBaseVariants())
|
||||||
@ -71,9 +54,7 @@ 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