9#include "Misc/FileHelper.h"
10#include "Misc/Paths.h"
11#include "Serialization/JsonReader.h"
12#include "Serialization/JsonSerializer.h"
13#include "Subsystems/SubsystemBlueprintLibrary.h"
22 Super::Initialize(Collection);
24 UE_LOG(LogVaRest, Log, TEXT(
"%s: VaRest subsystem initialized"), *
VA_FUNC_LINE);
30 Super::Deinitialize();
36 if (VaRestJson ==
nullptr)
67 const auto Response =
RequestMap.Find(Request);
71 Response->Callback.ExecuteIfBound(Request);
72 Response->Request =
nullptr;
78 return NewObject<UVaRestRequestJSON>(
this);
93 return NewObject<UVaRestJsonObject>(
this);
98 auto SelfSystem = CastChecked<UVaRestSubsystem>(USubsystemBlueprintLibrary::GetEngineSubsystem(UVaRestSubsystem::StaticClass()), ECastCheckedType::NullChecked);
99 return SelfSystem->ConstructVaRestJsonObject();
114 TSharedPtr<FJsonValue> NewVal = MakeShareable(
new FJsonValueString(StringValue));
135 TArray<TSharedPtr<FJsonValue>> ValueArray;
136 for (
auto InVal : InArray)
138 ValueArray.Add(InVal->GetRootValue());
141 TSharedPtr<FJsonValue> NewVal = MakeShareable(
new FJsonValueArray(ValueArray));
151 TSharedPtr<FJsonValue> NewVal = MakeShareable(
new FJsonValueObject(JsonObject->
GetRootObject()));
161 TSharedPtr<FJsonValue> NewVal = InValue;
171 const TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(*JsonString);
172 TSharedPtr<FJsonValue> OutJsonValue;
173 if (FJsonSerializer::Deserialize(Reader, OutJsonValue))
183 const TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(*JsonString);
184 TSharedPtr<FJsonObject> OutJsonObj;
185 if (FJsonSerializer::Deserialize(Reader, OutJsonObj))
187 auto NewJsonObj = NewObject<UVaRestJsonObject>(
this);
188 NewJsonObj->SetRootObject(OutJsonObj);
200 if (FFileHelper::LoadFileToString(JSONString, *(bIsRelativeToContentDir ? FPaths::ProjectContentDir() / Path : Path)))
202 if (Json->DecodeJson(JSONString))
208 UE_LOG(LogVaRest,
Error, TEXT(
"%s: Can't decode json from file %s"), *
VA_FUNC_LINE, *Path);
EVaRestRequestContentType
UENUM(BlueprintType)
EVaRestRequestVerb
UENUM(BlueprintType)
UCLASS(BlueprintType, Blueprintable)
TArray< T > GetTypeArrayField(const FString &FieldName) const
TSharedRef< FJsonObject > & GetRootObject()
UCLASS(BlueprintType, Blueprintable)
void SetRootValue(TSharedPtr< FJsonValue > &JsonValue)
UCLASS(BlueprintType, Blueprintable)
virtual void ProcessURL(const FString &Url=TEXT("http://alyamkin.com"))
UFUNCTION(BlueprintCallable, Category = "VaRest|Request")
void SetRequestObject(UVaRestJsonObject *JsonObject)
UFUNCTION(BlueprintCallable, Category = "VaRest|Request")
void SetContentType(EVaRestRequestContentType ContentType)
UFUNCTION(BlueprintCallable, Category = "VaRest|Request")
FOnStaticRequestFail OnStaticRequestFail
void SetVerb(EVaRestRequestVerb Verb)
UFUNCTION(BlueprintCallable, Category = "VaRest|Request")
void ResetResponseData()
UFUNCTION(BlueprintCallable, Category = "VaRest|Response")
FOnStaticRequestComplete OnStaticRequestComplete
static UVaRestJsonObject * StaticConstructVaRestJsonObject()
UFUNCTION()
UVaRestJsonValue * ConstructJsonValueArray(const TArray< UVaRestJsonValue * > &InArray)
UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Array Value"), Category = "VaRest|Subs...
UVaRestJsonValue * ConstructJsonValue(const TSharedPtr< FJsonValue > &InValue)
virtual void Initialize(FSubsystemCollectionBase &Collection) override
void CallURL(const FString &URL, EVaRestRequestVerb Verb, EVaRestRequestContentType ContentType, UVaRestJsonObject *VaRestJson, const FVaRestCallDelegate &Callback)
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility")
UVaRestJsonValue * DecodeJsonValue(const FString &JsonString)
UFUNCTION(BlueprintCallable, Category = "VaRest|Subsystem")
UVaRestJsonValue * ConstructJsonValueString(const FString &StringValue)
UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json String Value"), Category = "VaRest|Sub...
UVaRestJsonObject * LoadJsonFromFile(const FString &Path, const bool bIsRelativeToContentDir=true)
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility")
UVaRestRequestJSON * ConstructVaRestRequest()
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Construct Json Request (Empty)"),...
UVaRestJsonValue * ConstructJsonValueBool(bool InValue)
UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Bool Value"), Category = "VaRest|Subsy...
UVaRestRequestJSON * ConstructVaRestRequestExt(EVaRestRequestVerb Verb, EVaRestRequestContentType ContentType)
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Construct Json Request"), Category = "VaRest|Subs...
UVaRestJsonObject * ConstructVaRestJsonObject()
UFUNCTION(BlueprintCallable, meta = (DisplayName = "Construct Json Object"), Category = "VaRest|Subsy...
UVaRestJsonValue * ConstructJsonValueNumber(float Number)
UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Number Value"), Category = "VaRest|Sub...
UVaRestJsonObject * DecodeJsonObject(const FString &JsonString)
UFUNCTION(BlueprintCallable, Category = "VaRest|Subsystem")
UVaRestJsonValue * ConstructJsonValueObject(UVaRestJsonObject *JsonObject)
UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Object Value"), Category = "VaRest|Sub...
void OnCallComplete(UVaRestRequestJSON *Request)
virtual void Deinitialize() override
TMap< UVaRestRequestJSON *, FVaRestCallResponse > RequestMap
UPROPERTY()
FVaRestCallDelegate Callback
UPROPERTY()
FDelegateHandle CompleteDelegateHandle
UVaRestRequestJSON * Request
UPROPERTY()
FDelegateHandle FailDelegateHandle