Create Table
API for creating a leaderboard table.
URL Verification
This API uses the service-api.playnanoo.com domain.
API Information
- URL:
https://service-api.playnanoo.com/leaderboard/v20240301/table/create - Method:
PUT - Authentication Required: Yes
DeviceInfo Inheritance
The Req class of this API inherits from DeviceInfo. All properties of DeviceInfo are automatically included.
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| name | string | Required | Table name |
| rotation | string | Required | Rotation method ("never" or "rotation") |
| rotation_timeoffset | int | Conditional | Rotation time offset (required if rotation) |
| rotation_date | string | Conditional | Rotation start date (required if rotation) |
| rotation_time | string | Conditional | Rotation start time (required if rotation) |
| rotation_period | int | Conditional | Rotation period in days (required if rotation) |
| record_type | string | Required | Record type ("highscore", "lowscore", "sum", "last") |
| record_sort_type | string | Required | Sort type ("asc", "desc") |
| record_priority | string | Required | Record priority ("Y" or "N") |
Response Data
Res Class
| Field | Type | Description |
|---|---|---|
| TableId | string | Created table ID |
Unity C# Implementation
BaseResponse Class
Base class for all API responses.
public class BaseResponse
{
public string ErrorCode;
public string Message;
public string WithdrawalKey;
public string BlockKey;
}
Field descriptions:
ErrorCode: Error codeMessage: Error messageWithdrawalKey: Key required for recovery if in withdrawal grace period (only provided for accounts in withdrawal grace period)BlockKey: Key provided if account is blocked (only provided for blocked accounts)
Enum Definitions
public enum Rotaion
{
NEVER,
ROTATION
}
public enum RecordType
{
LOWSCORE,
HIGHSCORE,
SUM,
LAST
}
public enum SortType
{
DESC,
ASC
}
Create Table Class
using System;
using System.Collections;
using UnityEngine.Networking;
public class CreateTable
{
static string path = "https://service-api.playnanoo.com/leaderboard/v20240301/table/create";
[Serializable]
public class Req : DeviceInfo
{
public string name;
public string rotation;
public string record_type;
public string record_sort_type;
public string record_priority;
public int rotation_timeoffset;
public string rotation_date;
public string rotation_time;
public int rotation_period;
public IEnumerator Send(
string name,
Rotaion rotation,
int rotationTimeOffset,
string rotationDate,
string rotationTime,
int rotationPeriod,
RecordType recordType,
SortType recordSortType,
bool recordPriority,
Action<Res> onSuccess,
Action<BaseResponse> onError)
{
if (!string.IsNullOrEmpty(name)) this.name = name;
this.record_priority = recordPriority ? "Y" : "N";
this.rotation = GetRotation(rotation);
this.record_type = GetRecordType(recordType);
this.record_sort_type = GetSortType(recordSortType);
if(this.rotation == "rotation")
{
this.rotation_timeoffset = rotationTimeOffset;
this.rotation_period = rotationPeriod;
if (!string.IsNullOrEmpty(rotationDate)) this.rotation_date = rotationDate;
if (!string.IsNullOrEmpty(rotationTime)) this.rotation_time = rotationTime;
}
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
// Create as a common function.
private string GetRotation(Rotaion value)
{
if (value == Rotaion.NEVER)
{
return "never";
}
return "rotation";
}
private string GetRecordType(RecordType value)
{
return value switch
{
RecordType.LOWSCORE => "lowscore",
RecordType.SUM => "sum",
RecordType.LAST => "last",
_ => "highscore",
};
}
private string GetSortType(SortType value)
{
if (value == SortType.ASC)
{
return "asc";
}
return "desc";
}
}
[Serializable]
public class Res : BaseResponse
{
public string TableId;
}
}
Usage Example
public void CreateLeaderboardTable()
{
CreateTable.Req req = new CreateTable.Req();
StartCoroutine(req.Send(
name: "Weekly Ranking",
rotation: Rotaion.ROTATION,
rotationTimeOffset: 0,
rotationDate: "2024-03-01",
rotationTime: "00:00:00",
rotationPeriod: 7, // Rotate every 7 days
recordType: RecordType.HIGHSCORE,
recordSortType: SortType.DESC,
recordPriority: true,
onSuccess: res =>
{
Debug.Log("Table created successfully");
Debug.Log($"Table ID: {res.TableId}");
},
onError: error =>
{
Debug.LogError($"Table creation failed: [{error.ErrorCode}] {error.Message}");
}
));
}
Rotation Method
- never: Permanent leaderboard with no season rotation
- rotation: Leaderboard that automatically rotates seasons at specified intervals
Record Type
- highscore: Keep only the highest score
- lowscore: Keep only the lowest score
- sum: Sum all scores
- last: Update to the most recent score
Rotation Period
rotation_period is set in days. For example, to rotate every 7 days, set rotation_period to 7.