Skip to content

Commit 6faf828

Browse files
committed
update to use async web
1 parent cecebd8 commit 6faf828

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

source/main.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ local music = require("music")
3030

3131
local color = require("util.color")
3232
local gui = require("gui")
33-
33+
local web = require("web")
3434
local ease = require("ease")
3535

3636
local graphics = love.graphics

source/modules/stats.lua

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
local json = require("serializer.json")
2-
local http = require("socket.http")
2+
local web = require("web")
33
function grabUserStats(userCode)
44
-- userCode: 'xxx#123'
5-
local response_body = {}
6-
local request_body = {
5+
local body = json.encode({
76
operationName = "AccountManagementPageQuery",
87
variables = {
98
cc = string.format("%s", userCode),
109
uid = string.format("%s", userCode)
1110
},
1211
query = "fragment userProfilePage on User {\n fbUid\n displayName\n connectCode {\n code\n __typename\n }\n status\n activeSubscription {\n level\n hasGiftSub\n __typename\n }\n rankedNetplayProfile {\n id\n ratingOrdinal\n ratingUpdateCount\n wins\n losses\n dailyGlobalPlacement\n dailyRegionalPlacement\n continent\n characters {\n id\n character\n gameCount\n __typename\n }\n __typename\n }\n __typename\n}\n\nquery AccountManagementPageQuery($cc: String!, $uid: String!) {\n getUser(fbUid: $uid) {\n ...userProfilePage\n __typename\n }\n getConnectCode(code: $cc) {\n user {\n ...userProfilePage\n __typename\n }\n __typename\n }\n}\n"
13-
}
14-
request_body = json.encode(request_body)
15-
print(request_body)
12+
})
13+
print(body)
1614

17-
local res = http.request({
18-
url = 'https://gql-gateway-dot-slippi.uc.r.appspot.com/graphql',
19-
method = "POST",
20-
headers = {
15+
local res = web.post(
16+
'https://gql-gateway-dot-slippi.uc.r.appspot.com/graphql',
17+
body,
18+
{
2119
["Content-Type"] = "application/json",
22-
["Content-Length"] = string.len(request_body)
20+
["Content-Length"] = string.len(body)
2321
},
24-
source = ltn12.source.string(request_body),
25-
sink = ltn12.sink.table(response_body)
26-
})
27-
response_body = json.decode(response_body[1])
28-
29-
if not response_body.data or not response_body.data.getConnectCode then return {'', ''} end
30-
return {response_body.data.getConnectCode.user.displayName, math.floor(response_body.data.getConnectCode.user.rankedNetplayProfile.ratingOrdinal)}
22+
function(event)
23+
data = json.decode(event.response)
24+
if data.data and data.data.getConnectCode.user.displayName then
25+
return {data.data.getConnectCode.user.displayName, math.floor(data.data.getConnectCode.user.rankedNetplayProfile.ratingOrdinal)}
26+
end
27+
return {'', ''}
28+
end)
29+
-- if not response_body.data or not response_body.data.getConnectCode then return {'', ''} end
30+
-- return {response_body.data.getConnectCode.user.displayName, math.floor(response_body.data.getConnectCode.user.rankedNetplayProfile.ratingOrdinal)}
3131
end

0 commit comments

Comments
 (0)