mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 07:06:12 +00:00
Clean up and start work on Epiphany plugin
This commit is contained in:
@@ -18,38 +18,47 @@ local Http = {}
|
|||||||
|
|
||||||
function Http.get(url)
|
function Http.get(url)
|
||||||
dprint("\nGET", url)
|
dprint("\nGET", url)
|
||||||
|
|
||||||
return Promise.new(function(resolve, reject)
|
return Promise.new(function(resolve, reject)
|
||||||
spawn(function()
|
coroutine.wrap(function()
|
||||||
local ok, result = pcall(function()
|
local success, response = pcall(function()
|
||||||
return HttpService:GetAsync(url, true)
|
return HttpService:RequestAsync({
|
||||||
|
Url = url,
|
||||||
|
Method = "GET",
|
||||||
|
})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if ok then
|
if success then
|
||||||
dprint("\t", result)
|
dprint("\t", response)
|
||||||
resolve(HttpResponse.new(result))
|
resolve(HttpResponse.fromRobloxResponse(response))
|
||||||
else
|
else
|
||||||
reject(HttpError.fromErrorString(result))
|
reject(HttpError.fromErrorString(response))
|
||||||
end
|
end
|
||||||
end)
|
end)()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Http.post(url, body)
|
function Http.post(url, body)
|
||||||
dprint("\nPOST", url)
|
dprint("\nPOST", url)
|
||||||
dprint(body)
|
dprint(body);
|
||||||
|
|
||||||
return Promise.new(function(resolve, reject)
|
return Promise.new(function(resolve, reject)
|
||||||
spawn(function()
|
coroutine.wrap(function()
|
||||||
local ok, result = pcall(function()
|
local success, response = pcall(function()
|
||||||
return HttpService:PostAsync(url, body)
|
return HttpService:RequestAsync({
|
||||||
|
Url = url,
|
||||||
|
Method = "POST",
|
||||||
|
Body = body,
|
||||||
|
})
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if ok then
|
if success then
|
||||||
dprint("\t", result)
|
dprint("\t", response)
|
||||||
resolve(HttpResponse.new(result))
|
resolve(HttpResponse.fromRobloxResponse(response))
|
||||||
else
|
else
|
||||||
reject(HttpError.fromErrorString(result))
|
reject(HttpError.fromErrorString(response))
|
||||||
end
|
end
|
||||||
end)
|
end)()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,18 @@
|
|||||||
local HttpService = game:GetService("HttpService")
|
local HttpService = game:GetService("HttpService")
|
||||||
|
|
||||||
|
local stringTemplate = [[
|
||||||
|
HttpResponse {
|
||||||
|
code: %d
|
||||||
|
body: %s
|
||||||
|
}]]
|
||||||
|
|
||||||
local HttpResponse = {}
|
local HttpResponse = {}
|
||||||
HttpResponse.__index = HttpResponse
|
HttpResponse.__index = HttpResponse
|
||||||
|
|
||||||
|
function HttpResponse:__tostring()
|
||||||
|
return stringTemplate:format(self.code, self.body)
|
||||||
|
end
|
||||||
|
|
||||||
function HttpResponse.new(body)
|
function HttpResponse.new(body)
|
||||||
local response = {
|
local response = {
|
||||||
body = body,
|
body = body,
|
||||||
@@ -13,6 +23,20 @@ function HttpResponse.new(body)
|
|||||||
return response
|
return response
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function HttpResponse.fromRobloxResponse(response)
|
||||||
|
local self = {
|
||||||
|
body = response.Body,
|
||||||
|
code = response.StatusCode,
|
||||||
|
headers = response.Headers,
|
||||||
|
}
|
||||||
|
|
||||||
|
return setmetatable(self, HttpResponse)
|
||||||
|
end
|
||||||
|
|
||||||
|
function HttpResponse:isSuccess()
|
||||||
|
return self.code >= 200 and self.code < 300
|
||||||
|
end
|
||||||
|
|
||||||
function HttpResponse:json()
|
function HttpResponse:json()
|
||||||
return HttpService:JSONDecode(self.body)
|
return HttpService:JSONDecode(self.body)
|
||||||
end
|
end
|
||||||
|
|||||||
21
plugin/src/Logging.lua
Normal file
21
plugin/src/Logging.lua
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
local enabledByTest = false
|
||||||
|
|
||||||
|
local function isEnabled()
|
||||||
|
return _G.ROJO_LOG or enabledByTest
|
||||||
|
end
|
||||||
|
|
||||||
|
local Logging = {}
|
||||||
|
|
||||||
|
function Logging.info(template, ...)
|
||||||
|
if isEnabled() then
|
||||||
|
print("[Rojo] " .. template:format(...))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Logging.warn(template, ...)
|
||||||
|
if isEnabled() then
|
||||||
|
warn("[Rojo] " .. template:format(...))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return Logging
|
||||||
Reference in New Issue
Block a user