본문으로 건너뛰기

테이블 생성

리더보드 테이블을 생성하는 API입니다.

URL 확인

이 API는 service-api.playnanoo.com 도메인을 사용합니다.

API 정보

  • URL: https://service-api.playnanoo.com/leaderboard/v20240301/table/create
  • Method: PUT
  • 인증 필요: 예
DeviceInfo 상속

이 API의 Req 클래스는 DeviceInfo를 상속받습니다. DeviceInfo의 모든 속성이 자동으로 포함됩니다.

요청 파라미터

파라미터타입필수설명
namestring필수테이블 이름
rotationstring필수순환 방식 ("never" 또는 "rotation")
rotation_timeoffsetint조건부순환 시간 오프셋 (rotation인 경우 필수)
rotation_datestring조건부순환 시작 날짜 (rotation인 경우 필수)
rotation_timestring조건부순환 시작 시간 (rotation인 경우 필수)
rotation_periodint조건부순환 기간 일 단위 (rotation인 경우 필수)
record_typestring필수기록 타입 ("highscore", "lowscore", "sum", "last")
record_sort_typestring필수정렬 타입 ("asc", "desc")
record_prioritystring필수기록 우선순위 ("Y" 또는 "N")

응답 데이터

Res 클래스

필드타입설명
TableIdstring생성된 테이블 ID

Unity C# 구현

BaseResponse 클래스

모든 API 응답의 기본 클래스입니다.

public class BaseResponse
{
public string ErrorCode;
public string Message;
public string WithdrawalKey;
public string BlockKey;
}

필드 설명:

  • ErrorCode: 에러 코드
  • Message: 에러 메시지
  • WithdrawalKey: 탈퇴 유예 상태인 경우 복구에 필요한 키 (탈퇴 유예 중인 계정만 제공)
  • BlockKey: 차단된 계정인 경우 제공되는 키 (차단된 계정만 제공)

Enum 정의

public enum Rotaion
{
NEVER,
ROTATION
}

public enum RecordType
{
LOWSCORE,
HIGHSCORE,
SUM,
LAST
}

public enum SortType
{
DESC,
ASC
}

테이블 생성 클래스

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
);
}

// 공통 Common 함수로 만들어 두세요.
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;
}
}

사용 예제

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, // 7일마다 순환
recordType: RecordType.HIGHSCORE,
recordSortType: SortType.DESC,
recordPriority: true,
onSuccess: res =>
{
Debug.Log("테이블 생성 성공");
Debug.Log($"테이블 ID: {res.TableId}");
},
onError: error =>
{
Debug.LogError($"테이블 생성 실패: [{error.ErrorCode}] {error.Message}");
}
));
}
순환 방식
  • never: 시즌이 순환하지 않는 영구 리더보드
  • rotation: 지정된 기간마다 자동으로 시즌이 순환되는 리더보드
기록 타입
  • highscore: 가장 높은 점수만 유지
  • lowscore: 가장 낮은 점수만 유지
  • sum: 모든 점수를 합산
  • last: 가장 최근 점수로 갱신
순환 기간

rotation_period는 일 단위로 설정됩니다. 예를 들어, 7일마다 순환하려면 rotation_period를 7로 설정합니다.