49 lines
1.7 KiB
C++
49 lines
1.7 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "UI/API_Test/APITestManager.h"
|
|
#include "HttpModule.h"
|
|
#include "JsonObjectConverter.h"
|
|
#include "Data/API/APIData.h"
|
|
#include "DedicatedServers/DedicatedServers.h"
|
|
#include "GameplayTags/DedicatedServersTags.h"
|
|
#include "Interfaces/IHttpResponse.h"
|
|
#include "UI/HTTP/HTTPRequestTypes.h"
|
|
|
|
void UAPITestManager::ListFleets()
|
|
{
|
|
check(APIData);
|
|
TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
|
|
Request->OnProcessRequestComplete().BindUObject(this, &UAPITestManager::ListFleets_Response);
|
|
const FString APIUrl = APIData->GetAPIEndpoint(DedicatedServersTags::GameSessionsAPI::ListFleets);
|
|
Request->SetURL(APIUrl);
|
|
Request->SetVerb(TEXT("GET"));
|
|
Request->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
|
|
Request->ProcessRequest();
|
|
}
|
|
|
|
void UAPITestManager::ListFleets_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
|
|
{
|
|
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, "List Fleets Response Received");
|
|
|
|
TSharedPtr<FJsonObject> JsonObject;
|
|
TSharedRef<TJsonReader<>> JsonReader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
|
|
|
|
if (FJsonSerializer::Deserialize(JsonReader, JsonObject))
|
|
{
|
|
const TSharedPtr<FJsonObject>* ErrorObjPtr = nullptr;;
|
|
|
|
if (ContainsErrors(JsonObject, false))
|
|
{
|
|
OnListFleetsResponseReceived.Broadcast(FDS_ListFleetsResponse(), false);
|
|
return;
|
|
}
|
|
DumpMetaData(JsonObject);
|
|
|
|
FDS_ListFleetsResponse ListFleetsResponse;
|
|
FJsonObjectConverter::JsonObjectToUStruct(JsonObject.ToSharedRef(), &ListFleetsResponse);
|
|
ListFleetsResponse.Dump();
|
|
OnListFleetsResponseReceived.Broadcast(ListFleetsResponse, true);
|
|
}
|
|
}
|