This repository has been archived by the owner on Jul 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tankopedia.go
87 lines (71 loc) · 1.68 KB
/
tankopedia.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
package gotanking
import (
"bytes"
"encoding/json"
"net/http"
"net/url"
)
// Arena represents data from the encyclopedia/arenas endpoint
type Arena struct {
Data map[string]ArenaRecord `json:"data"`
}
// ArenaRecord represents a single arena record
type ArenaRecord struct {
Name string `json:"name_i18n"`
Camo string `json:"camouflage_type"`
Desc string `json:"description"`
ID string `json:"arena_id"`
}
// MapInput holds display filters
type MapInput struct {
// Fields you want displayed. Valid fields are:
//
// * name_i18n
// * description
// * camouflage_type
Fields []string
// Language in which you want the results. Valid values are:
//
// "en" — English (by default)
// "ru" — Русский
// "pl" — Polski
// "de" — Deutsch
// "fr" — Français
// "es" — Español
// "zh-cn" — 简体中文
// "zh-tw" — 繁體中文
// "tr" — Türkçe
// "cs" — Čeština
// "th" — ไทย
// "vi" — Tiếng Việt
// "ko" — 한국어
Language string
}
// ListMaps queries the encyclopedia/arenas endpoint
func (c *WOTClient) ListMaps(input *MapInput) (*Arena, error) {
endpoint := "/encyclopedia/arenas/"
arenas := Arena{}
v := url.Values{}
v.Set("application_id", c.ApplicationID)
if input != nil {
// encode URL
v.Set("language", input.Language)
var fields string
for _, i := range input.Fields {
fields = fields + "," + i
}
v.Set("fields", fields)
}
resp, err := http.Get(c.baseURL + endpoint + "?" + v.Encode())
if err != nil {
return &arenas, err
}
body := new(bytes.Buffer)
body.ReadFrom(resp.Body)
b := body.Bytes()
err = json.Unmarshal(b, &arenas)
if err != nil {
return &arenas, err
}
return &arenas, nil
}