2017-05-09 02:32:00 +00:00
|
|
|
package ovrstat
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
type OvrStatApi struct {
|
|
|
|
Client *http.Client
|
|
|
|
URL string
|
|
|
|
}
|
|
|
|
|
2017-05-09 03:06:48 +00:00
|
|
|
func New(apiUrl string) *OvrStatApi {
|
2017-05-09 02:32:00 +00:00
|
|
|
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
|
|
|
|
}
|