Skip to content

Commit

Permalink
Finish v1.1-r27.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ufna committed Jan 9, 2020
2 parents 4a925ea + 8b469fb commit 2c7c7ef
Show file tree
Hide file tree
Showing 33 changed files with 407 additions and 360 deletions.
14 changes: 14 additions & 0 deletions Config/BaseVaRest.ini
Original file line number Diff line number Diff line change
@@ -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")
14 changes: 14 additions & 0 deletions Config/DefaultVaRest.ini
Original file line number Diff line number Diff line change
@@ -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")
1 change: 1 addition & 0 deletions Config/FilterPlugin.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[FilterPlugin]
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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)

Expand Down
96 changes: 96 additions & 0 deletions Source/VaRest/Private/VaRest.cpp
Original file line number Diff line number Diff line change
@@ -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<UVaRestSettings>(GetTransientPackage(), "VaRestSettings", RF_Standalone);
VaRestSettings->AddToRoot();

// Register settings
if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("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<UVaRestRequestController>(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<ISettingsModule>("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
Original file line number Diff line number Diff line change
@@ -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<TCHAR, TCondensedJsonPrintPolicy<TCHAR>> FCondensedJsonStringWriterFactory;
typedef TJsonWriter<TCHAR, TCondensedJsonPrintPolicy<TCHAR>> FCondensedJsonStringWriter;

UVaRestJsonObject::UVaRestJsonObject(const class FObjectInitializer& PCIP)
: Super(PCIP)
UVaRestJsonObject::UVaRestJsonObject(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
, JsonObj(MakeShared<FJsonObject>())
{
}

UVaRestJsonObject* UVaRestJsonObject::ConstructJsonObject(UObject* WorldContextObject)
UVaRestJsonObject* UVaRestJsonObject::ConstructVaRestJsonObject(UObject* WorldContextObject)
{
return NewObject<UVaRestJsonObject>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -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)
{
}

Expand Down
72 changes: 72 additions & 0 deletions Source/VaRest/Private/VaRestLibrary.cpp
Original file line number Diff line number Diff line change
@@ -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<uint8>& Data, FString& Dest)
{
if (Data.Num() > 0)
{
Dest = FBase64::Encode(Data);
return true;
}

return false;
}

bool UVaRestLibrary::Base64DecodeData(const FString& Source, TArray<uint8>& 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;
}
14 changes: 14 additions & 0 deletions Source/VaRest/Private/VaRestRequestController.cpp
Original file line number Diff line number Diff line change
@@ -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()
{
}
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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* 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);
Expand Down Expand Up @@ -145,7 +146,7 @@ void UVaRestRequestJSON::Cancel()
//////////////////////////////////////////////////////////////////////////
// JSON data accessors

UVaRestJsonObject* UVaRestRequestJSON::GetRequestObject()
UVaRestJsonObject* UVaRestRequestJSON::GetRequestObject() const
{
return RequestJsonObj;
}
Expand All @@ -155,7 +156,7 @@ void UVaRestRequestJSON::SetRequestObject(UVaRestJsonObject* JsonObject)
RequestJsonObj = JsonObject;
}

UVaRestJsonObject* UVaRestRequestJSON::GetResponseObject()
UVaRestJsonObject* UVaRestRequestJSON::GetResponseObject() const
{
return ResponseJsonObj;
}
Expand All @@ -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;

Expand All @@ -196,7 +197,7 @@ FString UVaRestRequestJSON::GetResponseHeader(const FString HeaderName)
return Result;
}

TArray<FString> UVaRestRequestJSON::GetAllResponseHeaders()
TArray<FString> UVaRestRequestJSON::GetAllResponseHeaders() const
{
TArray<FString> Result;
for (TMap<FString, FString>::TConstIterator It(ResponseHeaders); It; ++It)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018 Vladimir Alyamkin. All Rights Reserved.
// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved.

#include "VaRestSettings.h"

Expand Down

0 comments on commit 2c7c7ef

Please sign in to comment.