Lesson 62 - Parsing the Metadata
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -70,3 +70,7 @@ Plugins/**/Intermediate/*
|
||||
|
||||
# Cache files for the editor to use
|
||||
DerivedDataCache/*
|
||||
|
||||
# IDE Settings
|
||||
.idea/
|
||||
*.iml
|
||||
@@ -4,3 +4,5 @@
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
IMPLEMENT_MODULE( FDefaultModuleImpl, DedicatedServers );
|
||||
|
||||
DEFINE_LOG_CATEGORY( LogDedicatedServers );
|
||||
@@ -3,3 +3,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
|
||||
DECLARE_LOG_CATEGORY_EXTERN(LogDedicatedServers, Log, All);
|
||||
@@ -3,9 +3,11 @@
|
||||
|
||||
#include "UI/APITest/APITestManager.h"
|
||||
#include "HttpModule.h"
|
||||
#include "JsonObjectConverter.h"
|
||||
#include "Data/API/APIData.h"
|
||||
#include "GameplayTags/DedicatedServerTags.h"
|
||||
#include "Interfaces/IHttpResponse.h"
|
||||
#include "UI/HTTP/HTTPRequestTypes.h"
|
||||
|
||||
|
||||
void UAPITestManager::ListFleetsButtonClicked()
|
||||
@@ -34,13 +36,13 @@ void UAPITestManager::ListFleets_Response(FHttpRequestPtr Request, FHttpResponse
|
||||
|
||||
if (FJsonSerializer::Deserialize(JsonReader, JsonObject))
|
||||
{
|
||||
if (JsonObject->HasField(TEXT("FleetIds")))
|
||||
if (JsonObject->HasField(TEXT("$metadata")))
|
||||
{
|
||||
for (TSharedPtr<FJsonValue> Fleet : JsonObject->GetArrayField(TEXT("FleetIds")))
|
||||
{
|
||||
FString FleetString = Fleet->AsString();
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FleetString);
|
||||
}
|
||||
TSharedPtr<FJsonObject> MetaDataJsonObject = JsonObject->GetObjectField(TEXT("$metadata"));
|
||||
FDSMetaData DSMetaData;
|
||||
FJsonObjectConverter::JsonObjectToUStruct(MetaDataJsonObject.ToSharedRef(), &DSMetaData);
|
||||
|
||||
DSMetaData.Dump();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
11
Source/DedicatedServers/Private/UI/HTTP/HTTPRequestTypes.cpp
Normal file
11
Source/DedicatedServers/Private/UI/HTTP/HTTPRequestTypes.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "UI/HTTP/HTTPRequestTypes.h"
|
||||
#include "DedicatedServers/DedicatedServers.h"
|
||||
|
||||
void FDSMetaData::Dump() const
|
||||
{
|
||||
UE_LOGFMT(LogDedicatedServers, Log, "MetaData:");
|
||||
UE_LOGFMT(LogDedicatedServers, Log, "httpStatusCode: {httpStatusCode}", httpStatusCode);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, "requestId: {requestId}", requestId);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, "attempts: {attempts}", attempts);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, "totalRetryDelay: {totalRetryDelay}", totalRetryDelay);
|
||||
}
|
||||
23
Source/DedicatedServers/Public/UI/HTTP/HTTPRequestTypes.h
Normal file
23
Source/DedicatedServers/Public/UI/HTTP/HTTPRequestTypes.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "HTTPRequestTypes.generated.h"
|
||||
|
||||
USTRUCT()
|
||||
struct FDSMetaData
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY()
|
||||
int32 httpStatusCode{};
|
||||
|
||||
UPROPERTY()
|
||||
FString requestId{};
|
||||
|
||||
UPROPERTY()
|
||||
int32 attempts{};
|
||||
|
||||
UPROPERTY()
|
||||
double totalRetryDelay{};
|
||||
|
||||
void Dump() const;
|
||||
};
|
||||
Reference in New Issue
Block a user