merge impl-v2: plugin

This commit is contained in:
Lucien Greathouse
2018-06-10 22:53:22 -07:00
parent 7d7f671920
commit e30545c132
13 changed files with 243 additions and 859 deletions

View File

@@ -13,27 +13,15 @@ local function dprint(...)
end
end
-- TODO: Factor out into separate library, especially error handling
local Http = {}
Http.__index = Http
function Http.new(baseUrl)
assert(type(baseUrl) == "string", "Http.new needs a baseUrl!")
local http = {
baseUrl = baseUrl
}
setmetatable(http, Http)
return http
end
function Http:get(endpoint)
dprint("\nGET", endpoint)
function Http.get(url)
dprint("\nGET", url)
return Promise.new(function(resolve, reject)
spawn(function()
local ok, result = pcall(function()
return HttpService:GetAsync(self.baseUrl .. endpoint, true)
return HttpService:GetAsync(url, true)
end)
if ok then
@@ -46,13 +34,13 @@ function Http:get(endpoint)
end)
end
function Http:post(endpoint, body)
dprint("\nPOST", endpoint)
function Http.post(url, body)
dprint("\nPOST", url)
dprint(body)
return Promise.new(function(resolve, reject)
spawn(function()
local ok, result = pcall(function()
return HttpService:PostAsync(self.baseUrl .. endpoint, body)
return HttpService:PostAsync(url, body)
end)
if ok then
@@ -65,4 +53,12 @@ function Http:post(endpoint, body)
end)
end
function Http.jsonEncode(object)
return HttpService:JSONEncode(object)
end
function Http.jsonDecode(source)
return HttpService:JSONDecode(source)
end
return Http