Clean up and start work on Epiphany plugin

This commit is contained in:
Lucien Greathouse
2018-12-03 13:54:54 -08:00
parent 75359e2b83
commit dd4d542d7e
3 changed files with 71 additions and 17 deletions

View File

@@ -1,8 +1,18 @@
local HttpService = game:GetService("HttpService")
local stringTemplate = [[
HttpResponse {
code: %d
body: %s
}]]
local HttpResponse = {}
HttpResponse.__index = HttpResponse
function HttpResponse:__tostring()
return stringTemplate:format(self.code, self.body)
end
function HttpResponse.new(body)
local response = {
body = body,
@@ -13,6 +23,20 @@ function HttpResponse.new(body)
return response
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()
return HttpService:JSONDecode(self.body)
end