@@ -21,7 +21,7 @@ local EndpointType = {
21
21
-- {"baseUrl": "https://mypoebuilds.gg/pob-builds.csv", "name": "MyPoEBuilds CSV", "endpointType": 1, "fallbackVersion": 1}
22
22
-- baseUrl means here the full URL to the actual file or endpoint that returns a CSV formatted file from a GET endpoint
23
23
24
- --- This is the required information from the enduser
24
+ --- APISourceInfo is the configurated data for a source from the enduser
25
25
--- @class APISourceInfo
26
26
--- @field name string
27
27
--- @field baseUrl string
@@ -43,9 +43,18 @@ local EndpointType = {
43
43
--- @field buildId string
44
44
--- @field sourceName string
45
45
46
+ --- API Capabilities returned by the source or defaulted to APISourceInfo
47
+ --- @class APICapabilities
48
+ --- @field name string
49
+ --- @field fallbackVersion integer
50
+ --- @field endpointType EndpointType
51
+ --- @field baseAPIPath string
52
+ --- @field league_filter boolean
53
+ --- @field gem_filter boolean
54
+
46
55
--- This primarily exists for the lua language server
47
56
--- @param buildInfo BuildInfo
48
- --- @param source APISourceInfo
57
+ --- @param source APICapabilities
49
58
--- @return BuildInfoCache
50
59
local function buildInfoToCache (buildInfo , source )
51
60
return {
@@ -58,10 +67,12 @@ local function buildInfoToCache(buildInfo, source)
58
67
end
59
68
60
69
--- @class APIContractBuilds
61
- --- @field buildList BuildInfoCache[]
70
+ --- @field buildList table<string,BuildInfoCache>
71
+ --- @field apiCapabilities table<string , APICapabilities>
62
72
local APIContractBuilds = newClass (" APIContractBuilds" ,
63
73
function (self )
64
74
self .buildList = {}
75
+ self .apiCapabilities = {}
65
76
end
66
77
)
67
78
@@ -83,13 +94,38 @@ function APIContractBuilds:GetAPICapabilities(source)
83
94
-- What is the latest version that is supported?
84
95
-- Which endpoints are supported
85
96
-- Is Querying supported? (CSV won't support this probably)
97
+
98
+ if source .endpointType ~= EndpointType .REST then
99
+ return
100
+ end
101
+
102
+ launch :DownloadPage (source .baseUrl + " /.well-known/pathofbuilding" ,
103
+ function (...) return APIContractBuilds :APICapabilitiesCallback (source , ... ) end , {})
86
104
end
87
105
88
- --- @param response table | BuildInfo[]
106
+ --- @param response table
89
107
--- @param errMsg any
90
108
--- @param source APISourceInfo
109
+ function APIContractBuilds :APICapabilitiesCallback (source , response , errMsg )
110
+ local parsedResponse = dkjson .decode (response .body )
111
+ --- @cast parsedResponse APICapabilities
112
+ if errMsg or not parsedResponse .baseAPIPath then
113
+ parsedResponse .baseAPIPath = source .baseUrl
114
+ end
115
+ parsedResponse .name = source .name
116
+ parsedResponse .fallbackVersion = source .fallbackVersion
117
+ parsedResponse .endpointType = source .endpointType
118
+
119
+ self .apiCapabilities [source .name ] = parsedResponse
120
+ end
121
+
122
+ --- @param response table
123
+ --- @param errMsg any
124
+ --- @param source APICapabilities
91
125
function APIContractBuilds :BuildsVersion1Callback (source , response , errMsg )
92
- for _ , build in ipairs (response ) do
126
+ local parsedResponse = dkjson .decode (response .body )
127
+ --- @cast parsedResponse BuildInfo[]
128
+ for _ , build in ipairs (parsedResponse ) do
93
129
-- source and buildId will be used as a caching key
94
130
-- to avoid buildId collissions
95
131
self .buildList [common .sha1 (source .name + " -" + build .buildId )] = buildInfoToCache (build , source )
98
134
99
135
--- Version 1 of the API Contract for Builds
100
136
--- @param path string
101
- --- @param source APISourceInfo
137
+ --- @param source APICapabilities
102
138
function APIContractBuilds :GetBuildsVersion1 (path , source )
103
- if source .endpointType == EndpointType .REST then
104
- launch :DownloadPage (source .baseUrl + path , function (...)
105
- self :BuildsVersion1Callback (source , ... )
106
- end , {})
139
+ if source .endpointType ~= EndpointType .REST then
140
+ return
107
141
end
142
+
143
+ launch :DownloadPage (source .baseAPIPath + path , function (...)
144
+ self :BuildsVersion1Callback (source , ... )
145
+ end , {})
108
146
end
0 commit comments