앞선 포스팅에서 django 프로젝트 세팅을 마쳤다. 이번 포스팅에서는 해당 프로젝트 안에서 lol api를 사용하고 테스트해보고자 한다.
리그오브레전드 개발자 사이트(https://developer.riotgames.com/)에 접속해서 본인 계정으로 로그인을 해준다. 개발자 프로그램 정책에 동의한 뒤 my page에 가면 테스트용 개인 api를 제공한다.
해당 api를 copy해서 프로젝트의 secret.py에 추가한 뒤 import해서 사용하면 된다.
롤 api서버에 요청하기 위해서 requests 라이브러리를 사용한다.
$pip install requests
test_lol_api/views.py에 만들어둔 test_api함수에 다음과 같이 작성한다.
def test_api(request) :
riot_status_url = "https://kr.api.riotgames.com/lol/status/v4/platform-data"
response = requests.get(riot_status_url, headers={"X-Riot-Token": key})
return JsonResponse({"riot_server_status" : response.text}, json_dumps_params={'ensure_ascii':False})
~/test/api 엔드포인트에 접속해보면 리그오브레전드의 한국서버 상태를 볼 수 있다.
"riot_server_status": {
"id": "KR",
"name": "Korea",
"locales": [
"ko_KR"
],
"maintenances": [
{
"maintenance_status": "scheduled",
"archive_at": "2022-04-27T02:00:00+00:00",
"id": 4566,
"updates": [
{
"translations": [
{
"locale": "ko_KR",
"content": "12.8 패치 준비를 위해 랭크 게임이 2022/04/27 04:30 KST 부터 비활성화 됩니다. 서버는 2022/04/27 06:00 KST에 비활성화되며, 이를 기준으로 진행 중인 모든 게임은 즉시 종료되고 대전기록에 저장되지 않습니다. 점검은 약 5시간 동안 진행될 예정입니다."
},
{
"locale": "en_US",
"content": "Starting at 04/26/2022 12:30 PDT Ranked Queues will be disabled in preparation for patch 12.8. At 04/26/2022 14:00 PDT the servers will be shut down and all games currently in progress will end in a draw and stats will not be recorded. We estimate the battlegrounds will be unavailable for 3 hours."
}
],
"publish_locations": [
"riotstatus"
],
...
4월 27일 새벽에 업데이트가 예정되어있음을 알 수 있다.