@@ -10,6 +10,52 @@ import (
1010 "github.com/gin-gonic/gin"
1111)
1212
13+ // Child of Fansite
14+ type ContentType struct {
15+ Statistics bool `json:"statistics"`
16+ Texts bool `json:"texts"`
17+ Tools bool `json:"tools"`
18+ Wiki bool `json:"wiki"`
19+ }
20+
21+ // Child of Fansite
22+ type SocialMedia struct {
23+ Discord bool `json:"discord"`
24+ Facebook bool `json:"facebook"`
25+ Instagram bool `json:"instagram"`
26+ Reddit bool `json:"reddit"`
27+ Twitch bool `json:"twitch"`
28+ Twitter bool `json:"twitter"`
29+ Youtube bool `json:"youtube"`
30+ }
31+
32+ // Child of Fansites
33+ type Fansite struct {
34+ Name string `json:"name"`
35+ LogoURL string `json:"logo_url"`
36+ Homepage string `json:"homepage"`
37+ Contact string `json:"contact"`
38+ ContentType ContentType `json:"content_type"`
39+ SocialMedia SocialMedia `json:"social_media"`
40+ Languages []string `json:"languages"`
41+ Specials []string `json:"specials"`
42+ FansiteItem bool `json:"fansite_item"`
43+ FansiteItemURL string `json:"fansite_item_url"`
44+ }
45+
46+ // Child of JSONData
47+ type Fansites struct {
48+ PromotedFansites []Fansite `json:"promoted"`
49+ SupportedFansites []Fansite `json:"supported"`
50+ }
51+
52+ //
53+ // The base includes two levels: Fansites and Information
54+ type FansitesResponse struct {
55+ Fansites Fansites `json:"fansites"`
56+ Information Information `json:"information"`
57+ }
58+
1359var (
1460 FansiteInformationRegex = regexp .MustCompile (`<td><a href="(.*)" target.*img .*src="(.*)" alt="(.*)"\/><\/a>.*<a href=".*">(.*)<\/a><\/td><td.*top;">(.*)<\/td><td.*top;">(.*)<\/td><td.*top;">(.*)<\/td><td.*<ul><li>(.*)<\/li><\/ul><\/td><td.*top;">(.*)<\/td>` )
1561 FansiteImgTagRegex = regexp .MustCompile (`<img[^>]+\bsrc="([^"]+)"` )
1965
2066// TibiaFansitesV3 func
2167func TibiaFansitesV3 (c * gin.Context ) {
22-
23- // Child of Fansite
24- type ContentType struct {
25- Statistics bool `json:"statistics"`
26- Texts bool `json:"texts"`
27- Tools bool `json:"tools"`
28- Wiki bool `json:"wiki"`
29- }
30- // Child of Fansite
31- type SocialMedia struct {
32- Discord bool `json:"discord"`
33- Facebook bool `json:"facebook"`
34- Instagram bool `json:"instagram"`
35- Reddit bool `json:"reddit"`
36- Twitch bool `json:"twitch"`
37- Twitter bool `json:"twitter"`
38- Youtube bool `json:"youtube"`
39- }
40-
41- // Child of Fansites
42- type Fansite struct {
43- Name string `json:"name"`
44- LogoURL string `json:"logo_url"`
45- Homepage string `json:"homepage"`
46- Contact string `json:"contact"`
47- ContentType ContentType `json:"content_type"`
48- SocialMedia SocialMedia `json:"social_media"`
49- Languages []string `json:"languages"`
50- Specials []string `json:"specials"`
51- FansiteItem bool `json:"fansite_item"`
52- FansiteItemURL string `json:"fansite_item_url"`
53- }
54-
55- // Child of JSONData
56- type Fansites struct {
57- PromotedFansites []Fansite `json:"promoted"`
58- SupportedFansites []Fansite `json:"supported"`
59- }
60-
61- //
62- // The base includes two levels: Fansites and Information
63- type JSONData struct {
64- Fansites Fansites `json:"fansites"`
65- Information Information `json:"information"`
66- }
67-
6868 // Getting data with TibiadataHTMLDataCollectorV3
6969 TibiadataRequest .URL = "https://www.tibia.com/community/?subtopic=fansites"
7070 BoxContentHTML , err := TibiadataHTMLDataCollectorV3 (TibiadataRequest )
@@ -75,6 +75,13 @@ func TibiaFansitesV3(c *gin.Context) {
7575 return
7676 }
7777
78+ jsonData := TibiaFansitesV3Impl (BoxContentHTML )
79+
80+ // return jsonData
81+ TibiaDataAPIHandleSuccessResponse (c , "TibiaFansitesV3" , jsonData )
82+ }
83+
84+ func TibiaFansitesV3Impl (BoxContentHTML string ) FansitesResponse {
7885 // Loading HTML data into ReaderHTML for goquery with NewReader
7986 ReaderHTML , err := goquery .NewDocumentFromReader (strings .NewReader (BoxContentHTML ))
8087 if err != nil {
@@ -207,9 +214,8 @@ func TibiaFansitesV3(c *gin.Context) {
207214
208215 }
209216
210- //
211217 // Build the data-blob
212- jsonData := JSONData {
218+ return FansitesResponse {
213219 Fansites {
214220 PromotedFansites : PromotedFansitesData ,
215221 SupportedFansites : SupportedFansitesData ,
@@ -219,7 +225,4 @@ func TibiaFansitesV3(c *gin.Context) {
219225 Timestamp : TibiadataDatetimeV3 ("" ),
220226 },
221227 }
222-
223- // return jsonData
224- TibiaDataAPIHandleSuccessResponse (c , "TibiaFansitesV3" , jsonData )
225228}
0 commit comments