diff --git a/ovrstat.go b/ovrstat.go index 02692ad..680fa6b 100644 --- a/ovrstat.go +++ b/ovrstat.go @@ -23,8 +23,8 @@ func New(apiUrl string) *OvrStatApi { return &OvrStatApi{Client: &http.Client{}, URL: u} } -func (s *OvrStatApi) Fetch(platform, region, battletag string) (*OverstatApiResponse, error) { - res, err := s.Client.Get(fmt.Sprintf("%s/v1/stats/%s/%s/%s", s.URL, platform, region, strings.Replace(battletag, "#", "-", -1))) +func (s *OvrStatApi) FetchProfile(platform, region, battletag string) (*OwApiResponse, error) { + res, err := s.Client.Get(fmt.Sprintf("%s/v1/stats/%s/%s/%s/profile", s.URL, platform, region, strings.Replace(battletag, "#", "-", -1))) if err != nil { return nil, err @@ -32,7 +32,25 @@ func (s *OvrStatApi) Fetch(platform, region, battletag string) (*OverstatApiResp defer res.Body.Close() - var r OverstatApiResponse + var r OwApiResponse + + if err := json.NewDecoder(res.Body).Decode(&r); err != nil { + return nil, err + } + + return &r, nil +} + +func (s *OvrStatApi) FetchHeroStats(platform, region, battletag string, heroes []string) (*OwApiResponse, error) { + res, err := s.Client.Get(fmt.Sprintf("%s/v1/stats/%s/%s/%s/heroes/%s", s.URL, platform, region, strings.Replace(battletag, "#", "-", -1), strings.Join(heroes, ","))) + + if err != nil { + return nil, err + } + + defer res.Body.Close() + + var r OwApiResponse if err := json.NewDecoder(res.Body).Decode(&r); err != nil { return nil, err diff --git a/ovrstat_test.go b/ovrstat_test.go new file mode 100644 index 0000000..55e4a01 --- /dev/null +++ b/ovrstat_test.go @@ -0,0 +1,15 @@ +package ovrstat + +import "testing" + +func TestOvrStatApi_Fetch(t *testing.T) { + api := New("https://ow-api.com") + + res, err := api.FetchHeroStats("pc", "us", "cats#11481", []string{"allHeroes"}) + + if err != nil { + t.Error(err) + } + + t.Logf("%v", res.QuickPlayStats.CareerStats.AllHeroes.Assists.HealingDone) +} \ No newline at end of file diff --git a/structs.go b/structs.go index b55b8ea..2b82538 100644 --- a/structs.go +++ b/structs.go @@ -1,6 +1,6 @@ package ovrstat -type OverstatApiResponse struct { +type OwApiResponse struct { Icon string `json:"icon"` Name string `json:"name"` Level int `json:"level"` @@ -8,6 +8,7 @@ type OverstatApiResponse struct { Prestige int `json:"prestige"` PrestigeIcon string `json:"prestigeIcon"` Rating string `json:"rating"` + RatingName string `json:"ratingName"` RatingIcon string `json:"ratingIcon"` GamesWon int `json:"gamesWon"` QuickPlayStats *GameplayStats `json:"quickPlayStats"` @@ -23,34 +24,22 @@ type GameplayStats struct { ObjectiveKillsAvg float64 `json:"objectiveKillsAvg"` ObjectiveTimeAvg string `json:"objectiveTimeAvg"` SoloKillsAvg float64 `json:"soloKillsAvg"` - TopHeroes *TopHeroStats `json:"topHeros"` + Games *GamesStats `json:"games"` + Awards *AwardsStats `json:"awards"` + CareerStats *CareerStats `json:"careerStats"` } -type TopHeroStats struct { - Ana *HeroStat `json:"ana"` - Bastion *HeroStat `json:"bastion"` - DVa *HeroStat `json:"d.Va"` - Genji *HeroStat `json:"genji"` - Hanzo *HeroStat `json:"hanzo"` - Junkrat *HeroStat `json:"junkrat"` - LCio *HeroStat `json:"lúcio"` - Mccree *HeroStat `json:"mccree"` - Mei *HeroStat `json:"mei"` - Mercy *HeroStat `json:"mercy"` - Orisa *HeroStat `json:"orisa"` - Pharah *HeroStat `json:"pharah"` - Reaper *HeroStat `json:"reaper"` - Reinhardt *HeroStat `json:"reinhardt"` - Roadhog *HeroStat `json:"roadhog"` - Soldier76 *HeroStat `json:"soldier:76"` - Sombra *HeroStat `json:"sombra"` - Symmetra *HeroStat `json:"symmetra"` - Torbjorn *HeroStat `json:"torbjörn"` - Tracer *HeroStat `json:"tracer"` - Widowmaker *HeroStat `json:"widowmaker"` - Winston *HeroStat `json:"winston"` - Zarya *HeroStat `json:"zarya"` - Zenyatta *HeroStat `json:"zenyatta"` +type GamesStats struct { + Played int `json:"played"` + Won int `json:"won"` +} + +type AwardsStats struct { + Cards int `json:"cards"` + Medals int `json:"medals"` + BronzeMedals int `json:"medalsBronze"` + SilverMedals int `json:"medalsSilver"` + GoldMedals int `json:"medalsGold"` } type HeroStat struct { @@ -61,4 +50,19 @@ type HeroStat struct { EliminationsPerLife float64 `json:"eliminationsPerLife"` MultiKillBest int `json:"multiKillBest"` ObjectiveKillsAvg float64 `json:"objectiveKillsAvg"` +} + +type CareerStats struct { + AllHeroes *CareerStat `json:"allHeroes"` +} + +type CareerStat struct { + Assists *AssistStats `json:"assists"` +} + +type AssistStats struct { + HealingDone int64 `json:"healingDone"` + OffensiveAssists int64 `json:"offensiveAssists"` + SelfHealing int64 `json:"offensiveAssists"` + TurretsDestroyed int64 `json:"turretsDestroyed"` } \ No newline at end of file