@@ -10,6 +10,33 @@ import (
1010 "github.com/gin-gonic/gin"
1111)
1212
13+ // Child of Highscores
14+ type Highscore struct {
15+ Rank int `json:"rank"` // Rank column
16+ Name string `json:"name"` // Name column
17+ Vocation string `json:"vocation"` // Vocation column
18+ World string `json:"world"` // World column
19+ Level int `json:"level"` // Level column
20+ Value int `json:"value"` // Points/SkillLevel column
21+ Title string `json:"title,omitempty"` // Title column (when category: loyalty)
22+ }
23+
24+ // Child of JSONData
25+ type Highscores struct {
26+ World string `json:"world"`
27+ Category string `json:"category"`
28+ Vocation string `json:"vocation"`
29+ HighscoreAge int `json:"highscore_age"`
30+ HighscoreList []Highscore `json:"highscore_list"`
31+ }
32+
33+ //
34+ // The base includes two levels: Highscores and Information
35+ type HighscoresResponse struct {
36+ Highscores Highscores `json:"highscores"`
37+ Information Information `json:"information"`
38+ }
39+
1340var (
1441 HighscoresAgeRegex = regexp .MustCompile (`.*<div class="Text">Highscores.*Last Update: ([0-9]+) minutes ago.*` )
1542 SevenColumnRegex = regexp .MustCompile (`<td>.*<\/td><td.*">(.*)<\/a><\/td><td.*>(.*)<\/td><td.*>(.*)<\/td><td>(.*)<\/td><td.*>(.*)<\/td><td.*>(.*)<\/td>` )
1845
1946// TibiaHighscoresV3 func
2047func TibiaHighscoresV3 (c * gin.Context ) {
21-
2248 // getting params from URL
2349 world := c .Param ("world" )
2450 category := c .Param ("category" )
@@ -27,33 +53,6 @@ func TibiaHighscoresV3(c *gin.Context) {
2753 // do some validation of category and vocation
2854 // maybe return error on faulty value?!
2955
30- // Child of Highscores
31- type Highscore struct {
32- Rank int `json:"rank"` // Rank column
33- Name string `json:"name"` // Name column
34- Vocation string `json:"vocation"` // Vocation column
35- World string `json:"world"` // World column
36- Level int `json:"level"` // Level column
37- Value int `json:"value"` // Points/SkillLevel column
38- Title string `json:"title,omitempty"` // Title column (when category: loyalty)
39- }
40-
41- // Child of JSONData
42- type Highscores struct {
43- World string `json:"world"`
44- Category string `json:"category"`
45- Vocation string `json:"vocation"`
46- HighscoreAge int `json:"highscore_age"`
47- HighscoreList []Highscore `json:"highscore_list"`
48- }
49-
50- //
51- // The base includes two levels: Highscores and Information
52- type JSONData struct {
53- Highscores Highscores `json:"highscores"`
54- Information Information `json:"information"`
55- }
56-
5756 // Adding fix for First letter to be upper and rest lower
5857 if strings .EqualFold (world , "all" ) {
5958 world = ""
@@ -125,6 +124,13 @@ func TibiaHighscoresV3(c *gin.Context) {
125124 return
126125 }
127126
127+ jsonData := TibiaHighscoresV3Impl (world , category , vocationName , BoxContentHTML )
128+
129+ // return jsonData
130+ TibiaDataAPIHandleSuccessResponse (c , "TibiaHighscoresV3" , jsonData )
131+ }
132+
133+ func TibiaHighscoresV3Impl (world string , category string , vocationName string , BoxContentHTML string ) HighscoresResponse {
128134 // Loading HTML data into ReaderHTML for goquery with NewReader
129135 ReaderHTML , err := goquery .NewDocumentFromReader (strings .NewReader (BoxContentHTML ))
130136 if err != nil {
@@ -226,7 +232,7 @@ func TibiaHighscoresV3(c *gin.Context) {
226232
227233 //
228234 // Build the data-blob
229- jsonData := JSONData {
235+ return HighscoresResponse {
230236 Highscores {
231237 World : strings .Title (strings .ToLower (world )),
232238 Category : category ,
@@ -239,7 +245,4 @@ func TibiaHighscoresV3(c *gin.Context) {
239245 Timestamp : TibiadataDatetimeV3 ("" ),
240246 },
241247 }
242-
243- // return jsonData
244- TibiaDataAPIHandleSuccessResponse (c , "TibiaHighscoresV3" , jsonData )
245248}
0 commit comments