From f837d3599a988f2b80cba67a1a9a05adb664c04b Mon Sep 17 00:00:00 2001 From: bshore Date: Tue, 1 Mar 2022 23:56:16 -0600 Subject: [PATCH] support new endopint GetGodAltAbilities --- README.md | 2 +- hirezapi/connection.go | 10 +++++----- hirezapi/game.go | 29 ++++++++++++++++++++++++----- hirezapi/hirezapi.go | 2 ++ hirezapi/matches.go | 12 ++++++------ hirezapi/misc.go | 16 ++++++++-------- hirezapi/paladins.go | 20 ++++++++++---------- hirezapi/player.go | 30 +++++++++++++++--------------- hirezapi_mock/game.go | 13 +++++++++++++ models/datatypes.go | 4 ++-- models/game.go | 11 ++++++++++- 11 files changed, 96 insertions(+), 53 deletions(-) diff --git a/README.md b/README.md index e6ba6e6..9e43366 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ func main() { client := &hirezapi.APIClient{ DeveloperID: devID, AuthKey: authKey, - BasePath: "http://api.smitegame.com/smiteapi.svc", + BasePath: "https://api.smitegame.com/smiteapi.svc", RespType: "json", } } diff --git a/hirezapi/connection.go b/hirezapi/connection.go index 9fb9733..57f2362 100644 --- a/hirezapi/connection.go +++ b/hirezapi/connection.go @@ -3,7 +3,7 @@ package hirezapi import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" "github.com/bshore/go-hirez/models" @@ -40,7 +40,7 @@ func (a *APIClient) CreateSession() error { } defer resp.Body.Close() sess := &models.Session{} - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return fmt.Errorf("error reading response: %v", err) } @@ -63,7 +63,7 @@ func (a *APIClient) TestSession() (string, error) { return "", err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return "", err } @@ -77,7 +77,7 @@ func (a *APIClient) GetHiRezServerStatus() ([]models.HiRezServerStatus, error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -93,7 +93,7 @@ func (a *APIClient) GetDataUsed() ([]models.DataUsed, error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/hirezapi/game.go b/hirezapi/game.go index 40f7d2f..e1aa714 100644 --- a/hirezapi/game.go +++ b/hirezapi/game.go @@ -2,7 +2,7 @@ package hirezapi import ( "fmt" - "io/ioutil" + "io" "github.com/bshore/go-hirez/models" "github.com/bshore/go-hirez/utils" @@ -21,7 +21,7 @@ func (a *APIClient) GetGods(langCode string) ([]models.God, error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -30,6 +30,25 @@ func (a *APIClient) GetGods(langCode string) ([]models.God, error) { return output, err } +func (a *APIClient) GetGodAltAbilities() ([]models.GodAltAbility, error) { + if !utils.IsSmitePath(a.BasePath) { + return nil, fmt.Errorf("GetGodAltAbilities(), %s", utils.NotSmiteErrMsg) + } + resp, err := a.makeRequest("getgodaltabilities", "") + if err != nil { + return nil, err + } + defer resp.Body.Close() + body, err := io.ReadAll(resp.Body) + if err != nil { + return nil, err + } + fmt.Println(string(body)) + var output []models.GodAltAbility + err = a.unmarshalResponse(body, &output) + return output, err +} + // GetGodSkins returns all available skins for a particular God. func (a *APIClient) GetGodSkins(godID int64, langCode string) ([]models.GodSkin, error) { if !utils.IsSmitePath(a.BasePath) { @@ -44,7 +63,7 @@ func (a *APIClient) GetGodSkins(godID int64, langCode string) ([]models.GodSkin, return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -67,7 +86,7 @@ func (a *APIClient) GetGodRecommendedItems(godID int64, langCode string) ([]mode return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -86,7 +105,7 @@ func (a *APIClient) GetItems(langCode string) ([]models.Item, error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/hirezapi/hirezapi.go b/hirezapi/hirezapi.go index b791f65..7c52c16 100644 --- a/hirezapi/hirezapi.go +++ b/hirezapi/hirezapi.go @@ -54,6 +54,8 @@ type HiRezAPI interface { // ===== Game Entity Related ===== // GetGods returns all Gods and their various attributes. GetGods(langCode string) ([]models.God, error) + // GetGodAltAbilities returns alt abilities for all Gods. + GetGodAltAbilities() ([]models.GodAltAbility, error) // GetGodSkins returns all available skins for a particular God. GetGodSkins(godID int64, langCode string) ([]models.GodSkin, error) // GetGodRecommendedItems returns the recommended items for a particular God. diff --git a/hirezapi/matches.go b/hirezapi/matches.go index 3edcdb0..ceb6964 100644 --- a/hirezapi/matches.go +++ b/hirezapi/matches.go @@ -2,7 +2,7 @@ package hirezapi import ( "fmt" - "io/ioutil" + "io" "strconv" "strings" @@ -16,7 +16,7 @@ func (a *APIClient) GetMatchDetails(matchID string) ([]models.MatchPlayer, error return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -35,7 +35,7 @@ func (a *APIClient) GetMatchDetailsBatch(matchIDs []string) ([]models.MatchPlaye return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -74,7 +74,7 @@ func (a *APIClient) GetMatchPlayerDetails(matchID string) ([]models.LiveMatchPla return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -96,7 +96,7 @@ func (a *APIClient) GetMatchIDsByQueue(queueID, date, hour string) ([]models.Mat return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -113,7 +113,7 @@ func (a *APIClient) GetQueueStats(player, queueID string) ([]models.PlayerGodQue return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/hirezapi/misc.go b/hirezapi/misc.go index 9eef133..2ba272a 100644 --- a/hirezapi/misc.go +++ b/hirezapi/misc.go @@ -2,7 +2,7 @@ package hirezapi import ( "fmt" - "io/ioutil" + "io" "github.com/bshore/go-hirez/models" "github.com/bshore/go-hirez/utils" @@ -15,7 +15,7 @@ func (a *APIClient) GetESportsProLeagueDetails() ([]models.ESportsProLeagueDetai return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -38,7 +38,7 @@ func (a *APIClient) GetGodLeaderboard(godID, queueID string) ([]models.GodLeader return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -61,7 +61,7 @@ func (a *APIClient) GetLeagueLeaderboard(queueID, tier, round string) ([]models. return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -83,7 +83,7 @@ func (a *APIClient) GetLeagueSeasons(queueID string) ([]models.Season, error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -99,7 +99,7 @@ func (a *APIClient) GetMOTD() ([]models.MOTD, error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -115,7 +115,7 @@ func (a *APIClient) GetTopMatches() ([]models.TopMatch, error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -131,7 +131,7 @@ func (a *APIClient) GetPatchInfo() (*models.VersionInfo, error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/hirezapi/paladins.go b/hirezapi/paladins.go index 33ae37a..4a3964e 100644 --- a/hirezapi/paladins.go +++ b/hirezapi/paladins.go @@ -2,7 +2,7 @@ package hirezapi import ( "fmt" - "io/ioutil" + "io" "strings" "github.com/bshore/go-hirez/models" @@ -22,7 +22,7 @@ func (a *APIClient) GetPlayerBatch(playerIDs []string) ([]models.Player, error) return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -41,7 +41,7 @@ func (a *APIClient) GetChampionRanks(player string) ([]models.ChampionRank, erro return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -63,7 +63,7 @@ func (a *APIClient) GetChampions(langCode string) ([]models.Champion, error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -83,7 +83,7 @@ func (a *APIClient) GetChampionLeaderboard(champID string) ([]models.ChampionLea return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -106,7 +106,7 @@ func (a *APIClient) GetChampionSkins(champID, langCode string) ([]models.Champio return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -125,7 +125,7 @@ func (a *APIClient) GetPlayerIDInfoForXBOXAndSwitch(player string) ([]models.Pla return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -148,7 +148,7 @@ func (a *APIClient) GetPlayerLoadouts(player, langCode string) ([]models.PlayerL return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -168,7 +168,7 @@ func (a *APIClient) GetChampionCards(champID, langCode string) ([]models.Champio return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -187,7 +187,7 @@ func (a *APIClient) GetBountyItems() ([]models.BountyItem, error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/hirezapi/player.go b/hirezapi/player.go index ce08775..d30cc47 100644 --- a/hirezapi/player.go +++ b/hirezapi/player.go @@ -2,7 +2,7 @@ package hirezapi import ( "fmt" - "io/ioutil" + "io" "github.com/bshore/go-hirez/models" "github.com/bshore/go-hirez/utils" @@ -15,7 +15,7 @@ func (a *APIClient) GetPlayer(player string) ([]models.Player, error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -32,7 +32,7 @@ func (a *APIClient) GetPlayerByPlatform(player, portalID string) ([]models.Playe return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -48,7 +48,7 @@ func (a *APIClient) GetPlayerIDByName(player string) ([]models.PlayerIDInfo, err return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -65,7 +65,7 @@ func (a *APIClient) GetPlayerIDByPortalUserID(portalID, portalUserID string) ([] return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -82,7 +82,7 @@ func (a *APIClient) GetPlayerIDsByGamertag(portalID, gamerTag string) ([]models. return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -98,7 +98,7 @@ func (a *APIClient) GetFriends(player string) ([]models.Friend, error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -114,7 +114,7 @@ func (a *APIClient) GetGodRanks(player string) ([]models.GodRank, error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -130,7 +130,7 @@ func (a *APIClient) GetMatchHistory(player string) ([]models.Match, error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -146,7 +146,7 @@ func (a *APIClient) GetPlayerStatus(player string) ([]models.PlayerStatus, error return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -165,7 +165,7 @@ func (a *APIClient) GetPlayerAchievements(playerID string) (*models.PlayerAchiev return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -181,7 +181,7 @@ func (a *APIClient) GetTeamDetails(clanID string) ([]models.TeamDetail, error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -197,7 +197,7 @@ func (a *APIClient) GetTeamPlayers(clanID string) ([]models.TeamPlayer, error) { return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -216,7 +216,7 @@ func (a *APIClient) SearchTeams(searchTeam string) ([]models.TeamDetail, error) return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -232,7 +232,7 @@ func (a *APIClient) SearchPlayers(searchPlayer string) ([]models.PlayerIDInfo, e return nil, err } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } diff --git a/hirezapi_mock/game.go b/hirezapi_mock/game.go index c7bc0d9..fad5730 100644 --- a/hirezapi_mock/game.go +++ b/hirezapi_mock/game.go @@ -24,6 +24,19 @@ func (a *APIClient) GetGods(langCode string) ([]models.God, error) { return output, err } +func (a *APIClient) GetGodAltAbilities() ([]models.GodAltAbility, error) { + if !utils.IsSmitePath(a.BasePath) { + return nil, fmt.Errorf("GetGodAltAbilities(), %s", utils.NotSmiteErrMsg) + } + resp, err := a.makeRequest("getgodaltabilities", "", []models.GodAltAbility{}) + if err != nil { + return nil, err + } + var output []models.GodAltAbility + err = a.unmarshalResponse(resp, &output) + return output, err +} + // GetGodSkins returns all available skins for a particular God. func (a *APIClient) GetGodSkins(godID int64, langCode string) ([]models.GodSkin, error) { if !utils.IsSmitePath(a.BasePath) { diff --git a/models/datatypes.go b/models/datatypes.go index 5a6f15c..1612c1f 100644 --- a/models/datatypes.go +++ b/models/datatypes.go @@ -4,8 +4,8 @@ package models type URL int const ( - URLSmitePC = "http://api.smitegame.com/smiteapi.svc" - URLPaladinsPC = "http://api.paladins.com/paladinsapi.svc" + URLSmitePC = "https://api.smitegame.com/smiteapi.svc" + URLPaladinsPC = "https://api.paladins.com/paladinsapi.svc" ResponseTypeJSON = "json" ResponseTypeXML = "xml" diff --git a/models/game.go b/models/game.go index e472e92..0579dac 100644 --- a/models/game.go +++ b/models/game.go @@ -70,6 +70,15 @@ type GodAbility struct { URL string `json:"URL"` } +type GodAltAbility struct { + AltName string `json:"alt_name"` + AltPosition string `json:"alt_position"` + God string `json:"God"` + GodID int64 `json:"god_id"` + ItemID int64 `json:"item_id"` + RetMsg string `json:"ret_msg"` +} + type GodBasicAttack struct { ItemDescription AbilityItemDescription `json:"itemDescription"` } @@ -145,4 +154,4 @@ type ItemDescription struct { type ItemDescriptionValueItem struct { Description string `json:"Description"` Value string `json:"value"` -} \ No newline at end of file +}