mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-20 12:45:05 +00:00
35 lines
617 B
Lua
35 lines
617 B
Lua
local HttpService = game:GetService("HttpService")
|
|
|
|
local stringTemplate = [[
|
|
Http.Response {
|
|
code: %d
|
|
body: %s
|
|
}]]
|
|
|
|
local Response = {}
|
|
Response.__index = Response
|
|
|
|
function Response:__tostring()
|
|
return stringTemplate:format(self.code, self.body)
|
|
end
|
|
|
|
function Response.fromRobloxResponse(response)
|
|
local self = {
|
|
body = response.Body,
|
|
code = response.StatusCode,
|
|
headers = response.Headers,
|
|
}
|
|
|
|
return setmetatable(self, Response)
|
|
end
|
|
|
|
function Response:isSuccess()
|
|
return self.code >= 200 and self.code < 300
|
|
end
|
|
|
|
function Response:json()
|
|
return HttpService:JSONDecode(self.body)
|
|
end
|
|
|
|
return Response
|