http test, homepage additions

This commit is contained in:
Jay 2020-04-12 11:53:02 +01:00
parent ba2a9f1c0d
commit f6020eed89
3 changed files with 87 additions and 31 deletions
core
dashboard
tests

View File

@ -1,8 +1,8 @@
local function newFeedItem(pfp, name, date, body)
local item = teverse.construct("guiFrame", {
size = guiCoord(1, -20, 0, 48),
position = guiCoord(0, 10, 0, 26),
backgroundAlpha = 1
position = guiCoord(0, 10, 0, 40),
backgroundAlpha = 0
})
teverse.construct("guiImage", {
@ -36,7 +36,8 @@ local function newFeedItem(pfp, name, date, body)
text = date,
textAlign = enums.align.middleRight,
textSize = 14,
textAlpha = 0.4
textAlpha = 0.4,
textWrap = true
})
teverse.construct("guiTextBox", {
@ -99,13 +100,13 @@ return {
position = guiCoord(0, 10, 0, 0)
})
teverse.construct("guiTextBox", {
local tevCoins = teverse.construct("guiTextBox", {
parent = tevs,
size = guiCoord(0.5, -20, 0, 40),
size = guiCoord(0.5, 0, 0, 40),
position = guiCoord(0.5, 0, 0.5, -15),
backgroundAlpha = 0,
text = "975",
textSize = 40,
text = "",
textSize = 34,
textAlign = "middleLeft",
textColour = colour(1, 1, 1),
textFont = "tevurl:fonts/openSansBold.ttf"
@ -168,18 +169,26 @@ return {
textFont = "tevurl:fonts/openSansLight.ttf"
})
teverse.construct("guiTextBox", {
local membershipText = teverse.construct("guiTextBox", {
parent = membership,
size = guiCoord(0.5, -20, 0, 40),
size = guiCoord(0.5, 0, 0, 40),
position = guiCoord(0.5, 0, 0.5, -15),
backgroundAlpha = 0,
text = "Free",
textSize = 40,
textSize = 34,
textAlign = "middleLeft",
textColour = colour(1, 1, 1),
textFont = "tevurl:fonts/openSansBold.ttf"
})
local membertype = teverse.networking.localClient.membership
if membership == "plus" then
membershipText.text = "Plus"
elseif membership == "pro" then
membershipText.text = "Pro"
else
membershipText.text = "Free"
end
teverse.construct("guiIcon", {
parent = membership,
size = guiCoord(0, 40, 0, 40),
@ -231,7 +240,7 @@ return {
position = guiCoord(0.5, 0, 0.5, -15),
backgroundAlpha = 0,
text = _TEV_BUILD,
textSize = 40,
textSize = 34,
textAlign = "middleLeft",
textColour = colour(1, 1, 1),
textFont = "tevurl:fonts/openSansBold.ttf"
@ -248,6 +257,14 @@ return {
iconAlpha = 0.9
})
teverse.http:get("https://teverse.com/api/users/me/tevs", {
["Authorization"] = "BEARER " .. teverse.userToken
}, function(code, body)
if code == 200 then
tevCoins.text = body
end
end)
local feedItems = teverse.construct("guiFrame", {
parent = feed,
backgroundAlpha = 1,
@ -269,24 +286,33 @@ return {
})
teverse.construct("guiTextBox", {
size = guiCoord(1, -20, 0, 26),
position = guiCoord(0, 10, 0, 0),
backgroundAlpha = 0,
parent = feedItems,
text = "Feed",
textSize = 26,
textFont = "tevurl:fonts/openSansBold.ttf"
size = guiCoord(1, -20, 0, 30),
position = guiCoord(0, 10, 0, 10),
strokeAlpha = 0.15,
strokeRadius = 3,
textEditable = true,
textAlign = "topLeft"
})
local function pushItem(item)
local y = item.absoluteSize.y
for i,v in pairs(feedItems.children) do
v.position = guiCoord(0, 10, 0, y)
y = y + v.absoluteSize.y + 10
end
item.parent = feedItems
end
teverse.http:get("https://teverse.com/api/feed", {
["Authorization"] = "BEARER " .. teverse.userToken
}, function(code, body)
if code == 200 then
local json = teverse.json:decode(body)
local y = 50
for _,v in pairs(json) do
local date = os.date("%d/%m/%Y %H:%M", os.parseISO8601(v.postedAt))
local item = newFeedItem("tevurl:asset/user/" .. v.postedBy.id, v.postedBy.username, date, v.message)
item.parent = feedItems
local dy = item:child("body").textDimensions.y
item.size = guiCoord(1, -20, 0, dy + 28)
item.position = guiCoord(0, 10, 0, y)
y = y + dy + 28
end
pushItem(newFeedItem("tevurl:asset/user/" .. teverse.networking.localClient.id, teverse.networking.localClient.name, "Now", "test"))
feed.canvasSize = guiCoord(1, 0, 0, feedItems.absolutePosition.y + y + 100)
end
end)
end
}

View File

@ -12,7 +12,7 @@ controller.setup = function()
parent = navBar,
backgroundAlpha = 0
})
teverse.bp
.gridConstraint(navContainer, {
cellSize = guiCoord(0, 40, 0, 40),
@ -135,9 +135,9 @@ controller.setup = function()
table.insert(pages, {container, icon})
end
setupPage(require("tevgit:core/dashboard/pages/home"))
setupPage(require("tevgit:core/dashboard/pages/apps"))
setupPage(require("tevgit:core/dashboard/pages/develop"))
setupPage(require("tevgit:core/dashboard/pages/home.lua"))
setupPage(require("tevgit:core/dashboard/pages/apps.lua"))
setupPage(require("tevgit:core/dashboard/pages/develop.lua"))
end
return controller

30
core/tests/http.lua Normal file
View File

@ -0,0 +1,30 @@
-- test that the http api is functional
return function()
print("Running http tests!")
print("tested")
local code, body = teverse.http:get("https://teverse.com/")
print ("Http Test #1 https", code == 200 and "PASS" or "FAIL")
local code, body = teverse.http:get("http://teverse.com/")
print ("Http Test #2 http", code == 301 and "PASS" or "FAIL")
teverse.http:get("https://teverse.com/", function(code, body)
print ("Http Test #3 https async", code == 200 and "PASS" or "FAIL")
end)
teverse.http:get("http://teverse.com/", function(code, body)
print ("Http Test #4 http async", code == 301 and "PASS" or "FAIL")
end)
local code, body = teverse.http:get("https://teverse.com/", {
["header-name"] = "test"
})
print ("Http Test #5 https header", code == 200 and "PASS" or "FAIL")
teverse.http:get("https://teverse.com/", {
["header-name"] = "test"
}, function(code, body)
print ("Http Test #6 https async header", code == 200 and "PASS" or "FAIL")
end)
end