v0.1.1: add configure() method, wally dependency, project config
This commit is contained in:
@@ -17,5 +17,30 @@ wally install
|
||||
|
||||
## Setup
|
||||
|
||||
1. Add your Filoxen API key as a secret named `FILOXEN_API_KEY` in the [Creator Dashboard](https://create.roblox.com) under Secrets.
|
||||
1. Add your Filoxen API key as a secret in the [Creator Dashboard](https://create.roblox.com) under Secrets (defaults to `FILOXEN_API_KEY`).
|
||||
2. Make sure `HttpService` is enabled for your game.
|
||||
|
||||
## Usage
|
||||
|
||||
```luau
|
||||
local Filoxen = require(path.to.Filoxen)
|
||||
|
||||
-- Must be called once before any other function
|
||||
Filoxen.configure({
|
||||
baseUrl = "https://your-filoxen-instance.com",
|
||||
apiKeySecretName = "FILOXEN_API_KEY", -- optional, this is the default
|
||||
})
|
||||
|
||||
-- Fetch 10 random hats
|
||||
local assets = Filoxen.random(
|
||||
{ Enum.AssetType.Hat }, -- assetTypeIds
|
||||
nil, -- maxAssetId
|
||||
nil, -- minAssetId
|
||||
10, -- batch
|
||||
true -- onsale
|
||||
)
|
||||
|
||||
-- Search for assets by name
|
||||
local results = Filoxen.search("blue hat", Enum.AssetType.Hat.Value)
|
||||
```
|
||||
|
||||
|
||||
+15
-7
@@ -4,15 +4,23 @@ local HttpService = game:GetService("HttpService")
|
||||
local RbxAssetUtils = require(script.Packages.RbxAssetUtils)
|
||||
local Types = RbxAssetUtils.Types
|
||||
|
||||
-- Change this to your own API instance URL if self-hosting.
|
||||
local API_URL_BASE = "https://filoxen.example.com"
|
||||
-- Name of the secret in the Secrets Store (Creator Dashboard -> Secrets).
|
||||
local API_KEY_SECRET_NAME = "FILOXEN_API_KEY"
|
||||
local BASE_URL: string? = nil
|
||||
local API_KEY: Secret? = nil
|
||||
|
||||
local API_KEY = HttpService:GetSecret(API_KEY_SECRET_NAME)
|
||||
export type Config = {
|
||||
baseUrl: string,
|
||||
apiKeySecretName: string?,
|
||||
}
|
||||
|
||||
function module.configure(config: Config)
|
||||
BASE_URL = config.baseUrl
|
||||
local secretName = config.apiKeySecretName or "FILOXEN_API_KEY"
|
||||
API_KEY = HttpService:GetSecret(secretName)
|
||||
end
|
||||
|
||||
-- Makes a GET request to the Filoxen API and decodes the assets array from the response.
|
||||
local function makeApiRequest(url: string): {Types.Asset}?
|
||||
assert(BASE_URL and API_KEY, "[Filoxen] Must call .configure() before using the API")
|
||||
local success, response = pcall(function()
|
||||
return HttpService:RequestAsync({
|
||||
Url = url,
|
||||
@@ -43,7 +51,7 @@ end
|
||||
|
||||
-- Fetches random assets from the Filoxen API with the given filters.
|
||||
function module.random(assetTypeIds: {number | Enum.AssetType}, maxAssetId: number?, minAssetId: number?, batch: number, onsale: number | boolean?, playable: number?): {Types.Asset}?
|
||||
local REQUEST_URL = `{API_URL_BASE}/assets/random?assetTypeIds={table.concat(assetTypeIds, ',')}&batch={batch}`
|
||||
local REQUEST_URL = `{BASE_URL}/assets/random?assetTypeIds={table.concat(assetTypeIds, ',')}&batch={batch}`
|
||||
if type(onsale) == "boolean" then
|
||||
onsale = if onsale then 1 else 0
|
||||
end
|
||||
@@ -70,7 +78,7 @@ end
|
||||
-- Searches for assets matching a query string via the Filoxen API.
|
||||
function module.search(query: string, assetTypeId: number, page: number?): {Types.Asset}?
|
||||
if not page then page = 1 end
|
||||
local REQUEST_URL = `{API_URL_BASE}/assets/search?assetTypeId={assetTypeId}&query={HttpService:UrlEncode(query)}&page={page}`
|
||||
local REQUEST_URL = `{BASE_URL}/assets/search?assetTypeId={assetTypeId}&query={HttpService:UrlEncode(query)}&page={page}`
|
||||
return makeApiRequest(REQUEST_URL)
|
||||
end
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "secret-rare/filoxen-luau"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
registry = "https://github.com/UpliftGames/wally-index"
|
||||
realm = "server"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user