-
Notifications
You must be signed in to change notification settings - Fork 8
/
hero.go
121 lines (107 loc) · 4.1 KB
/
hero.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package opendota
import (
"net/http"
"strconv"
"github.com/dghubble/sling"
)
func newHeroService(sling *sling.Sling) *HeroService {
return &HeroService{
sling: sling.Path("heroes/"),
}
}
// HeroService provides methods for accessing information
// about heroes.
type HeroService struct {
sling *sling.Sling
}
// Hero holds a collection of data specific to a Dota 2 hero.
type Hero struct {
ID int `json:"id"`
Name string `json:"name"`
LocalizedName string `json:"localized_name"`
PrimaryAttr string `json:"primary_attr"`
AttackType string `json:"attack_type"`
Roles []string `json:"roles"`
Legs int `json:"legs"`
}
// HeroDuration represents a heroes performance over
// a range of match durations.
type HeroDuration struct {
DurationBin int `json:"duration_bin"`
GamesPlayed int `json:"games_played"`
Wins int `json:"wins"`
}
// HeroMatch represents data about a hero in a Dota 2 match.
type HeroMatch struct {
MatchID int64 `json:"match_id"`
StartTime int `json:"start_time"`
Duration int `json:"duration"`
RadiantWin bool `json:"radiant_win"`
LeagueID int `json:"leagueid"`
LeagueName string `json:"league_name"`
Radiant bool `json:"radiant"`
AccountID int `json:"account_id"`
Kills int `json:"kills"`
Deaths int `json:"deaths"`
Assists int `json:"assists"`
}
// HeroMatchup represents data about how a hero matches up against
// another hero.
type HeroMatchup struct {
HeroID int `json:"hero_id"`
GamesPlayed int `json:"games_played"`
Wins int `json:"wins"`
}
// HeroPlayer represents data about how a player performs
// on a hero.
type HeroPlayer struct {
AccountID int `json:"account_id"`
GamesPlayed int `json:"games_played"`
Wins int `json:"wins"`
}
// Durations takes a Hero ID and returns a collection of stats
// about a hero for varying match lengths.
// https://docs.opendota.com/#tag/heroes%2Fpaths%2F~1heroes~1%7Bhero_id%7D~1durations%2Fget
func (s *HeroService) Durations(heroID int) ([]HeroDuration, *http.Response, error) {
herodurations := new([]HeroDuration)
apiError := new(APIError)
path := strconv.Itoa(heroID) + "/durations"
resp, err := s.sling.New().Get(path).Receive(herodurations, apiError)
return *herodurations, resp, relevantError(err, *apiError)
}
// Heroes returns a collection of all heroes.
// https://docs.opendota.com/#tag/heroes%2Fpaths%2F~1heroes%2Fget
func (s *HeroService) Heroes() ([]Hero, *http.Response, error) {
heroes := new([]Hero)
apiError := new(APIError)
resp, err := s.sling.New().Receive(heroes, apiError)
return *heroes, resp, relevantError(err, *apiError)
}
// Matches takes a Hero ID and returns a collection of matches played by the hero.
// https://docs.opendota.com/#tag/heroes%2Fpaths%2F~1heroes~1%7Bhero_id%7D~1matches%2Fget
func (s *HeroService) Matches(heroID int) ([]HeroMatch, *http.Response, error) {
heromatches := new([]HeroMatch)
apiError := new(APIError)
path := strconv.Itoa(heroID) + "/matches"
resp, err := s.sling.New().Get(path).Receive(heromatches, apiError)
return *heromatches, resp, relevantError(err, *apiError)
}
// Matchups takes a Hero ID and returns a collection of how a hero compares
// against all other heroes.
// https://docs.opendota.com/#tag/heroes%2Fpaths%2F~1heroes~1%7Bhero_id%7D~1matchups%2Fget
func (s *HeroService) Matchups(heroID int) ([]HeroMatchup, *http.Response, error) {
heromatchups := new([]HeroMatchup)
apiError := new(APIError)
path := strconv.Itoa(heroID) + "/matchups"
resp, err := s.sling.New().Get(path).Receive(heromatchups, apiError)
return *heromatchups, resp, relevantError(err, *apiError)
}
// Players takes a Hero ID and returns a collection about players for a hero.
// https://docs.opendota.com/#tag/heroes%2Fpaths%2F~1heroes~1%7Bhero_id%7D~1players%2Fget
func (s *HeroService) Players(heroID int) ([]HeroPlayer, *http.Response, error) {
heroplayers := new([]HeroPlayer)
apiError := new(APIError)
path := strconv.Itoa(heroID) + "/players"
resp, err := s.sling.New().Get(path).Receive(heroplayers, apiError)
return *heroplayers, resp, relevantError(err, *apiError)
}