Update to use ow-api.com

This commit is contained in:
Tyler 2017-05-27 21:23:12 -04:00
parent c7cb3f5af5
commit 8d30cfdfa2
3 changed files with 67 additions and 30 deletions

View File

@ -23,8 +23,8 @@ func New(apiUrl string) *OvrStatApi {
return &OvrStatApi{Client: &http.Client{}, URL: u} return &OvrStatApi{Client: &http.Client{}, URL: u}
} }
func (s *OvrStatApi) Fetch(platform, region, battletag string) (*OverstatApiResponse, error) { func (s *OvrStatApi) FetchProfile(platform, region, battletag string) (*OwApiResponse, error) {
res, err := s.Client.Get(fmt.Sprintf("%s/v1/stats/%s/%s/%s", s.URL, platform, region, strings.Replace(battletag, "#", "-", -1))) 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 { if err != nil {
return nil, err return nil, err
@ -32,7 +32,25 @@ func (s *OvrStatApi) Fetch(platform, region, battletag string) (*OverstatApiResp
defer res.Body.Close() 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 { if err := json.NewDecoder(res.Body).Decode(&r); err != nil {
return nil, err return nil, err

15
ovrstat_test.go Normal file
View File

@ -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)
}

View File

@ -1,6 +1,6 @@
package ovrstat package ovrstat
type OverstatApiResponse struct { type OwApiResponse struct {
Icon string `json:"icon"` Icon string `json:"icon"`
Name string `json:"name"` Name string `json:"name"`
Level int `json:"level"` Level int `json:"level"`
@ -8,6 +8,7 @@ type OverstatApiResponse struct {
Prestige int `json:"prestige"` Prestige int `json:"prestige"`
PrestigeIcon string `json:"prestigeIcon"` PrestigeIcon string `json:"prestigeIcon"`
Rating string `json:"rating"` Rating string `json:"rating"`
RatingName string `json:"ratingName"`
RatingIcon string `json:"ratingIcon"` RatingIcon string `json:"ratingIcon"`
GamesWon int `json:"gamesWon"` GamesWon int `json:"gamesWon"`
QuickPlayStats *GameplayStats `json:"quickPlayStats"` QuickPlayStats *GameplayStats `json:"quickPlayStats"`
@ -23,34 +24,22 @@ type GameplayStats struct {
ObjectiveKillsAvg float64 `json:"objectiveKillsAvg"` ObjectiveKillsAvg float64 `json:"objectiveKillsAvg"`
ObjectiveTimeAvg string `json:"objectiveTimeAvg"` ObjectiveTimeAvg string `json:"objectiveTimeAvg"`
SoloKillsAvg float64 `json:"soloKillsAvg"` SoloKillsAvg float64 `json:"soloKillsAvg"`
TopHeroes *TopHeroStats `json:"topHeros"` Games *GamesStats `json:"games"`
Awards *AwardsStats `json:"awards"`
CareerStats *CareerStats `json:"careerStats"`
} }
type TopHeroStats struct { type GamesStats struct {
Ana *HeroStat `json:"ana"` Played int `json:"played"`
Bastion *HeroStat `json:"bastion"` Won int `json:"won"`
DVa *HeroStat `json:"d.Va"` }
Genji *HeroStat `json:"genji"`
Hanzo *HeroStat `json:"hanzo"` type AwardsStats struct {
Junkrat *HeroStat `json:"junkrat"` Cards int `json:"cards"`
LCio *HeroStat `json:"lúcio"` Medals int `json:"medals"`
Mccree *HeroStat `json:"mccree"` BronzeMedals int `json:"medalsBronze"`
Mei *HeroStat `json:"mei"` SilverMedals int `json:"medalsSilver"`
Mercy *HeroStat `json:"mercy"` GoldMedals int `json:"medalsGold"`
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 HeroStat struct { type HeroStat struct {
@ -61,4 +50,19 @@ type HeroStat struct {
EliminationsPerLife float64 `json:"eliminationsPerLife"` EliminationsPerLife float64 `json:"eliminationsPerLife"`
MultiKillBest int `json:"multiKillBest"` MultiKillBest int `json:"multiKillBest"`
ObjectiveKillsAvg float64 `json:"objectiveKillsAvg"` 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"`
} }