refactor url encoded form requests
This commit is contained in:
1 parent
edbfc86e56
commit
f2ffb42876
4 files changed
+33
-30
No files matched your search
@@ -99,6 +99,7 @@ class LoungeApi
|
||||
end if
|
||||
|
||||
request = HttpClient.Get("https://www.youtube.com/api/lounge/pairing/generate_screen_id")
|
||||
|
||||
response = request.Await()
|
||||
if not response.IsSuccess()
|
||||
error = `Failed to get screen id. Please restart playlet to use the cast function.\n${response.ErrorMessage()}`
|
||||
@@ -106,6 +107,7 @@ class LoungeApi
|
||||
DialogUtils.ShowDialog(error, "Lounge service setup error")
|
||||
return invalid
|
||||
end if
|
||||
|
||||
id = response.Text()
|
||||
if not IsString(id)
|
||||
error = `Failed to get screen id. Please restart playlet to use the cast function.\nNot a valid screen id: ${id}`
|
||||
@@ -113,6 +115,7 @@ class LoungeApi
|
||||
DialogUtils.ShowDialog(error, "Lounge service setup error")
|
||||
return invalid
|
||||
end if
|
||||
|
||||
m.screenId = id
|
||||
return id
|
||||
end function
|
||||
@@ -122,9 +125,11 @@ class LoungeApi
|
||||
return m.loungeToken
|
||||
end if
|
||||
|
||||
form = UrlUtils.GetUrlEncodedForm({ "screen_ids": m.screenId })
|
||||
request = HttpClient.Post("https://www.youtube.com/api/lounge/pairing/get_lounge_token_batch", form)
|
||||
request.Header("Content-Type", "application/x-www-form-urlencoded")
|
||||
request = HttpClient.Post("https://www.youtube.com/api/lounge/pairing/get_lounge_token_batch", "")
|
||||
request.UrlEncodedForm({
|
||||
"screen_ids": m.screenId
|
||||
})
|
||||
|
||||
response = request.Await()
|
||||
if not response.IsSuccess()
|
||||
error = `Failed to get lounge token. Please restart playlet to use the cast function.\n${response.ErrorMessage()}`
|
||||
@@ -148,7 +153,6 @@ class LoungeApi
|
||||
end function
|
||||
|
||||
function GetSessionData() as boolean
|
||||
baseUrl = "https://www.youtube.com/api/lounge/bc/bind"
|
||||
queryParams = {
|
||||
"device": "LOUNGE_SCREEN"
|
||||
"theme": "cl"
|
||||
@@ -166,10 +170,11 @@ class LoungeApi
|
||||
queryParams["loungeIdToken"] = m.loungeToken
|
||||
queryParams["zx"] = m.Zx()
|
||||
|
||||
url = UrlUtils.BuildUrl(baseUrl, invalid, queryParams)
|
||||
|
||||
request = HttpClient.Post(url, "count=0")
|
||||
request.Header("Content-Type", "application/x-www-form-urlencoded")
|
||||
request = HttpClient.Post("https://www.youtube.com/api/lounge/bc/bind", "")
|
||||
request.QueryParams(queryParams)
|
||||
request.UrlEncodedForm({
|
||||
"count": 0
|
||||
})
|
||||
|
||||
response = request.Await()
|
||||
if not response.IsSuccess()
|
||||
@@ -435,7 +440,6 @@ class LoungeApi
|
||||
return
|
||||
end if
|
||||
|
||||
baseUrl = "https://www.youtube.com/api/lounge/bc/bind"
|
||||
queryParams = {
|
||||
"device": "LOUNGE_SCREEN"
|
||||
"theme": "cl"
|
||||
@@ -462,8 +466,6 @@ class LoungeApi
|
||||
queryParams["AID"] = messages[0].commandId
|
||||
end if
|
||||
|
||||
url = UrlUtils.BuildUrl(baseUrl, invalid, queryParams)
|
||||
|
||||
postData = [
|
||||
{ key: "count", value: messages.Count() }
|
||||
{ key: "ofs", value: loungeData.ofs }
|
||||
@@ -487,9 +489,10 @@ class LoungeApi
|
||||
|
||||
LogDebug("Sending messages:", postData)
|
||||
|
||||
body = UrlUtils.GetUrlEncodedForm(postData)
|
||||
request = HttpClient.Post(url, body)
|
||||
request.Header("Content-Type", "application/x-www-form-urlencoded")
|
||||
request = HttpClient.Post("https://www.youtube.com/api/lounge/bc/bind", "")
|
||||
request.QueryParams(queryParams)
|
||||
request.UrlEncodedForm(postData)
|
||||
|
||||
request.Send()
|
||||
|
||||
' we do not need to wait for requests to finish, we check on them later
|
||||
|
||||
+7
-10
@@ -23,15 +23,15 @@ function LoungeGenerateManualPairingCodeTask(input as object) as object
|
||||
input.loungeToken = loungeService.loungeToken
|
||||
end if
|
||||
|
||||
bodyParams = {
|
||||
form = {
|
||||
"lounge_token": input.loungeToken
|
||||
"screen_id": input.screenId
|
||||
"screen_name": input.screenName
|
||||
"device_id": input.deviceId
|
||||
}
|
||||
|
||||
for each key in bodyParams
|
||||
if StringUtils.IsNullOrEmpty(bodyParams[key])
|
||||
for each key in form
|
||||
if StringUtils.IsNullOrEmpty(form[key])
|
||||
return {
|
||||
"success": false
|
||||
"error": key + " is empty"
|
||||
@@ -39,14 +39,11 @@ function LoungeGenerateManualPairingCodeTask(input as object) as object
|
||||
end if
|
||||
end for
|
||||
|
||||
bodyParams["access_type"] = "permanent"
|
||||
bodyParams["app"] = "Playlet"
|
||||
form["access_type"] = "permanent"
|
||||
form["app"] = "Playlet"
|
||||
|
||||
baseUrl = "https://www.youtube.com/api/lounge/pairing/get_pairing_code?ctx=pair"
|
||||
|
||||
body = UrlUtils.GetUrlEncodedForm(bodyParams)
|
||||
request = HttpClient.Post(baseUrl, body)
|
||||
request.Header("Content-Type", "application/x-www-form-urlencoded")
|
||||
request = HttpClient.Post("https://www.youtube.com/api/lounge/pairing/get_pairing_code?ctx=pair", "")
|
||||
request.UrlEncodedForm(form)
|
||||
|
||||
response = request.Await()
|
||||
if not response.IsSuccess()
|
||||
|
||||
@@ -77,18 +77,15 @@ namespace Http
|
||||
end if
|
||||
end if
|
||||
|
||||
registerUrl = "https://www.youtube.com/api/lounge/pairing/register_pairing_code"
|
||||
registerBody = {
|
||||
req = HttpClient.Post("https://www.youtube.com/api/lounge/pairing/register_pairing_code", "")
|
||||
req.UrlEncodedForm({
|
||||
"app": "Playlet"
|
||||
"pairing_code": pairingCode
|
||||
"screen_id": m.loungeService.screenId
|
||||
"screen_name": m.deviceName
|
||||
"device_id": m.deviceId
|
||||
}
|
||||
})
|
||||
|
||||
body = UrlUtils.GetUrlEncodedForm(registerBody)
|
||||
req = HttpClient.Post(registerUrl, body)
|
||||
req.Header("Content-Type", "application/x-www-form-urlencoded")
|
||||
res = req.Await()
|
||||
|
||||
if not res.IsSuccess()
|
||||
|
||||
@@ -211,6 +211,12 @@ namespace HttpClient
|
||||
return m
|
||||
end function
|
||||
|
||||
function UrlEncodedForm(form as object) as HttpRequest
|
||||
m.Body(UrlUtils.GetUrlEncodedForm(form))
|
||||
m.Header("Content-Type", "application/x-www-form-urlencoded")
|
||||
return m
|
||||
end function
|
||||
|
||||
function TimeoutSeconds(timeoutSeconds as integer) as HttpRequest
|
||||
m._timeoutSeconds = timeoutSeconds
|
||||
return m
|
||||
|
||||
Reference in new issue
Block a user