@@ -49,10 +49,16 @@ local EndpointType = {
49
49
--- @field name string
50
50
--- @field fallbackVersion integer
51
51
--- @field endpointType EndpointType
52
+ --- @field supportedVersion ? integer
52
53
--- @field baseAPIPath ? string
53
54
--- @field league_filter ? boolean
54
55
--- @field gem_filter ? boolean
55
56
57
+ --- Build version 1 Filter option
58
+ --- @class BuildVersion1Filter
59
+ --- @field league string
60
+ --- @field gem string
61
+
56
62
--- This primarily exists for the lua language server
57
63
--- @param buildInfo BuildInfo
58
64
--- @param source APICapabilities
@@ -67,6 +73,25 @@ local function buildInfoToCache(buildInfo, source)
67
73
}
68
74
end
69
75
76
+ --- @param t table
77
+ local function tableToQueryParams (t )
78
+ if # t == 0 then
79
+ return " "
80
+ end
81
+ local query = " ?"
82
+ for key , value in pairs (t ) do
83
+ if value then
84
+ query = query .. key .. " =" .. value .. " &"
85
+ end
86
+ end
87
+ -- remove trailing &
88
+ if # t > 0 then
89
+ query = query :sub (1 , # query - 1 )
90
+ end
91
+
92
+ return query
93
+ end
94
+
70
95
--- @class APIContractBuilds
71
96
--- @field buildList table<string,BuildInfoCache>
72
97
--- @field apiCapabilities table<string , APICapabilities>
@@ -81,11 +106,36 @@ local APIContractBuilds = newClass("APIContractBuilds",
81
106
local getBuildVersions = {
82
107
[0 ] = function (...) return APIContractBuilds :GetBuildsVersion1 (... ) end ,
83
108
}
109
+ -- Switch case for GET Endpoint for Builds
110
+ local getBuildFilterVersions = {
111
+ [0 ] = function (data ) return APIContractBuilds :GetBuildVersion1Filter (data ) end ,
112
+ }
113
+
114
+ --- @param data table
115
+ function APIContractBuilds :GetBuildVersion1Filter (data )
116
+ return {
117
+ league = data .league ,
118
+ gem = data .gem
119
+ }
120
+ end
84
121
85
122
--- Gets the builds from the source
86
- --- @param source APISourceInfo
87
- function APIContractBuilds :GetBuilds (source )
88
- getBuildVersions [source .fallbackVersion ](source .endpointType )
123
+ --- @param source APICapabilities
124
+ --- @param data table
125
+ function APIContractBuilds :GetBuilds (source , data )
126
+ local getBuildsFunction = nil
127
+ local getBuildsFilterFunction = nil
128
+ if not source .supportedVersion then
129
+ getBuildsFunction = getBuildVersions [source .fallbackVersion ]
130
+ getBuildsFilterFunction = getBuildFilterVersions [source .fallbackVersion ]
131
+ else
132
+ getBuildsFunction = getBuildVersions [source .supportedVersion ]
133
+ getBuildsFilterFunction = getBuildFilterVersions [source .supportedVersion ]
134
+ end
135
+
136
+ if getBuildsFunction and getBuildsFilterFunction then
137
+ getBuildsFunction (source .endpointType , getBuildsFilterFunction (data ), source )
138
+ end
89
139
end
90
140
91
141
--- @param source APISourceInfo
@@ -136,13 +186,14 @@ end
136
186
137
187
--- Version 1 of the API Contract for Builds
138
188
--- @param source APICapabilities
139
- function APIContractBuilds :GetBuildsVersion1 (source )
189
+ --- @param params BuildVersion1Filter
190
+ function APIContractBuilds :GetBuildsVersion1 (source , params )
140
191
if source .endpointType == EndpointType .CSV then
141
192
-- TODO: Implement CSV Parsing and Format
142
193
return
143
194
end
144
195
145
- launch :DownloadPage (source .baseAPIPath + " /v1/builds" , function (...)
196
+ launch :DownloadPage (source .baseAPIPath .. " /v1/builds" .. tableToQueryParams ( params ) , function (...)
146
197
self :BuildsVersion1Callback (source , ... )
147
198
end , {})
148
199
end
0 commit comments