Initial commit

This commit is contained in:
Tyler 2017-05-08 22:32:00 -04:00
commit 27630f0137
2 changed files with 99 additions and 0 deletions

35
ovrstat.go Normal file
View File

@ -0,0 +1,35 @@
package ovrstat
import (
"strings"
"encoding/json"
"net/http"
"fmt"
)
type OvrStatApi struct {
Client *http.Client
URL string
}
func New(apiUrl string) {
return &OvrStatApi{Client: &http.Client{}, URL: apiUrl}
}
func (s *OvrStatApi) Fetch(region, platform, battletag string) (*OverstatApiResponse, error) {
res, err := s.Client.Get(fmt.Sprintf("%s/v1/stats/%s/%s/%s", s.URL, region, platform, strings.Replace(battletag, "#", "-", -1)))
if err != nil {
return nil, err
}
defer res.Body.Close()
var r OverstatApiResponse
if err := json.NewDecoder(res.Body).Decode(&r); err != nil {
return nil, err
}
return &r, nil
}

64
structs.go Normal file
View File

@ -0,0 +1,64 @@
package ovrstat
type OverstatApiResponse struct {
Icon string `json:"icon"`
Name string `json:"name"`
Level int `json:"level"`
LevelIcon string `json:"levelIcon"`
Prestige int `json:"prestige"`
PrestigeIcon string `json:"prestigeIcon"`
Rating string `json:"rating"`
RatingIcon string `json:"ratingIcon"`
GamesWon int `json:"gamesWon"`
QuickPlayStats *GameplayStats `json:"quickPlayStats"`
CompetitiveStats *GameplayStats `json:"competitiveStats"`
}
type GameplayStats struct {
EliminationsAvg float64 `json:"eliminationsAvg"`
DamageDoneAvg int `json:"damageDoneAvg"`
DeathsAvg float64 `json:"deathsAvg"`
FinalBlowsAvg float64 `json:"finalBlowsAvg"`
HealingDoneAvg int `json:"healingDoneAvg"`
ObjectiveKillsAvg float64 `json:"objectiveKillsAvg"`
ObjectiveTimeAvg string `json:"objectiveTimeAvg"`
SoloKillsAvg float64 `json:"soloKillsAvg"`
TopHeroes *TopHeroStats `json:"topHeros"`
}
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 HeroStat struct {
TimePlayed string `json:"timePlayed"`
GamesWon int `json:"gamesWon"`
WinPercentage int `json:"winPercentage"`
WeaponAccuracy int `json:"weaponAccuracy"`
EliminationsPerLife int `json:"eliminationsPerLife"`
MultiKillBest int `json:"multiKillBest"`
ObjectiveKillsAvg float64 `json:"objectiveKillsAvg"`
}