add gs
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
local HttpService = game:GetService("HttpService")
|
||||
|
||||
local Url = require(CorePackages.AppTempCommon.LuaApp.Http.Url)
|
||||
|
||||
return function(requestImpl, conversationId, messageText)
|
||||
local payload = HttpService:JSONEncode({
|
||||
conversationId = conversationId,
|
||||
message = messageText,
|
||||
})
|
||||
|
||||
local url = string.format("%s/send-message", Url.CHAT_URL)
|
||||
|
||||
return requestImpl(url, "POST", { postBody = payload })
|
||||
end
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
local HttpService = game:GetService("HttpService")
|
||||
|
||||
local Url = require(CorePackages.AppTempCommon.LuaApp.Http.Url)
|
||||
|
||||
return function(requestImpl, userId, clientId)
|
||||
local payload = HttpService:JSONEncode({
|
||||
participantuserId = userId
|
||||
})
|
||||
|
||||
local url = string.format("%s/start-one-to-one-conversation", Url.CHAT_URL)
|
||||
|
||||
return requestImpl(url, "POST", { postBody = payload })
|
||||
end
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
|
||||
local Url = require(CorePackages.AppTempCommon.LuaApp.Http.Url)
|
||||
|
||||
--[[
|
||||
This endpoint returns a promise that resolves to:
|
||||
[
|
||||
{
|
||||
"final": true,
|
||||
"url": "string",
|
||||
"retryToken": "string",
|
||||
"universeId": 0,
|
||||
"placeId": 0
|
||||
}, {...}, ...
|
||||
]
|
||||
]]
|
||||
|
||||
-- requestImpl - (function<promise<HttpResponse>>(url, requestMethod, options))
|
||||
-- imageTokens - (array<long>) the placeIds of the places you want to get thumbnails for
|
||||
-- height - (int) the height of the asset to render
|
||||
-- width - (int) the width of the asset to render
|
||||
return function(requestImpl, imageTokens, height, width)
|
||||
local args = {}
|
||||
|
||||
if height then
|
||||
table.insert(args, string.format("height=%d", height))
|
||||
end
|
||||
|
||||
if width then
|
||||
table.insert(args, string.format("width=%d", width))
|
||||
end
|
||||
|
||||
-- append all of the thumbnail tokens
|
||||
local totalTokens = 0
|
||||
for _, value in pairs(imageTokens) do
|
||||
totalTokens = totalTokens + 1
|
||||
table.insert(args, string.format("imageTokens=%s", value))
|
||||
end
|
||||
if totalTokens == 0 then
|
||||
error("cannot fetch thumbnails without tokens")
|
||||
end
|
||||
|
||||
-- construct the url
|
||||
local url = string.format("%sv1/games/game-thumbnails?%s", Url.GAME_URL, table.concat(args, "&"))
|
||||
|
||||
-- return a promise of the result listed above
|
||||
return requestImpl(url, "GET")
|
||||
end
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
|
||||
local Url = require(CorePackages.AppTempCommon.LuaApp.Http.Url)
|
||||
|
||||
--[[
|
||||
This endpoint returns games' information with a batches of place ids
|
||||
Doc: https://games.roblox.com/docs#!/Games/get_v1_games_multiget_place_details
|
||||
{
|
||||
"placeId": 0,
|
||||
"name": "string",
|
||||
"description": "string",
|
||||
"url": "string",
|
||||
"builder": "string",
|
||||
"builderId": 0,
|
||||
"isPlayable": true,
|
||||
"reasonProhibited": "string",
|
||||
"universeId": 0,
|
||||
"universeRootPlaceId": 0,
|
||||
"price": 0,
|
||||
"imageToken": "string"
|
||||
}
|
||||
]]--
|
||||
|
||||
return function(requestImpl, placeIds)
|
||||
local argTable = {
|
||||
placeIds = placeIds,
|
||||
}
|
||||
|
||||
local args = Url:makeQueryString(argTable)
|
||||
local url = string.format("%s/v1/games/multiget-place-details?%s", Url.GAME_URL, args)
|
||||
|
||||
return requestImpl(url, "GET")
|
||||
end
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
|
||||
local Url = require(CorePackages.AppTempCommon.LuaApp.Http.Url)
|
||||
|
||||
return function(requestImpl, placeIds)
|
||||
local argTable = {
|
||||
placeIds = placeIds,
|
||||
}
|
||||
|
||||
-- construct the url
|
||||
local args = Url:makeQueryString(argTable)
|
||||
local url = string.format("%s/v1/games/multiget-place-details?%s",
|
||||
Url.GAME_URL, args
|
||||
)
|
||||
|
||||
return requestImpl(url, "GET")
|
||||
end
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
local Players = game:GetService("Players")
|
||||
|
||||
local Url = require(CorePackages.AppTempCommon.LuaApp.Http.Url)
|
||||
|
||||
--[[
|
||||
This endpoint returns a promise that resolves to:
|
||||
|
||||
[
|
||||
{
|
||||
"success:" true,
|
||||
"count": "0"
|
||||
},
|
||||
]
|
||||
]]--
|
||||
|
||||
-- requestImpl - (function<promise<HttpResponse>>(url, requestMethod, options))
|
||||
return function(requestImpl)
|
||||
|
||||
local argTable = {
|
||||
userId = Players.LocalPlayer.UserId,
|
||||
}
|
||||
|
||||
local args = Url:makeQueryString(argTable)
|
||||
local url = string.format("%s/user/get-friendship-count?%s",
|
||||
Url.API_URL, tostring(Players.LocalPlayer.UserId), args
|
||||
)
|
||||
|
||||
return requestImpl(url, "GET")
|
||||
end
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
local Url = require(CorePackages.AppTempCommon.LuaApp.Http.Url)
|
||||
|
||||
return function(requestImpl, userId)
|
||||
local url = string.format("%s/users/%s/friends",
|
||||
Url.FRIEND_URL, userId
|
||||
)
|
||||
|
||||
return requestImpl(url, "GET")
|
||||
end
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
local HttpService = game:GetService("HttpService")
|
||||
|
||||
local Url = require(CorePackages.AppTempCommon.LuaApp.Http.Url)
|
||||
|
||||
-- Endpoint documented here:
|
||||
-- https://presence.roblox.com/docs
|
||||
|
||||
return function(requestImpl, userIds)
|
||||
local userIdsToNumber = {}
|
||||
for _, id in pairs(userIds) do
|
||||
local idToNumber = tonumber(id)
|
||||
if idToNumber then
|
||||
table.insert(userIdsToNumber, idToNumber)
|
||||
end
|
||||
end
|
||||
|
||||
local payload = HttpService:JSONEncode({
|
||||
userIds = userIdsToNumber,
|
||||
})
|
||||
|
||||
local url = string.format("%s/presence/users", Url.PRESENCE_URL)
|
||||
|
||||
return requestImpl(url, "POST", { postBody = payload })
|
||||
end
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
local CorePackages = game:GetService("CorePackages")
|
||||
local Players = game:GetService("Players")
|
||||
|
||||
local Promise = require(CorePackages.AppTempCommon.LuaApp.Promise)
|
||||
|
||||
local THUMBNAIL_TYPE_BY_NAME = {
|
||||
AvatarThumbnail = Enum.ThumbnailType.AvatarThumbnail,
|
||||
HeadShot = Enum.ThumbnailType.HeadShot,
|
||||
}
|
||||
|
||||
local THUMBNAIL_SIZE_BY_NAME = {
|
||||
Size48x48 = Enum.ThumbnailSize.Size48x48,
|
||||
Size60x60 = Enum.ThumbnailSize.Size60x60,
|
||||
Size100x100 = Enum.ThumbnailSize.Size100x100,
|
||||
Size150x150 = Enum.ThumbnailSize.Size150x150,
|
||||
Size352x352 = Enum.ThumbnailSize.Size352x352
|
||||
}
|
||||
|
||||
return function(userId, thumbnailType, thumbnailSize)
|
||||
return Promise.new(function(resolve, reject)
|
||||
--Async methods will yield the thread
|
||||
spawn(function()
|
||||
local result = {success = false}
|
||||
local success, message = pcall(function()
|
||||
local image, isFinal = Players:GetUserThumbnailAsync(
|
||||
userId, THUMBNAIL_TYPE_BY_NAME[thumbnailType], THUMBNAIL_SIZE_BY_NAME[thumbnailSize]
|
||||
)
|
||||
|
||||
result = {
|
||||
success = true,
|
||||
id = userId,
|
||||
thumbnailType = thumbnailType,
|
||||
thumbnailSize = thumbnailSize,
|
||||
|
||||
image = isFinal and image or nil,
|
||||
isFinal = isFinal,
|
||||
}
|
||||
end)
|
||||
|
||||
if success then
|
||||
resolve(result)
|
||||
else
|
||||
result.message = message
|
||||
reject(result)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end
|
||||
@@ -0,0 +1,114 @@
|
||||
--[[
|
||||
Url Constructor
|
||||
|
||||
Provides a single location for base urls.
|
||||
|
||||
]]--
|
||||
local ContentProvider = game:GetService("ContentProvider")
|
||||
|
||||
-- helper functions
|
||||
local function parseBaseUrlInformation()
|
||||
-- get the current base url from the current configuration
|
||||
local baseUrl = ContentProvider.BaseUrl
|
||||
|
||||
-- keep a copy of the base url (https://www.roblox.com/)
|
||||
-- append a trailing slash if there isn't one
|
||||
if baseUrl:sub(#baseUrl) ~= "/" then
|
||||
baseUrl = baseUrl .. "/"
|
||||
end
|
||||
|
||||
-- parse out scheme (http, https)
|
||||
local _, schemeEnd = baseUrl:find("://")
|
||||
|
||||
-- parse out the prefix (www, kyle, ying, etc.)
|
||||
local prefixIndex, prefixEnd = baseUrl:find("%.", schemeEnd + 1)
|
||||
local basePrefix = baseUrl:sub(schemeEnd + 1, prefixIndex - 1)
|
||||
|
||||
-- parse out the domain (roblox.com/, sitetest1.robloxlabs.com/, etc.)
|
||||
local baseDomain = baseUrl:sub(prefixEnd + 1)
|
||||
|
||||
return baseUrl, basePrefix, baseDomain
|
||||
end
|
||||
local function preventTableModification(aTable, key, value)
|
||||
error("Attempt to modify read-only table")
|
||||
end
|
||||
local function createReadOnlyTable(aTable)
|
||||
return setmetatable({}, {
|
||||
__index = aTable,
|
||||
__newindex = preventTableModification,
|
||||
__metatable = false
|
||||
});
|
||||
end
|
||||
|
||||
|
||||
-- url construction building blocks
|
||||
local _baseUrl, _basePrefix, _baseDomain = parseBaseUrlInformation()
|
||||
|
||||
-- construct urls once
|
||||
local _baseApiUrl = string.format("https://api.%s", _baseDomain)
|
||||
local _baseAuthUrl = string.format("https://auth.%s", _baseDomain)
|
||||
local _baseChatUrl = string.format("https://chat.%sv2", _baseDomain)
|
||||
local _baseFriendUrl = string.format("https://friends.%sv1", _baseDomain)
|
||||
local _baseGameAssetUrl = string.format("https://assetgame.%s", _baseDomain)
|
||||
local _baseGamesUrl = string.format("https://games.%s", _baseDomain)
|
||||
local _baseNotificationUrl = string.format("https://notifications.%s", _baseDomain)
|
||||
local _basePresenceUrl = string.format("https://presence.%sv1", _baseDomain)
|
||||
local _baseRealtimeUrl = string.format("https://realtime.%s", _baseDomain)
|
||||
local _baseWebUrl = string.format("https://web.%s", _baseDomain)
|
||||
local _baseWwwUrl = string.format("https://www.%s", _baseDomain)
|
||||
local _baseAdsUrl = string.format("https://ads.%s", _baseDomain)
|
||||
|
||||
-- public api
|
||||
local Url = {
|
||||
DOMAIN = _baseDomain,
|
||||
PREFIX = _basePrefix,
|
||||
BASE_URL = _baseUrl,
|
||||
API_URL = _baseApiUrl,
|
||||
AUTH_URL = _baseAuthUrl,
|
||||
GAME_URL = _baseGamesUrl,
|
||||
GAME_ASSET_URL = _baseGameAssetUrl,
|
||||
CHAT_URL = _baseChatUrl,
|
||||
FRIEND_URL = _baseFriendUrl,
|
||||
PRESENCE_URL = _basePresenceUrl,
|
||||
NOTIFICATION_URL = _baseNotificationUrl,
|
||||
REALTIME_URL = _baseRealtimeUrl,
|
||||
WEB_URL = _baseWebUrl,
|
||||
WWW_URL = _baseWwwUrl,
|
||||
ADS_URL = _baseAdsUrl,
|
||||
}
|
||||
|
||||
function Url:getUserProfileUrl(userId)
|
||||
return string.format("%susers/%s/profile", self.BASE_URL, userId)
|
||||
end
|
||||
|
||||
function Url:isVanitySite()
|
||||
return self.PREFIX ~= "www"
|
||||
end
|
||||
|
||||
-- data - (table<string, string>) a table of key/value pairs to format
|
||||
function Url:makeQueryString(data)
|
||||
--NOTE - This function can be used to create a query string of parameters
|
||||
-- at the end of url query, or create a application/form-url-encoded post body string
|
||||
local params = {}
|
||||
|
||||
-- NOTE - Arrays are handled, but generally data is expected to be flat.
|
||||
for key, value in pairs(data) do
|
||||
if value ~= nil then --for optional params
|
||||
if type(value) == "table" then
|
||||
for i = 1, #value do
|
||||
table.insert(params, key .. "=" .. value[i])
|
||||
end
|
||||
else
|
||||
table.insert(params, key .. "=" .. tostring(value))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return table.concat(params, "&")
|
||||
end
|
||||
|
||||
|
||||
-- prevent anyone from modifying this table:
|
||||
Url = createReadOnlyTable(Url)
|
||||
|
||||
return Url
|
||||
@@ -0,0 +1,12 @@
|
||||
return function()
|
||||
|
||||
local ContentProvider = game:GetService("ContentProvider")
|
||||
local Url = require(script.Parent.Url)
|
||||
|
||||
it("The base url has not been changed for debugging", function()
|
||||
local baseUrl = ContentProvider.BaseUrl
|
||||
|
||||
expect(baseUrl).to.equal(Url.BASE_URL)
|
||||
end)
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user