diff --git a/Config/BaseVaRest.ini b/Config/BaseVaRest.ini new file mode 100644 index 00000000..22766973 --- /dev/null +++ b/Config/BaseVaRest.ini @@ -0,0 +1,14 @@ +[CoreRedirects] ++PackageRedirects=(OldName="/VaRestPlugin/", NewName="/VaRest/", MatchSubstring=true) ++ClassRedirects=(OldName="/Script/VaRestPlugin.VaRestJsonObject",NewName="/Script/VaRest.VaRestJsonObject") ++ClassRedirects=(OldName="/Script/VaRestPlugin.VaRestJsonValue",NewName="/Script/VaRest.VaRestJsonValue") ++ClassRedirects=(OldName="/Script/VaRestPlugin.VaRestLibrary",NewName="/Script/VaRest.VaRestLibrary") ++ClassRedirects=(OldName="/Script/VaRestPlugin.VaRestRequestJSON",NewName="/Script/VaRest.VaRestRequestJSON") ++StructRedirects=(OldName="/Script/VaRestPlugin.VaRestCallResponse",NewName="/Script/VaRest.VaRestCallResponse") ++EnumRedirects=(OldName="/Script/VaRestPlugin.EVaJson",NewName="/Script/VaRest.EVaJson") ++EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestVerb",NewName="/Script/VaRest.ERequestVerb") ++EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestContentType",NewName="/Script/VaRest.ERequestContentType") ++EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestStatus",NewName="/Script/VaRest.ERequestStatus") ++FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequest",NewName="VaRestRequestJSON.ConstructVaRestRequest") ++FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequestExt",NewName="VaRestRequestJSON.ConstructVaRestRequestExt") ++FunctionRedirects=(OldName="VaRestJsonObject.ConstructJsonObject",NewName="VaRestJsonObject.ConstructVaRestJsonObject") diff --git a/Config/DefaultVaRest.ini b/Config/DefaultVaRest.ini new file mode 100644 index 00000000..22766973 --- /dev/null +++ b/Config/DefaultVaRest.ini @@ -0,0 +1,14 @@ +[CoreRedirects] ++PackageRedirects=(OldName="/VaRestPlugin/", NewName="/VaRest/", MatchSubstring=true) ++ClassRedirects=(OldName="/Script/VaRestPlugin.VaRestJsonObject",NewName="/Script/VaRest.VaRestJsonObject") ++ClassRedirects=(OldName="/Script/VaRestPlugin.VaRestJsonValue",NewName="/Script/VaRest.VaRestJsonValue") ++ClassRedirects=(OldName="/Script/VaRestPlugin.VaRestLibrary",NewName="/Script/VaRest.VaRestLibrary") ++ClassRedirects=(OldName="/Script/VaRestPlugin.VaRestRequestJSON",NewName="/Script/VaRest.VaRestRequestJSON") ++StructRedirects=(OldName="/Script/VaRestPlugin.VaRestCallResponse",NewName="/Script/VaRest.VaRestCallResponse") ++EnumRedirects=(OldName="/Script/VaRestPlugin.EVaJson",NewName="/Script/VaRest.EVaJson") ++EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestVerb",NewName="/Script/VaRest.ERequestVerb") ++EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestContentType",NewName="/Script/VaRest.ERequestContentType") ++EnumRedirects=(OldName="/Script/VaRestPlugin.ERequestStatus",NewName="/Script/VaRest.ERequestStatus") ++FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequest",NewName="VaRestRequestJSON.ConstructVaRestRequest") ++FunctionRedirects=(OldName="VaRestRequestJSON.ConstructRequestExt",NewName="VaRestRequestJSON.ConstructVaRestRequestExt") ++FunctionRedirects=(OldName="VaRestJsonObject.ConstructJsonObject",NewName="VaRestJsonObject.ConstructVaRestJsonObject") diff --git a/Config/FilterPlugin.ini b/Config/FilterPlugin.ini new file mode 100644 index 00000000..bb30259b --- /dev/null +++ b/Config/FilterPlugin.ini @@ -0,0 +1 @@ +[FilterPlugin] diff --git a/README.md b/README.md index 4d2a5534..b13aa22d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ -Overview -======== +[![statusIcon](https://teamcity.ufna.dev/app/rest/builds/buildType:(id:UfnaDev_VaRest_ClangFormatCheck)/statusIcon.svg)](https://teamcity.ufna.dev/viewType.html?buildTypeId=UfnaDev_VaRest_ClangFormatCheck&guest=1) +![GitHub](https://img.shields.io/github/license/ufna/VaRest) +![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/ufna/VaRest?include_prereleases) + +# VaRest VaRest is the plugin for [Unreal Engine 4](https://www.unrealengine.com/) that makes REST server communications easier to use. @@ -11,7 +14,7 @@ Key features: * Blueprintable FJsonValue wrapper - **full Json features made for blueprints!** * Both bindable events and **latent functions** are provided to control the asynchronous requests -Check the [Wiki](https://hiazma.atlassian.net/wiki/display/VAR) for plugin usage examples and installation notes. +Check the [Wiki](http://bit.ly/VaRest-Docs) for plugin usage examples and installation notes. Current version: **1.1 R 26** (UE 4.19-4.23) diff --git a/Source/VaRest/Private/VaRest.cpp b/Source/VaRest/Private/VaRest.cpp new file mode 100644 index 00000000..283e9fb8 --- /dev/null +++ b/Source/VaRest/Private/VaRest.cpp @@ -0,0 +1,96 @@ +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. + +#include "VaRest.h" + +#include "VaRestDefines.h" +#include "VaRestJsonObject.h" +#include "VaRestJsonValue.h" +#include "VaRestRequestController.h" +#include "VaRestRequestJSON.h" +#include "VaRestSettings.h" + +#include "Developer/Settings/Public/ISettingsModule.h" + +#define LOCTEXT_NAMESPACE "FVaRestModule" + +void FVaRestModule::StartupModule() +{ + // @HACK Force classes to be compiled on shipping build + UVaRestJsonObject::StaticClass(); + UVaRestJsonValue::StaticClass(); + UVaRestRequestJSON::StaticClass(); + + VaRestSettings = NewObject(GetTransientPackage(), "VaRestSettings", RF_Standalone); + VaRestSettings->AddToRoot(); + + // Register settings + if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr("Settings")) + { + SettingsModule->RegisterSettings("Project", "Plugins", "VaRest", + LOCTEXT("RuntimeSettingsName", "VaRest"), + LOCTEXT("RuntimeSettingsDescription", "Configure VaRest plugin settings"), + VaRestSettings); + } + + FWorldDelegates::OnWorldCleanup.AddLambda([this](UWorld* World, bool bSessionEnded, bool bCleanupResources) { + RequestControllers.Remove(World); + + UE_LOG(LogVaRest, Log, TEXT("%s: Request Controller is removed for: %s"), *VA_FUNC_LINE, *World->GetName()); + }); + + FWorldDelegates::OnPostWorldInitialization.AddLambda([this](UWorld* World, const UWorld::InitializationValues IVS) { + auto Controller = NewObject(GetTransientPackage()); + Controller->SetFlags(RF_Standalone); + Controller->AddToRoot(); + + Controller->Initialize(); + + RequestControllers.Add(World, Controller); + + UE_LOG(LogVaRest, Log, TEXT("%s: Request Controller is created for: %s"), *VA_FUNC_LINE, *World->GetName()); + }); + + UE_LOG(LogVaRest, Log, TEXT("%s: VaRest module started"), *VA_FUNC_LINE); +} + +void FVaRestModule::ShutdownModule() +{ + if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr("Settings")) + { + SettingsModule->UnregisterSettings("Project", "Plugins", "VaRest"); + } + + if (!GExitPurge) + { + VaRestSettings->RemoveFromRoot(); + + // If we're in exit purge, this object has already been destroyed + for (auto Controller : RequestControllers) + { + Controller.Value->RemoveFromRoot(); + } + } + else + { + VaRestSettings = nullptr; + } + + RequestControllers.Empty(); +} + +UVaRestSettings* FVaRestModule::GetSettings() const +{ + check(VaRestSettings); + return VaRestSettings; +} + +UVaRestRequestController* FVaRestModule::GetRequestController(UWorld* World) const +{ + return RequestControllers.FindChecked(World); +} + +IMPLEMENT_MODULE(FVaRestModule, VaRest) + +DEFINE_LOG_CATEGORY(LogVaRest); + +#undef LOCTEXT_NAMESPACE diff --git a/Source/VaRestPlugin/Private/VaRestJsonObject.cpp b/Source/VaRest/Private/VaRestJsonObject.cpp similarity index 98% rename from Source/VaRestPlugin/Private/VaRestJsonObject.cpp rename to Source/VaRest/Private/VaRestJsonObject.cpp index 3153c2cc..495592b2 100644 --- a/Source/VaRestPlugin/Private/VaRestJsonObject.cpp +++ b/Source/VaRest/Private/VaRestJsonObject.cpp @@ -1,23 +1,23 @@ -// Copyright 2014 Vladimir Alyamkin. All Rights Reserved. +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. #include "VaRestJsonObject.h" +#include "VaRestDefines.h" #include "VaRestJsonParser.h" #include "VaRestJsonValue.h" -#include "VaRestPluginPrivatePCH.h" #include "Runtime/Launch/Resources/Version.h" typedef TJsonWriterFactory> FCondensedJsonStringWriterFactory; typedef TJsonWriter> FCondensedJsonStringWriter; -UVaRestJsonObject::UVaRestJsonObject(const class FObjectInitializer& PCIP) - : Super(PCIP) +UVaRestJsonObject::UVaRestJsonObject(const FObjectInitializer& ObjectInitializer) + : Super(ObjectInitializer) , JsonObj(MakeShared()) { } -UVaRestJsonObject* UVaRestJsonObject::ConstructJsonObject(UObject* WorldContextObject) +UVaRestJsonObject* UVaRestJsonObject::ConstructVaRestJsonObject(UObject* WorldContextObject) { return NewObject(); } diff --git a/Source/VaRestPlugin/Private/VaRestJsonParser.cpp b/Source/VaRest/Private/VaRestJsonParser.cpp similarity index 99% rename from Source/VaRestPlugin/Private/VaRestJsonParser.cpp rename to Source/VaRest/Private/VaRestJsonParser.cpp index a3fe4b6c..b156ec5d 100644 --- a/Source/VaRestPlugin/Private/VaRestJsonParser.cpp +++ b/Source/VaRest/Private/VaRestJsonParser.cpp @@ -83,7 +83,7 @@ uint32 FUtf8Helper::CodepointFromUtf8(const ANSICHAR*& SourceString, const uint3 Codepoint = (((Octet << 12)) | ((Octet2 - 128) << 6) | ((Octet3 - 128))); // UTF-8 characters cannot be in the UTF-16 surrogates range - if (UE4StringConv_Private::IsHighSurrogate(Codepoint) || UE4StringConv_Private::IsLowSurrogate(Codepoint)) + if (StringConv::IsHighSurrogate(Codepoint) || StringConv::IsLowSurrogate(Codepoint)) { ++SourceString; // Sequence was not valid UTF-8. Skip the first byte and continue. return UNICODE_BOGUS_CHAR_CODEPOINT; diff --git a/Source/VaRestPlugin/Private/VaRestJsonParser.h b/Source/VaRest/Private/VaRestJsonParser.h similarity index 100% rename from Source/VaRestPlugin/Private/VaRestJsonParser.h rename to Source/VaRest/Private/VaRestJsonParser.h diff --git a/Source/VaRestPlugin/Private/VaRestJsonValue.cpp b/Source/VaRest/Private/VaRestJsonValue.cpp similarity index 96% rename from Source/VaRestPlugin/Private/VaRestJsonValue.cpp rename to Source/VaRest/Private/VaRestJsonValue.cpp index dfe20434..3895ae09 100644 --- a/Source/VaRestPlugin/Private/VaRestJsonValue.cpp +++ b/Source/VaRest/Private/VaRestJsonValue.cpp @@ -1,11 +1,12 @@ -// Copyright 2014 Vladimir Alyamkin. All Rights Reserved. +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. #include "VaRestJsonValue.h" + +#include "VaRestDefines.h" #include "VaRestJsonObject.h" -#include "VaRestPluginPrivatePCH.h" -UVaRestJsonValue::UVaRestJsonValue(const class FObjectInitializer& PCIP) - : Super(PCIP) +UVaRestJsonValue::UVaRestJsonValue(const FObjectInitializer& ObjectInitializer) + : Super(ObjectInitializer) { } diff --git a/Source/VaRest/Private/VaRestLibrary.cpp b/Source/VaRest/Private/VaRestLibrary.cpp new file mode 100644 index 00000000..6dd20605 --- /dev/null +++ b/Source/VaRest/Private/VaRestLibrary.cpp @@ -0,0 +1,72 @@ +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. + +#include "VaRestLibrary.h" + +#include "VaRestDefines.h" +#include "VaRestJsonObject.h" +#include "VaRestRequestJSON.h" + +#include "Misc/Base64.h" +#include "Misc/FileHelper.h" +#include "Misc/Paths.h" + +////////////////////////////////////////////////////////////////////////// +// Helpers + +FString UVaRestLibrary::PercentEncode(const FString& Source) +{ + return FGenericPlatformHttp::UrlEncode(Source); +} + +FString UVaRestLibrary::Base64Encode(const FString& Source) +{ + return FBase64::Encode(Source); +} + +bool UVaRestLibrary::Base64Decode(const FString& Source, FString& Dest) +{ + return FBase64::Decode(Source, Dest); +} + +bool UVaRestLibrary::Base64EncodeData(const TArray& Data, FString& Dest) +{ + if (Data.Num() > 0) + { + Dest = FBase64::Encode(Data); + return true; + } + + return false; +} + +bool UVaRestLibrary::Base64DecodeData(const FString& Source, TArray& Dest) +{ + return FBase64::Decode(Source, Dest); +} + +////////////////////////////////////////////////////////////////////////// +// File system integration + +class UVaRestJsonObject* UVaRestLibrary::LoadJsonFromFile(UObject* WorldContextObject, const FString& Path, const bool bIsRelativeToContentDir) +{ + UVaRestJsonObject* Json = UVaRestJsonObject::ConstructVaRestJsonObject(WorldContextObject); + + FString JSONString; + if (FFileHelper::LoadFileToString(JSONString, *(bIsRelativeToContentDir ? FPaths::ProjectContentDir() / Path : Path))) + { + if (Json->DecodeJson(JSONString)) + { + return Json; + } + else + { + UE_LOG(LogVaRest, Error, TEXT("%s: Can't decode json from file %s"), *VA_FUNC_LINE, *Path); + } + } + else + { + UE_LOG(LogVaRest, Error, TEXT("%s: Can't open file %s"), *VA_FUNC_LINE, *Path); + } + + return nullptr; +} diff --git a/Source/VaRest/Private/VaRestRequestController.cpp b/Source/VaRest/Private/VaRestRequestController.cpp new file mode 100644 index 00000000..a38682a7 --- /dev/null +++ b/Source/VaRest/Private/VaRestRequestController.cpp @@ -0,0 +1,14 @@ +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. + +#include "VaRestRequestController.h" + +#include "VaRestDefines.h" + +UVaRestRequestController::UVaRestRequestController(const FObjectInitializer& ObjectInitializer) + : Super(ObjectInitializer) +{ +} + +void UVaRestRequestController::Initialize() +{ +} diff --git a/Source/VaRestPlugin/Private/VaRestRequestJSON.cpp b/Source/VaRest/Private/VaRestRequestJSON.cpp similarity index 94% rename from Source/VaRestPlugin/Private/VaRestRequestJSON.cpp rename to Source/VaRest/Private/VaRestRequestJSON.cpp index 7e66c018..80b646b4 100644 --- a/Source/VaRestPlugin/Private/VaRestRequestJSON.cpp +++ b/Source/VaRest/Private/VaRestRequestJSON.cpp @@ -1,12 +1,13 @@ -// Copyright 2014 Vladimir Alyamkin. All Rights Reserved. +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. #include "VaRestRequestJSON.h" +#include "VaRestDefines.h" #include "VaRestJsonObject.h" #include "VaRestLibrary.h" -#include "VaRestPluginPrivatePCH.h" #include "VaRestSettings.h" +#include "Json.h" #include "Misc/CoreMisc.h" #include "Runtime/Launch/Resources/Version.h" @@ -34,17 +35,17 @@ UVaRestRequestJSON::UVaRestRequestJSON(const class FObjectInitializer& PCIP) ResetData(); } -UVaRestRequestJSON* UVaRestRequestJSON::ConstructRequest(UObject* WorldContextObject) +UVaRestRequestJSON* UVaRestRequestJSON::ConstructVaRestRequest(UObject* WorldContextObject) { return NewObject(); } -UVaRestRequestJSON* UVaRestRequestJSON::ConstructRequestExt( +UVaRestRequestJSON* UVaRestRequestJSON::ConstructVaRestRequestExt( UObject* WorldContextObject, ERequestVerb Verb, ERequestContentType ContentType) { - UVaRestRequestJSON* Request = ConstructRequest(WorldContextObject); + UVaRestRequestJSON* Request = ConstructVaRestRequest(WorldContextObject); Request->SetVerb(Verb); Request->SetContentType(ContentType); @@ -145,7 +146,7 @@ void UVaRestRequestJSON::Cancel() ////////////////////////////////////////////////////////////////////////// // JSON data accessors -UVaRestJsonObject* UVaRestRequestJSON::GetRequestObject() +UVaRestJsonObject* UVaRestRequestJSON::GetRequestObject() const { return RequestJsonObj; } @@ -155,7 +156,7 @@ void UVaRestRequestJSON::SetRequestObject(UVaRestJsonObject* JsonObject) RequestJsonObj = JsonObject; } -UVaRestJsonObject* UVaRestRequestJSON::GetResponseObject() +UVaRestJsonObject* UVaRestRequestJSON::GetResponseObject() const { return ResponseJsonObj; } @@ -168,22 +169,22 @@ void UVaRestRequestJSON::SetResponseObject(UVaRestJsonObject* JsonObject) /////////////////////////////////////////////////////////////////////////// // Response data access -FString UVaRestRequestJSON::GetURL() +FString UVaRestRequestJSON::GetURL() const { return HttpRequest->GetURL(); } -ERequestStatus UVaRestRequestJSON::GetStatus() +ERequestStatus UVaRestRequestJSON::GetStatus() const { return ERequestStatus((uint8)HttpRequest->GetStatus()); } -int32 UVaRestRequestJSON::GetResponseCode() +int32 UVaRestRequestJSON::GetResponseCode() const { return ResponseCode; } -FString UVaRestRequestJSON::GetResponseHeader(const FString HeaderName) +FString UVaRestRequestJSON::GetResponseHeader(const FString& HeaderName) { FString Result; @@ -196,7 +197,7 @@ FString UVaRestRequestJSON::GetResponseHeader(const FString HeaderName) return Result; } -TArray UVaRestRequestJSON::GetAllResponseHeaders() +TArray UVaRestRequestJSON::GetAllResponseHeaders() const { TArray Result; for (TMap::TConstIterator It(ResponseHeaders); It; ++It) diff --git a/Source/VaRestPlugin/Private/VaRestSettings.cpp b/Source/VaRest/Private/VaRestSettings.cpp similarity index 68% rename from Source/VaRestPlugin/Private/VaRestSettings.cpp rename to Source/VaRest/Private/VaRestSettings.cpp index e4d28ff2..79ba9c31 100644 --- a/Source/VaRestPlugin/Private/VaRestSettings.cpp +++ b/Source/VaRest/Private/VaRestSettings.cpp @@ -1,4 +1,4 @@ -// Copyright 2018 Vladimir Alyamkin. All Rights Reserved. +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. #include "VaRestSettings.h" diff --git a/Source/VaRest/Public/VaRest.h b/Source/VaRest/Public/VaRest.h new file mode 100644 index 00000000..9efb2ca2 --- /dev/null +++ b/Source/VaRest/Public/VaRest.h @@ -0,0 +1,50 @@ +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. + +#pragma once + +#include "Modules/ModuleManager.h" + +class UVaRestRequestController; +class UVaRestSettings; + +class FVaRestModule : public IModuleInterface +{ +public: + /** IModuleInterface implementation */ + virtual void StartupModule() override; + virtual void ShutdownModule() override; + + /** + * Singleton-like access to this module's interface. This is just for convenience! + * Beware of calling this during the shutdown phase, though. Your module might have been unloaded already. + * + * @return Returns singleton instance, loading the module on demand if needed + */ + static inline FVaRestModule& Get() + { + return FModuleManager::LoadModuleChecked("VaRest"); + } + + /** + * Checks to see if this module is loaded and ready. It is only valid to call Get() if IsAvailable() returns true. + * + * @return True if the module is loaded and ready to use + */ + static inline bool IsAvailable() + { + return FModuleManager::Get().IsModuleLoaded("VaRest"); + } + + /** Getter for internal settings object to support runtime configuration changes */ + UVaRestSettings* GetSettings() const; + + /** Get global request controller */ + UVaRestRequestController* GetRequestController(UWorld* World) const; + +protected: + /** Module settings */ + UVaRestSettings* VaRestSettings; + + /** Request controllers (one for each World we have) */ + TMap RequestControllers; +}; diff --git a/Source/VaRestPlugin/Private/VaRestPluginPrivatePCH.h b/Source/VaRest/Public/VaRestDefines.h similarity index 81% rename from Source/VaRestPlugin/Private/VaRestPluginPrivatePCH.h rename to Source/VaRest/Public/VaRestDefines.h index c9fd4f5a..17b35010 100644 --- a/Source/VaRestPlugin/Private/VaRestPluginPrivatePCH.h +++ b/Source/VaRest/Public/VaRestDefines.h @@ -1,4 +1,4 @@ -// Copyright 2014 Vladimir Alyamkin. All Rights Reserved. +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. #pragma once @@ -15,12 +15,10 @@ #include "Engine.h" #endif -#include "Containers/Map.h" -#include "Http.h" -#include "Json.h" - -#include "LatentActions.h" -#include "Templates/SharedPointer.h" +#include "Delegates/DelegateCombinations.h" +#include "Logging/LogCategory.h" +#include "Logging/LogMacros.h" +#include "Logging/LogVerbosity.h" // You should place include statements to your module's private header files here. You only need to // add includes for headers that are used in most of your module's source files though. diff --git a/Source/VaRestPlugin/Classes/VaRestJsonObject.h b/Source/VaRest/Public/VaRestJsonObject.h similarity index 94% rename from Source/VaRestPlugin/Classes/VaRestJsonObject.h rename to Source/VaRest/Public/VaRestJsonObject.h index 32ece87d..f1b78817 100644 --- a/Source/VaRestPlugin/Classes/VaRestJsonObject.h +++ b/Source/VaRest/Public/VaRestJsonObject.h @@ -1,5 +1,4 @@ -// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved. -// Copyright 2014 Vladimir Alyamkin. All Rights Reserved. +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. #pragma once @@ -13,13 +12,13 @@ class UVaRestJsonValue; * Blueprintable FJsonObject wrapper */ UCLASS(BlueprintType, Blueprintable) -class VARESTPLUGIN_API UVaRestJsonObject : public UObject +class VAREST_API UVaRestJsonObject : public UObject { GENERATED_UCLASS_BODY() /** Create new Json object */ - UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Object", HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"), Category = "VaRest|Json") - static UVaRestJsonObject* ConstructJsonObject(UObject* WorldContextObject); + UFUNCTION(BlueprintCallable, meta = (DisplayName = "Construct Json Object", HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"), Category = "VaRest|Json") + static UVaRestJsonObject* ConstructVaRestJsonObject(UObject* WorldContextObject); /** Reset all internal data */ UFUNCTION(BlueprintCallable, Category = "VaRest|Json") diff --git a/Source/VaRestPlugin/Classes/VaRestJsonValue.h b/Source/VaRest/Public/VaRestJsonValue.h similarity index 95% rename from Source/VaRestPlugin/Classes/VaRestJsonValue.h rename to Source/VaRest/Public/VaRestJsonValue.h index 9b5036b2..1d9ad0f3 100644 --- a/Source/VaRestPlugin/Classes/VaRestJsonValue.h +++ b/Source/VaRest/Public/VaRestJsonValue.h @@ -1,8 +1,9 @@ -// Copyright 1998-2014 Epic Games, Inc. All Rights Reserved. -// Copyright 2014 Vladimir Alyamkin. All Rights Reserved. +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. #pragma once +#include "VaRestDefines.h" + #include "VaRestJsonValue.generated.h" class UVaRestJsonObject; @@ -27,7 +28,7 @@ enum class EVaJson : uint8 * Blueprintable FJsonValue wrapper */ UCLASS(BlueprintType, Blueprintable) -class VARESTPLUGIN_API UVaRestJsonValue : public UObject +class VAREST_API UVaRestJsonValue : public UObject { GENERATED_UCLASS_BODY() diff --git a/Source/VaRestPlugin/Classes/VaRestLibrary.h b/Source/VaRest/Public/VaRestLibrary.h similarity index 79% rename from Source/VaRestPlugin/Classes/VaRestLibrary.h rename to Source/VaRest/Public/VaRestLibrary.h index bfd5ea9d..30a95732 100644 --- a/Source/VaRestPlugin/Classes/VaRestLibrary.h +++ b/Source/VaRest/Public/VaRestLibrary.h @@ -1,9 +1,10 @@ -// Copyright 2016 Vladimir Alyamkin. All Rights Reserved. +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. #pragma once #include "Kismet/BlueprintFunctionLibrary.h" +#include "VaRestDefines.h" #include "VaRestTypes.h" #include "VaRestLibrary.generated.h" @@ -41,7 +42,7 @@ struct FVaRestCallResponse * Useful tools for REST communications */ UCLASS() -class VARESTPLUGIN_API UVaRestLibrary : public UBlueprintFunctionLibrary +class VAREST_API UVaRestLibrary : public UBlueprintFunctionLibrary { GENERATED_BODY() @@ -101,18 +102,4 @@ class VARESTPLUGIN_API UVaRestLibrary : public UBlueprintFunctionLibrary */ UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (WorldContext = "WorldContextObject")) static class UVaRestJsonObject* LoadJsonFromFile(UObject* WorldContextObject, const FString& Path, const bool bIsRelativeToContentDir = true); - - ////////////////////////////////////////////////////////////////////////// - // Easy URL processing - -public: - /** Easy way to process http requests */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (WorldContext = "WorldContextObject")) - static void CallURL(UObject* WorldContextObject, const FString& URL, ERequestVerb Verb, ERequestContentType ContentType, UVaRestJsonObject* VaRestJson, const FVaRestCallDelegate& Callback); - - /** Called when URL is processed (one for both success/unsuccess events)*/ - static void OnCallComplete(UVaRestRequestJSON* Request); - -private: - static TMap RequestMap; }; diff --git a/Source/VaRest/Public/VaRestRequestController.h b/Source/VaRest/Public/VaRestRequestController.h new file mode 100644 index 00000000..04772c71 --- /dev/null +++ b/Source/VaRest/Public/VaRestRequestController.h @@ -0,0 +1,18 @@ +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. + +#pragma once + +#include "VaRestDefines.h" + +#include "VaRestRequestController.generated.h" + +UCLASS() +class VAREST_API UVaRestRequestController : public UObject +{ + GENERATED_UCLASS_BODY() + +public: + /** */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Controller") + void Initialize(); +}; diff --git a/Source/VaRestPlugin/Classes/VaRestRequestJSON.h b/Source/VaRest/Public/VaRestRequestJSON.h similarity index 90% rename from Source/VaRestPlugin/Classes/VaRestRequestJSON.h rename to Source/VaRest/Public/VaRestRequestJSON.h index a0497562..2f2eb2f0 100644 --- a/Source/VaRestPlugin/Classes/VaRestRequestJSON.h +++ b/Source/VaRest/Public/VaRestRequestJSON.h @@ -1,4 +1,4 @@ -// Copyright 2014 Vladimir Alyamkin. All Rights Reserved. +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. #pragma once @@ -77,7 +77,7 @@ DECLARE_MULTICAST_DELEGATE_OneParam(FOnStaticRequestFail, class UVaRestRequestJS * General helper class http requests via blueprints */ UCLASS(BlueprintType, Blueprintable) -class VARESTPLUGIN_API UVaRestRequestJSON : public UObject +class VAREST_API UVaRestRequestJSON : public UObject { GENERATED_UCLASS_BODY() @@ -86,12 +86,12 @@ class VARESTPLUGIN_API UVaRestRequestJSON : public UObject // Construction /** Creates new request (totally empty) */ - UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Request (Empty)", HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"), Category = "VaRest|Request") - static UVaRestRequestJSON* ConstructRequest(UObject* WorldContextObject); + UFUNCTION(BlueprintCallable, meta = (DisplayName = "Construct Json Request (Empty)", HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"), Category = "VaRest|Request") + static UVaRestRequestJSON* ConstructVaRestRequest(UObject* WorldContextObject); /** Creates new request with defined verb and content type */ - UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Json Request", HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"), Category = "VaRest|Request") - static UVaRestRequestJSON* ConstructRequestExt(UObject* WorldContextObject, ERequestVerb Verb, ERequestContentType ContentType); + UFUNCTION(BlueprintCallable, meta = (DisplayName = "Construct Json Request", HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"), Category = "VaRest|Request") + static UVaRestRequestJSON* ConstructVaRestRequestExt(UObject* WorldContextObject, ERequestVerb Verb, ERequestContentType ContentType); /** Set verb to the request */ UFUNCTION(BlueprintCallable, Category = "VaRest|Request") @@ -146,7 +146,7 @@ class VARESTPLUGIN_API UVaRestRequestJSON : public UObject /** Get the Request Json object */ UFUNCTION(BlueprintCallable, Category = "VaRest|Request") - UVaRestJsonObject* GetRequestObject(); + UVaRestJsonObject* GetRequestObject() const; /** Set the Request Json object */ UFUNCTION(BlueprintCallable, Category = "VaRest|Request") @@ -154,7 +154,7 @@ class VARESTPLUGIN_API UVaRestRequestJSON : public UObject /** Get the Response Json object */ UFUNCTION(BlueprintCallable, Category = "VaRest|Response") - UVaRestJsonObject* GetResponseObject(); + UVaRestJsonObject* GetResponseObject() const; /** Set the Response Json object */ UFUNCTION(BlueprintCallable, Category = "VaRest|Response") @@ -165,23 +165,23 @@ class VARESTPLUGIN_API UVaRestRequestJSON : public UObject /** Get url of http request */ UFUNCTION(BlueprintCallable, Category = "VaRest|Request") - FString GetURL(); + FString GetURL() const; /** Get status of http request */ UFUNCTION(BlueprintCallable, Category = "VaRest|Request") - ERequestStatus GetStatus(); + ERequestStatus GetStatus() const; /** Get the response code of the last query */ UFUNCTION(BlueprintCallable, Category = "VaRest|Response") - int32 GetResponseCode(); + int32 GetResponseCode() const; /** Get value of desired response header */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Response") - FString GetResponseHeader(const FString HeaderName); + UFUNCTION(BlueprintPure, Category = "VaRest|Response") + FString GetResponseHeader(const FString& HeaderName); /** Get list of all response headers */ UFUNCTION(BlueprintCallable, Category = "VaRest|Response") - TArray GetAllResponseHeaders(); + TArray GetAllResponseHeaders() const; ////////////////////////////////////////////////////////////////////////// // URL processing diff --git a/Source/VaRestPlugin/Classes/VaRestSettings.h b/Source/VaRest/Public/VaRestSettings.h similarity index 71% rename from Source/VaRestPlugin/Classes/VaRestSettings.h rename to Source/VaRest/Public/VaRestSettings.h index 3de0258c..d246671b 100644 --- a/Source/VaRestPlugin/Classes/VaRestSettings.h +++ b/Source/VaRest/Public/VaRestSettings.h @@ -1,11 +1,11 @@ -// Copyright 2018 Vladimir Alyamkin. All Rights Reserved. +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. #pragma once #include "VaRestSettings.generated.h" UCLASS(config = Engine, defaultconfig) -class VARESTPLUGIN_API UVaRestSettings : public UObject +class VAREST_API UVaRestSettings : public UObject { GENERATED_UCLASS_BODY() diff --git a/Source/VaRestPlugin/Classes/VaRestTypes.h b/Source/VaRest/Public/VaRestTypes.h similarity index 94% rename from Source/VaRestPlugin/Classes/VaRestTypes.h rename to Source/VaRest/Public/VaRestTypes.h index c1a61497..5088e60c 100644 --- a/Source/VaRestPlugin/Classes/VaRestTypes.h +++ b/Source/VaRest/Public/VaRestTypes.h @@ -1,4 +1,4 @@ -// Copyright 2016 Vladimir Alyamkin. All Rights Reserved. +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. #pragma once diff --git a/Source/VaRestPlugin/VaRestPlugin.Build.cs b/Source/VaRest/VaRest.Build.cs similarity index 70% rename from Source/VaRestPlugin/VaRestPlugin.Build.cs rename to Source/VaRest/VaRest.Build.cs index d1ded261..30d13a99 100644 --- a/Source/VaRestPlugin/VaRestPlugin.Build.cs +++ b/Source/VaRest/VaRest.Build.cs @@ -1,18 +1,18 @@ -// Copyright 2014-2018 Vladimir Alyamkin. All Rights Reserved. +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. using System.IO; namespace UnrealBuildTool.Rules { - public class VaRestPlugin : ModuleRules + public class VaRest : ModuleRules { - public VaRestPlugin(ReadOnlyTargetRules Target) : base(Target) + public VaRest(ReadOnlyTargetRules Target) : base(Target) { PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; PrivateIncludePaths.AddRange( new string[] { - "VaRestPlugin/Private", + "VaRest/Private", // ... add other private include paths required here ... }); diff --git a/Source/VaRestEditor/Private/VaRestEditor.cpp b/Source/VaRestEditor/Private/VaRestEditor.cpp new file mode 100644 index 00000000..82d0973e --- /dev/null +++ b/Source/VaRestEditor/Private/VaRestEditor.cpp @@ -0,0 +1,20 @@ +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. + +#include "VaRestEditor.h" + +#define LOCTEXT_NAMESPACE "FVaRestEditorModule" + +void FVaRestEditorModule::StartupModule() +{ + // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module +} + +void FVaRestEditorModule::ShutdownModule() +{ + // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, + // we call this function before unloading the module. +} + +#undef LOCTEXT_NAMESPACE + +IMPLEMENT_MODULE(FVaRestEditorModule, VaRestEditor) diff --git a/Source/VaRestEditorPlugin/Private/VaRest_BreakJson.cpp b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp similarity index 93% rename from Source/VaRestEditorPlugin/Private/VaRest_BreakJson.cpp rename to Source/VaRestEditor/Private/VaRest_BreakJson.cpp index 1a14290f..b61f76af 100644 --- a/Source/VaRestEditorPlugin/Private/VaRest_BreakJson.cpp +++ b/Source/VaRestEditor/Private/VaRest_BreakJson.cpp @@ -1,16 +1,16 @@ -// Copyright 2015 Vladimir Alyamkin. All Rights Reserved. +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. // Original code by https://github.com/unktomi #include "VaRest_BreakJson.h" + #include "BlueprintActionDatabaseRegistrar.h" #include "BlueprintNodeSpawner.h" #include "EdGraph/EdGraph.h" #include "EdGraph/EdGraphNodeUtils.h" // for FNodeTextCache #include "EdGraphSchema_K2.h" +#include "EdGraphUtilities.h" #include "EditorCategoryUtils.h" #include "KismetCompiler.h" - -#include "EdGraphUtilities.h" #include "Runtime/Launch/Resources/Version.h" #define LOCTEXT_NAMESPACE "VaRest_BreakJson" @@ -39,7 +39,7 @@ class FKCHandler_BreakJson : public FNodeHandlingFunctor } UEdGraphPin* InNet = FEdGraphUtilities::GetNetFromPin(InputPin); - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRestPlugin.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); FBPTerminal** SourceTerm = Context.NetMap.Find(InNet); if (SourceTerm == nullptr) @@ -194,7 +194,7 @@ void UVaRest_BreakJson::AllocateDefaultPins() { const UEdGraphSchema_K2* K2Schema = GetDefault(); - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRestPlugin.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); UEdGraphPin* Pin = CreatePin(EGPD_Input, K2Schema->PC_Object, TEXT(""), Class, TEXT("Target")); #if ENGINE_MINOR_VERSION >= 17 @@ -213,15 +213,11 @@ FLinearColor UVaRest_BreakJson::GetNodeTitleColor() const void UVaRest_BreakJson::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) { - bool bIsDirty = false; - FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None; - if (true || PropertyName == TEXT("Outputs")) - { - bIsDirty = true; - } - - if (bIsDirty) + if (PropertyName == GET_MEMBER_NAME_STRING_CHECKED(UVaRest_BreakJson, Outputs) || + PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Name) || + PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Type) || + PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, bIsArray)) { ReconstructNode(); GetGraph()->NotifyGraphChanged(); @@ -266,7 +262,7 @@ FText UVaRest_BreakJson::GetMenuCategory() const void UVaRest_BreakJson::CreateProjectionPins(UEdGraphPin* Source) { const UEdGraphSchema_K2* K2Schema = GetDefault(); - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRestPlugin.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); for (TArray::TIterator it(Outputs); it; ++it) { @@ -277,7 +273,7 @@ void UVaRest_BreakJson::CreateProjectionPins(UEdGraphPin* Source) #endif UObject* Subtype = nullptr; - FString FieldName = (*it).Name; + FString FieldName = (*it).Name.ToString(); switch ((*it).Type) { @@ -301,7 +297,7 @@ void UVaRest_BreakJson::CreateProjectionPins(UEdGraphPin* Source) UEdGraphNode::FCreatePinParams OutputPinParams; OutputPinParams.ContainerType = (*it).bIsArray ? EPinContainerType::Array : EPinContainerType::None; - UEdGraphPin* OutputPin = CreatePin(EGPD_Output, Type, TEXT(""), Subtype, FName(*(*it).Name), OutputPinParams); + UEdGraphPin* OutputPin = CreatePin(EGPD_Output, Type, TEXT(""), Subtype, FName((*(*it).Name.ToString())), OutputPinParams); } } @@ -333,7 +329,7 @@ class FKCHandler_MakeJson : public FNodeHandlingFunctor } } - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRestPlugin.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); FBPTerminal** TargetTerm = Context.NetMap.Find(OutputPin); if (TargetTerm == nullptr) @@ -341,7 +337,7 @@ class FKCHandler_MakeJson : public FNodeHandlingFunctor return; } { - FName FunctionName = TEXT("ConstructJsonObject"); + FName FunctionName = TEXT("ConstructVaRestJsonObject"); UFunction* FunctionPtr = Class->FindFunctionByName(FunctionName); FBlueprintCompiledStatement& Statement = Context.AppendStatementForNode(Node); Statement.Type = KCST_CallFunction; @@ -489,7 +485,7 @@ void UVaRest_MakeJson::AllocateDefaultPins() { const UEdGraphSchema_K2* K2Schema = GetDefault(); - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRestPlugin.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); UEdGraphPin* Pin = CreatePin(EGPD_Output, K2Schema->PC_Object, TEXT(""), Class, TEXT("Target")); #if ENGINE_MINOR_VERSION >= 17 @@ -508,15 +504,11 @@ FLinearColor UVaRest_MakeJson::GetNodeTitleColor() const void UVaRest_MakeJson::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) { - bool bIsDirty = false; - FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None; - if (true || PropertyName == TEXT("Inputs")) - { - bIsDirty = true; - } - - if (bIsDirty) + if (PropertyName == GET_MEMBER_NAME_STRING_CHECKED(UVaRest_MakeJson, Inputs) || + PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Name) || + PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, Type) || + PropertyName == GET_MEMBER_NAME_STRING_CHECKED(FVaRest_NamedType, bIsArray)) { ReconstructNode(); GetGraph()->NotifyGraphChanged(); @@ -561,13 +553,13 @@ FText UVaRest_MakeJson::GetMenuCategory() const void UVaRest_MakeJson::CreateProjectionPins(UEdGraphPin* Source) { const UEdGraphSchema_K2* K2Schema = GetDefault(); - UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRestPlugin.VaRestJsonObject'"))); + UClass* Class = Cast(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRest.VaRestJsonObject'"))); for (TArray::TIterator it(Inputs); it; ++it) { FName Type; UObject* Subtype = nullptr; - FString FieldName = (*it).Name; + FString FieldName = (*it).Name.ToString(); switch ((*it).Type) { @@ -591,7 +583,7 @@ void UVaRest_MakeJson::CreateProjectionPins(UEdGraphPin* Source) UEdGraphNode::FCreatePinParams InputPinParams; InputPinParams.ContainerType = (*it).bIsArray ? EPinContainerType::Array : EPinContainerType::None; - UEdGraphPin* InputPin = CreatePin(EGPD_Input, Type, TEXT(""), Subtype, FName(*(*it).Name), InputPinParams); + UEdGraphPin* InputPin = CreatePin(EGPD_Input, Type, TEXT(""), Subtype, FName((*(*it).Name.ToString())), InputPinParams); #if ENGINE_MINOR_VERSION >= 20 InputPin->SetSavePinIfOrphaned(false); diff --git a/Source/VaRestEditorPlugin/Public/VaRestEditorPlugin.h b/Source/VaRestEditor/Public/VaRestEditor.h similarity index 53% rename from Source/VaRestEditorPlugin/Public/VaRestEditorPlugin.h rename to Source/VaRestEditor/Public/VaRestEditor.h index 6e1cb4a5..a51c92c9 100644 --- a/Source/VaRestEditorPlugin/Public/VaRestEditorPlugin.h +++ b/Source/VaRestEditor/Public/VaRestEditor.h @@ -1,11 +1,10 @@ -// Copyright 2015 Vladimir Alyamkin. All Rights Reserved. -// Original code by https://github.com/unktomi +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. #pragma once #include "Modules/ModuleManager.h" -class FVaRestEditorPluginModule : public IModuleInterface +class FVaRestEditorModule : public IModuleInterface { public: diff --git a/Source/VaRestEditorPlugin/Classes/VaRest_BreakJson.h b/Source/VaRestEditor/Public/VaRest_BreakJson.h similarity index 93% rename from Source/VaRestEditorPlugin/Classes/VaRest_BreakJson.h rename to Source/VaRestEditor/Public/VaRest_BreakJson.h index 8917b63f..dcdf51b5 100644 --- a/Source/VaRestEditorPlugin/Classes/VaRest_BreakJson.h +++ b/Source/VaRestEditor/Public/VaRest_BreakJson.h @@ -1,4 +1,4 @@ -// Copyright 2015 Vladimir Alyamkin. All Rights Reserved. +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. // Original code by https://github.com/unktomi #pragma once @@ -30,7 +30,7 @@ struct FVaRest_NamedType GENERATED_USTRUCT_BODY(); UPROPERTY(EditAnywhere, Category = NamedType) - FString Name; + FText Name; UPROPERTY(EditAnywhere, Category = NamedType) EVaRest_JsonType Type; @@ -40,7 +40,7 @@ struct FVaRest_NamedType }; UCLASS(BlueprintType, Blueprintable) -class VARESTEDITORPLUGIN_API UVaRest_MakeJson : public UK2Node +class VARESTEDITOR_API UVaRest_MakeJson : public UK2Node { GENERATED_UCLASS_BODY() @@ -69,7 +69,7 @@ class VARESTEDITORPLUGIN_API UVaRest_MakeJson : public UK2Node }; UCLASS(BlueprintType, Blueprintable) -class VARESTEDITORPLUGIN_API UVaRest_BreakJson : public UK2Node +class VARESTEDITOR_API UVaRest_BreakJson : public UK2Node { GENERATED_UCLASS_BODY() diff --git a/Source/VaRestEditorPlugin/VaRestEditorPlugin.Build.cs b/Source/VaRestEditor/VaRestEditor.Build.cs similarity index 83% rename from Source/VaRestEditorPlugin/VaRestEditorPlugin.Build.cs rename to Source/VaRestEditor/VaRestEditor.Build.cs index e684e83e..a12c78e7 100644 --- a/Source/VaRestEditorPlugin/VaRestEditorPlugin.Build.cs +++ b/Source/VaRestEditor/VaRestEditor.Build.cs @@ -1,16 +1,16 @@ -// Copyright 2015 Vladimir Alyamkin. All Rights Reserved. +// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved. using UnrealBuildTool; -public class VaRestEditorPlugin : ModuleRules +public class VaRestEditor : ModuleRules { - public VaRestEditorPlugin(ReadOnlyTargetRules Target) : base(Target) + public VaRestEditor(ReadOnlyTargetRules Target) : base(Target) { PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; PrivateIncludePaths.AddRange( new string[] { - "VaRestEditorPlugin/Private", + "VaRestEditor/Private", // ... add other private include paths required here ... }); @@ -20,7 +20,7 @@ public VaRestEditorPlugin(ReadOnlyTargetRules Target) : base(Target) new string[] { "Core", - "VaRestPlugin" + "VaRest" // ... add other public dependencies that you statically link with here ... }); diff --git a/Source/VaRestEditorPlugin/Private/VaRestEditorPlugin.cpp b/Source/VaRestEditorPlugin/Private/VaRestEditorPlugin.cpp deleted file mode 100644 index 19f843be..00000000 --- a/Source/VaRestEditorPlugin/Private/VaRestEditorPlugin.cpp +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2015 Vladimir Alyamkin. All Rights Reserved. -// Original code by https://github.com/unktomi - -#include "VaRestEditorPlugin.h" - -#define LOCTEXT_NAMESPACE "FVaRestEditorPluginModule" - -void FVaRestEditorPluginModule::StartupModule() -{ - // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module -} - -void FVaRestEditorPluginModule::ShutdownModule() -{ - // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, - // we call this function before unloading the module. -} - -#undef LOCTEXT_NAMESPACE - -IMPLEMENT_MODULE(FVaRestEditorPluginModule, VaRestEditorPlugin) diff --git a/Source/VaRestPlugin/Private/VaRestLibrary.cpp b/Source/VaRestPlugin/Private/VaRestLibrary.cpp deleted file mode 100644 index 13893b64..00000000 --- a/Source/VaRestPlugin/Private/VaRestLibrary.cpp +++ /dev/null @@ -1,127 +0,0 @@ -// Copyright 2016 Vladimir Alyamkin. All Rights Reserved. - -#include "VaRestLibrary.h" -#include "Misc/Base64.h" -#include "VaRestJsonObject.h" -#include "VaRestPluginPrivatePCH.h" -#include "VaRestRequestJSON.h" - -////////////////////////////////////////////////////////////////////////// -// Helpers - -FString UVaRestLibrary::PercentEncode(const FString& Source) -{ - return FGenericPlatformHttp::UrlEncode(Source); -} - -FString UVaRestLibrary::Base64Encode(const FString& Source) -{ - return FBase64::Encode(Source); -} - -bool UVaRestLibrary::Base64Decode(const FString& Source, FString& Dest) -{ - return FBase64::Decode(Source, Dest); -} - -bool UVaRestLibrary::Base64EncodeData(const TArray& Data, FString& Dest) -{ - if (Data.Num() > 0) - { - Dest = FBase64::Encode(Data); - return true; - } - - return false; -} - -bool UVaRestLibrary::Base64DecodeData(const FString& Source, TArray& Dest) -{ - return FBase64::Decode(Source, Dest); -} - -////////////////////////////////////////////////////////////////////////// -// File system integration - -class UVaRestJsonObject* UVaRestLibrary::LoadJsonFromFile(UObject* WorldContextObject, const FString& Path, const bool bIsRelativeToContentDir) -{ - UVaRestJsonObject* Json = UVaRestJsonObject::ConstructJsonObject(WorldContextObject); - - FString JSONString; - if (FFileHelper::LoadFileToString(JSONString, *(bIsRelativeToContentDir ? FPaths::ProjectContentDir() / Path : Path))) - { - if (Json->DecodeJson(JSONString)) - { - return Json; - } - else - { - UE_LOG(LogVaRest, Error, TEXT("%s: Can't decode json from file %s"), *VA_FUNC_LINE, *Path); - } - } - else - { - UE_LOG(LogVaRest, Error, TEXT("%s: Can't open file %s"), *VA_FUNC_LINE, *Path); - } - - return nullptr; -} - -////////////////////////////////////////////////////////////////////////// -// Easy URL processing - -TMap UVaRestLibrary::RequestMap; - -void UVaRestLibrary::CallURL(UObject* WorldContextObject, const FString& URL, ERequestVerb Verb, ERequestContentType ContentType, UVaRestJsonObject* VaRestJson, const FVaRestCallDelegate& Callback) -{ - UWorld* World = GEngine->GetWorldFromContextObjectChecked(WorldContextObject); - if (World == nullptr) - { - UE_LOG(LogVaRest, Error, TEXT("UVaRestLibrary: Wrong world context")) - return; - } - - // Check we have valid data json - if (VaRestJson == nullptr) - { - VaRestJson = UVaRestJsonObject::ConstructJsonObject(WorldContextObject); - } - - UVaRestRequestJSON* Request = NewObject(); - - Request->SetVerb(Verb); - Request->SetContentType(ContentType); - Request->SetRequestObject(VaRestJson); - - FVaRestCallResponse Response; - Response.Request = Request; - Response.WorldContextObject = WorldContextObject; - Response.Callback = Callback; - - Response.CompleteDelegateHandle = Request->OnStaticRequestComplete.AddStatic(&UVaRestLibrary::OnCallComplete); - Response.FailDelegateHandle = Request->OnStaticRequestFail.AddStatic(&UVaRestLibrary::OnCallComplete); - - RequestMap.Add(Request, Response); - - Request->ResetResponseData(); - Request->ProcessURL(URL); -} - -void UVaRestLibrary::OnCallComplete(UVaRestRequestJSON* Request) -{ - if (!RequestMap.Contains(Request)) - { - return; - } - - FVaRestCallResponse* Response = RequestMap.Find(Request); - - Request->OnStaticRequestComplete.Remove(Response->CompleteDelegateHandle); - Request->OnStaticRequestFail.Remove(Response->FailDelegateHandle); - - Response->Callback.ExecuteIfBound(Request); - - Response->WorldContextObject = nullptr; - Response->Request = nullptr; - RequestMap.Remove(Request); -} diff --git a/Source/VaRestPlugin/Private/VaRestPlugin.cpp b/Source/VaRestPlugin/Private/VaRestPlugin.cpp deleted file mode 100644 index 7bef598b..00000000 --- a/Source/VaRestPlugin/Private/VaRestPlugin.cpp +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2014 Vladimir Alyamkin. All Rights Reserved. - -#include "VaRestPlugin.h" -#include "VaRestJsonObject.h" -#include "VaRestJsonValue.h" -#include "VaRestPluginPrivatePCH.h" -#include "VaRestRequestJSON.h" -#include "VaRestSettings.h" - -//#include "UObject/Package.h" -//#include "Misc/ConfigCacheIni.h" - -#include "Developer/Settings/Public/ISettingsModule.h" - -#define LOCTEXT_NAMESPACE "VaRest" - -class FVaRestPlugin : public IVaRestPlugin -{ - /** IModuleInterface implementation */ - virtual void StartupModule() override - { - // @HACK Force classes to be compiled on shipping build - UVaRestJsonObject::StaticClass(); - UVaRestJsonValue::StaticClass(); - UVaRestRequestJSON::StaticClass(); - - // Register settings - if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr("Settings")) - { - SettingsModule->RegisterSettings("Project", "Plugins", "VaRest", - LOCTEXT("RuntimeSettingsName", "VaRest Kit"), - LOCTEXT("RuntimeSettingsDescription", "Configure API keys for VaRest"), - GetMutableDefault()); - } - } - - virtual void ShutdownModule() override - { - if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr("Settings")) - { - SettingsModule->UnregisterSettings("Project", "Plugins", "VaRest"); - } - } -}; - -IMPLEMENT_MODULE(FVaRestPlugin, VaRestPlugin) - -DEFINE_LOG_CATEGORY(LogVaRest); - -#undef LOCTEXT_NAMESPACE diff --git a/Source/VaRestPlugin/Public/VaRestPlugin.h b/Source/VaRestPlugin/Public/VaRestPlugin.h deleted file mode 100644 index 52b1938a..00000000 --- a/Source/VaRestPlugin/Public/VaRestPlugin.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2014 Vladimir Alyamkin. All Rights Reserved. - -#pragma once - -#include "Modules/ModuleManager.h" - -/** - * The public interface to this module. In most cases, this interface is only public to sibling modules - * within this plugin. - */ -class IVaRestPlugin : public IModuleInterface -{ - -public: - /** - * Singleton-like access to this module's interface. This is just for convenience! - * Beware of calling this during the shutdown phase, though. Your module might have been unloaded already. - * - * @return Returns singleton instance, loading the module on demand if needed - */ - static inline IVaRestPlugin& Get() - { - return FModuleManager::LoadModuleChecked("VaRestPlugin"); - } - - /** - * Checks to see if this module is loaded and ready. It is only valid to call Get() if IsAvailable() returns true. - * - * @return True if the module is loaded and ready to use - */ - static inline bool IsAvailable() - { - return FModuleManager::Get().IsModuleLoaded("VaRestPlugin"); - } -}; diff --git a/VaRestPlugin.uplugin b/VaRest.uplugin similarity index 66% rename from VaRestPlugin.uplugin rename to VaRest.uplugin index be5ac78b..4ad50f91 100644 --- a/VaRestPlugin.uplugin +++ b/VaRest.uplugin @@ -2,11 +2,11 @@ "FileVersion" : 3, "FriendlyName" : "VaRest", - "Version" : 26, - "VersionName" : "1.1-r26", + "Version" : 27, + "VersionName" : "1.1-r27", "CreatedBy" : "Vladimir Alyamkin", - "CreatedByURL" : "http://alyamkin.com", - "EngineVersion" : "4.23.0", + "CreatedByURL" : "https://alyamkin.com", + "EngineVersion" : "4.24.0", "Description" : "Plugin that makes REST (JSON) server communication easy to use", "Category" : "Network", "MarketplaceURL" : "com.epicgames.launcher://ue/marketplace/content/e47be161e7a24e928560290abd5dcc4f", @@ -14,13 +14,13 @@ "Modules" : [ { - "Name" : "VaRestPlugin", + "Name" : "VaRest", "Type" : "Runtime", "LoadingPhase": "PreDefault" }, { - "Name": "VaRestEditorPlugin", - "Type": "Developer" + "Name": "VaRestEditor", + "Type": "UncookedOnly" } ] } \ No newline at end of file