-
Notifications
You must be signed in to change notification settings - Fork 2
/
api.go
49 lines (36 loc) · 863 Bytes
/
api.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
package gopubg
import (
"fmt"
"net/url"
"github.com/driquet/gopubg/models/player"
)
type API struct {
Key string
}
func NewAPI(key string) *API {
return &API{
Key: key,
}
}
func (a *API) RequestStatus() error {
endpoint_url := "https://api.playbattlegrounds.com/status"
buffer, err := httpRequest(endpoint_url, a.Key)
if err != nil {
return err
}
fmt.Printf("data:\n%s\n", buffer)
return nil
}
func (a *API) RequestSinglePlayerByName(shard, playerName string) (*player.Player, error) {
parameters := url.Values{
"filter[playerNames]": {playerName},
}
endpoint_url := fmt.Sprintf("https://api.playbattlegrounds.com/shards/%s/players?%s", shard, parameters.Encode())
buffer, err := httpRequest(endpoint_url, a.Key)
if err != nil {
return nil, err
}
fmt.Printf("data:\n%s\n", buffer)
// TODO parse player
return nil, nil
}