데이터 멀티 조회
여러 개의 저장된 데이터를 한 번에 불러오는 API입니다.
URL 확인
이 API는 service-storage-api.playnanoo.com 도메인을 사용합니다.
API 정보
- URL:
https://service-storage-api.playnanoo.com/storage/v20221001/load/multi - Method:
PUT - 인증 필요: 예
DeviceInfo 상속
이 API의 Req 클래스는 DeviceInfo를 상속받습니다. DeviceInfo의 모든 속성이 자동으로 포함됩니다.
요청 파라미터
| 파라미터 | 타입 | 필수 | 설명 |
|---|---|---|---|
| storage_keys | string[] | 필수 | 불러올 데이터 키 목록 |
응답 데이터
Res 클래스
| 필드 | 타입 | 설명 |
|---|---|---|
| Items | StorageItem[] | 불러온 데이터 목록 |
StorageItem 구조
| 필드 | 타입 | 설명 |
|---|---|---|
| PlayerId | string | 플레이어 ID |
| StorageKey | string | 데이터의 키 |
| StorageValue | string | 데이터의 값 |
Unity C# 구현
BaseResponse 클래스
모든 API 응답의 기본 클래스입니다.
public class BaseResponse
{
public string ErrorCode;
public string Message;
public string WithdrawalKey;
public string BlockKey;
}
필드 설명:
ErrorCode: 에러 코드Message: 에러 메시지WithdrawalKey: 탈퇴 유예 상태인 경우 복구에 필요한 키 (탈퇴 유예 중인 계정만 제공)BlockKey: 차단된 계정인 경우 제공되는 키 (차단된 계정만 제공)
데이터 멀티 조회 클래스
using System;
using System.Collections;
using UnityEngine.Networking;
public class StorageMultiLoad
{
static string path = "https://service-storage-api.playnanoo.com/storage/v20221001/load/multi";
[Serializable]
public class StorageItem
{
public string PlayerId;
public string StorageKey;
public string StorageValue;
}
[Serializable]
public class Req : DeviceInfo
{
public string[] storage_keys; // 불러올 데이터 키 목록
public IEnumerator Send(string[] storage_keys, Action<Res> onSuccess, Action<BaseResponse> onError)
{
this.storage_keys = storage_keys;
yield return HttpClient.Send<Req, Res>(
UnityWebRequest.kHttpVerbPUT,
path,
requireToken: true,
body: this,
onSuccess: onSuccess,
onError: onError
);
}
}
[Serializable]
public class Res : BaseResponse
{
public StorageItem[] Items;
}
}
사용 예제
public void LoadMultipleData()
{
StorageMultiLoad.Req req = new StorageMultiLoad.Req();
// 불러올 데이터 키 목록
string[] keys = new string[]
{
"player_level",
"player_gold",
"player_inventory"
};
StartCoroutine(req.Send(
storage_keys: keys,
onSuccess: res =>
{
Debug.Log("다중 데이터 불러오기 성공");
foreach (var item in res.Items)
{
Debug.Log($"플레이어 ID: {item.PlayerId}");
Debug.Log($"{item.StorageKey}: {item.StorageValue}");
}
},
onError: error =>
{
Debug.LogError($"다중 데이터 불러오기 실패: [{error.ErrorCode}] {error.Message}");
}
));
}
효율적인 불러오기
여러 데이터를 동시에 불러와야 하는 경우 이 API를 사용하면 네트워크 요청 횟수를 줄일 수 있어 효율적입니다.
존재하지 않는 키
요청한 키 중 일부가 존재하지 않아도 에러가 발생하지 않으며, 존재하는 데이터만 반환됩니다.