Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Finish v1.1-r18
Browse files Browse the repository at this point in the history
  • Loading branch information
ufna committed Aug 16, 2017
2 parents c75059f + 739eff5 commit b3830ae
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 42 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Key features:

Check the [Wiki](https://hiazma.atlassian.net/wiki/display/VAR) for plugin usage examples and installation notes.

Current version: **1.1 R 16** (UE 4.11-4.13)
Current version: **1.1 R 18** (UE 4.16-4.17)

![SCREENSHOT](SCREENSHOT.jpg)

Expand All @@ -23,5 +23,5 @@ Legal info

Unreal® is a trademark or registered trademark of Epic Games, Inc. in the United States of America and elsewhere.

Unreal® Engine, Copyright 1998 – 2014, Epic Games, Inc. All rights reserved.
Unreal® Engine, Copyright 1998 – 2017, Epic Games, Inc. All rights reserved.

7 changes: 7 additions & 0 deletions Source/VaRestEditorPlugin/Classes/VaRest_BreakJson.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@

#pragma once

#include "Runtime/Launch/Resources/Version.h"

#if ENGINE_MINOR_VERSION >= 15
#include "CoreMinimal.h"
#else
#include "Engine.h"
#endif

#include "K2Node.h"

#include "VaRest_BreakJson.generated.h"
Expand Down
9 changes: 9 additions & 0 deletions Source/VaRestEditorPlugin/Private/VaRest_BreakJson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "VaRest_BreakJson.h"

#include "Runtime/Launch/Resources/Version.h"
#include "EdGraphUtilities.h"

#define LOCTEXT_NAMESPACE "VaRest_BreakJson"

Expand Down Expand Up @@ -68,7 +69,11 @@ class FKCHandler_BreakJson : public FNodeHandlingFunctor
FBlueprintCompiledStatement& Statement = Context.AppendStatementForNode(Node);
FName FunctionName;

#if ENGINE_MINOR_VERSION >= 17
bool bIsArray = Pin->PinType.IsArray();
#else
bool bIsArray = Pin->PinType.bIsArray;
#endif

if (FieldType == CompilerContext.GetSchema()->PC_Boolean)
{
Expand Down Expand Up @@ -180,7 +185,11 @@ void UVaRest_BreakJson::AllocateDefaultPins()
UClass *Class = Cast<UClass>(StaticLoadObject(UClass::StaticClass(), NULL, TEXT("class'VaRestPlugin.VaRestJsonObject'")));
UEdGraphPin* Pin = CreatePin(EGPD_Input, K2Schema->PC_Object, TEXT(""), Class, false, false, TEXT("Target"));

#if ENGINE_MINOR_VERSION >= 17
K2Schema->SetPinAutogeneratedDefaultValueBasedOnType(Pin);
#else
K2Schema->SetPinDefaultValueBasedOnType(Pin);
#endif

CreateProjectionPins(Pin);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/VaRestEditorPlugin/VaRestEditorPlugin.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class VaRestEditorPlugin : ModuleRules
{
public VaRestEditorPlugin(TargetInfo Target)
public VaRestEditorPlugin(ReadOnlyTargetRules Target) : base(Target)
{

PublicIncludePaths.AddRange(
Expand Down
18 changes: 13 additions & 5 deletions Source/VaRestPlugin/Classes/VaRestJsonObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class VARESTPLUGIN_API UVaRestJsonObject : public UObject

/** Get the field named FieldName as a Json Array */
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
TArray<UVaRestJsonValue*> GetArrayField(const FString& FieldName);
TArray<UVaRestJsonValue*> GetArrayField(const FString& FieldName) const;

/** Set an ObjectField named FieldName and value of Json Array */
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
Expand All @@ -95,6 +95,14 @@ class VARESTPLUGIN_API UVaRestJsonObject : public UObject
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetNumberField(const FString& FieldName, float Number);

/** Get the field named FieldName as an Integer. Ensures that the field is present and is of type Json number. */
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
int32 GetIntegerField(const FString& FieldName) const;

/** Add a field named FieldName with Integer as value. */
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetIntegerField(const FString& FieldName, int32 Number);

/** Get the field named FieldName as a string. */
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
FString GetStringField(const FString& FieldName) const;
Expand Down Expand Up @@ -126,7 +134,7 @@ class VARESTPLUGIN_API UVaRestJsonObject : public UObject
/** Get the field named FieldName as a Number Array. Use it only if you're sure that array is uniform!
* Attn.!! float used instead of double to make the function blueprintable! */
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
TArray<float> GetNumberArrayField(const FString& FieldName);
TArray<float> GetNumberArrayField(const FString& FieldName) const;

/** Set an ObjectField named FieldName and value of Number Array
* Attn.!! float used instead of double to make the function blueprintable! */
Expand All @@ -135,23 +143,23 @@ class VARESTPLUGIN_API UVaRestJsonObject : public UObject

/** Get the field named FieldName as a String Array. Use it only if you're sure that array is uniform! */
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
TArray<FString> GetStringArrayField(const FString& FieldName);
TArray<FString> GetStringArrayField(const FString& FieldName) const;

/** Set an ObjectField named FieldName and value of String Array */
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetStringArrayField(const FString& FieldName, const TArray<FString>& StringArray);

/** Get the field named FieldName as a Bool Array. Use it only if you're sure that array is uniform! */
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
TArray<bool> GetBoolArrayField(const FString& FieldName);
TArray<bool> GetBoolArrayField(const FString& FieldName) const;

/** Set an ObjectField named FieldName and value of Bool Array */
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetBoolArrayField(const FString& FieldName, const TArray<bool>& BoolArray);

/** Get the field named FieldName as an Object Array. Use it only if you're sure that array is uniform! */
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
TArray<UVaRestJsonObject*> GetObjectArrayField(const FString& FieldName);
TArray<UVaRestJsonObject*> GetObjectArrayField(const FString& FieldName) const;

/** Set an ObjectField named FieldName and value of Ob Array */
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
Expand Down
2 changes: 1 addition & 1 deletion Source/VaRestPlugin/Classes/VaRestJsonValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace EVaJson
* Blueprintable FJsonValue wrapper
*/
UCLASS(BlueprintType, Blueprintable)
class UVaRestJsonValue : public UObject
class VARESTPLUGIN_API UVaRestJsonValue : public UObject
{
GENERATED_UCLASS_BODY()

Expand Down
21 changes: 20 additions & 1 deletion Source/VaRestPlugin/Classes/VaRestLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct FVaRestCallResponse
, WorldContextObject(nullptr)
{
}

};

/**
Expand Down Expand Up @@ -73,6 +73,25 @@ class UVaRestLibrary : public UBlueprintFunctionLibrary
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "Base64 Decode"))
static bool Base64Decode(const FString& Source, FString& Dest);

/**
* Encodes a byte array into a Base64 string
*
* @param Dara The data to convert
* @return A string that encodes the binary data in a way that can be safely transmitted via various Internet protocols
*/
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "Base64 Encode Data"))
static bool Base64EncodeData(const TArray<uint8>& Data, FString& Dest);

/**
* Decodes a Base64 string into a byte array
*
* @param Source The stringified data to convert
* @param Dest The out buffer that will be filled with the decoded data
* @return True if the buffer was decoded, false if it failed to decode
*/
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility", meta = (DisplayName = "Base64 Decode Data"))
static bool Base64DecodeData(const FString& Source, TArray<uint8>& Dest);


//////////////////////////////////////////////////////////////////////////
// Easy URL processing
Expand Down
26 changes: 19 additions & 7 deletions Source/VaRestPlugin/Classes/VaRestRequestJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

#pragma once

#include "Delegate.h"
#include "Engine/LatentActionManager.h"
#include "Http.h"
#include "Map.h"
#include "Json.h"

#include "VaRestTypes.h"
#include "VaRestRequestJSON.generated.h"
Expand Down Expand Up @@ -115,6 +113,10 @@ class VARESTPLUGIN_API UVaRestRequestJSON : public UObject
UFUNCTION(BlueprintCallable, Category = "VaRest|Request")
void SetBinaryRequestContent(const TArray<uint8> &Content);

/** Set content of the request as a plain string */
UFUNCTION(BlueprintCallable, Category = "VaRest|Request")
void SetStringRequestContent(const FString &Content);

/** Sets optional header info */
UFUNCTION(BlueprintCallable, Category = "VaRest|Request")
void SetHeader(const FString& HeaderName, const FString& HeaderValue);
Expand Down Expand Up @@ -187,6 +189,11 @@ class VARESTPLUGIN_API UVaRestRequestJSON : public UObject
//////////////////////////////////////////////////////////////////////////
// URL processing

public:
/** Setting request URL */
UFUNCTION(BlueprintCallable, Category = "VaRest|Request")
void SetURL(const FString& Url = TEXT("http://alyamkin.com"));

/** Open URL with current setup */
UFUNCTION(BlueprintCallable, Category = "VaRest|Request")
virtual void ProcessURL(const FString& Url = TEXT("http://alyamkin.com"));
Expand All @@ -195,10 +202,14 @@ class VARESTPLUGIN_API UVaRestRequestJSON : public UObject
UFUNCTION(BlueprintCallable, Category = "VaRest|Request", meta = (Latent, LatentInfo = "LatentInfo", HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"))
virtual void ApplyURL(const FString& Url, UVaRestJsonObject *&Result, UObject* WorldContextObject, struct FLatentActionInfo LatentInfo);

/** Check URL and execute process request */
UFUNCTION(BlueprintCallable, Category = "VaRest|Request")
virtual void ExecuteProcessRequest();

protected:
/** Apply current internal setup to request and process it */
void ProcessRequest();


//////////////////////////////////////////////////////////////////////////
// Request callbacks

Expand Down Expand Up @@ -267,12 +278,13 @@ class VARESTPLUGIN_API UVaRestRequestJSON : public UObject
UPROPERTY()
UVaRestJsonObject* RequestJsonObj;

UPROPERTY()
TArray<uint8> RequestBytes;

UPROPERTY()
FString BinaryContentType;

/** Used for special cases when used wants to have plain string data in request.
* Attn.! Content-type x-www-form-urlencoded only. */
FString StringRequestContent;

/** Response data stored as JSON */
UPROPERTY()
UVaRestJsonObject* ResponseJsonObj;
Expand Down
31 changes: 26 additions & 5 deletions Source/VaRestPlugin/Private/VaRestJsonObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,27 @@ void UVaRestJsonObject::SetNumberField(const FString& FieldName, float Number)
JsonObj->SetNumberField(FieldName, Number);
}

int32 UVaRestJsonObject::GetIntegerField(const FString& FieldName) const
{
if (!JsonObj.IsValid() || !JsonObj->HasTypedField<EJson::Number>(FieldName))
{
UE_LOG(LogVaRest, Warning, TEXT("No field with name %s of type Number"), *FieldName);
return 0;
}

return JsonObj->GetIntegerField(FieldName);
}

void UVaRestJsonObject::SetIntegerField(const FString& FieldName, int32 Number)
{
if (!JsonObj.IsValid() || FieldName.IsEmpty())
{
return;
}

JsonObj->SetNumberField(FieldName, Number);
}

FString UVaRestJsonObject::GetStringField(const FString& FieldName) const
{
if (!JsonObj.IsValid() || !JsonObj->HasTypedField<EJson::String>(FieldName))
Expand Down Expand Up @@ -217,7 +238,7 @@ void UVaRestJsonObject::SetBoolField(const FString& FieldName, bool InValue)
JsonObj->SetBoolField(FieldName, InValue);
}

TArray<UVaRestJsonValue*> UVaRestJsonObject::GetArrayField(const FString& FieldName)
TArray<UVaRestJsonValue*> UVaRestJsonObject::GetArrayField(const FString& FieldName) const
{
if (!JsonObj->HasTypedField<EJson::Array>(FieldName))
{
Expand Down Expand Up @@ -338,7 +359,7 @@ void UVaRestJsonObject::SetObjectField(const FString& FieldName, UVaRestJsonObje
//////////////////////////////////////////////////////////////////////////
// Array fields helpers (uniform arrays)

TArray<float> UVaRestJsonObject::GetNumberArrayField(const FString& FieldName)
TArray<float> UVaRestJsonObject::GetNumberArrayField(const FString& FieldName) const
{
if (!JsonObj->HasTypedField<EJson::Array>(FieldName))
{
Expand Down Expand Up @@ -383,7 +404,7 @@ void UVaRestJsonObject::SetNumberArrayField(const FString& FieldName, const TArr
JsonObj->SetArrayField(FieldName, EntriesArray);
}

TArray<FString> UVaRestJsonObject::GetStringArrayField(const FString& FieldName)
TArray<FString> UVaRestJsonObject::GetStringArrayField(const FString& FieldName) const
{
if (!JsonObj->HasTypedField<EJson::Array>(FieldName))
{
Expand Down Expand Up @@ -427,7 +448,7 @@ void UVaRestJsonObject::SetStringArrayField(const FString& FieldName, const TArr
JsonObj->SetArrayField(FieldName, EntriesArray);
}

TArray<bool> UVaRestJsonObject::GetBoolArrayField(const FString& FieldName)
TArray<bool> UVaRestJsonObject::GetBoolArrayField(const FString& FieldName) const
{
if (!JsonObj->HasTypedField<EJson::Array>(FieldName))
{
Expand Down Expand Up @@ -471,7 +492,7 @@ void UVaRestJsonObject::SetBoolArrayField(const FString& FieldName, const TArray
JsonObj->SetArrayField(FieldName, EntriesArray);
}

TArray<UVaRestJsonObject*> UVaRestJsonObject::GetObjectArrayField(const FString& FieldName)
TArray<UVaRestJsonObject*> UVaRestJsonObject::GetObjectArrayField(const FString& FieldName) const
{
if (!JsonObj->HasTypedField<EJson::Array>(FieldName))
{
Expand Down
22 changes: 19 additions & 3 deletions Source/VaRestPlugin/Private/VaRestLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
FString UVaRestLibrary::PercentEncode(const FString& Source)
{
FString OutText = Source;

OutText = OutText.Replace(TEXT(" "), TEXT("%20"));
OutText = OutText.Replace(TEXT("!"), TEXT("%21"));
OutText = OutText.Replace(TEXT("\""), TEXT("%22"));
Expand All @@ -32,7 +32,7 @@ FString UVaRestLibrary::PercentEncode(const FString& Source)
OutText = OutText.Replace(TEXT("]"), TEXT("%5D"));
OutText = OutText.Replace(TEXT("{"), TEXT("%7B"));
OutText = OutText.Replace(TEXT("}"), TEXT("%7D"));

return OutText;
}

Expand All @@ -46,6 +46,22 @@ 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);
}


//////////////////////////////////////////////////////////////////////////
// Easy URL processing
Expand All @@ -60,7 +76,7 @@ void UVaRestLibrary::CallURL(UObject* WorldContextObject, const FString& URL, ER
UE_LOG(LogVaRest, Error, TEXT("UVaRestLibrary: Wrong world context"))
return;
}

// Check we have valid data json
if (VaRestJson == nullptr)
{
Expand Down
13 changes: 10 additions & 3 deletions Source/VaRestPlugin/Private/VaRestPluginPrivatePCH.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,24 @@

#pragma once

#include "Runtime/Launch/Resources/Version.h"

#if ENGINE_MINOR_VERSION >= 15
#include "CoreMinimal.h"
#include "EngineDefines.h"
#include "Engine/Engine.h"
#include "UObject/Object.h"
#include "UObject/ScriptMacros.h"
#else
#include "CoreUObject.h"
#include "Engine.h"
#endif

#include "Delegate.h"
#include "Http.h"
#include "Map.h"
#include "Json.h"

#include "LatentActions.h"
#include "Core.h"
#include "Engine.h"
#include "SharedPointer.h"

// You should place include statements to your module's private header files here. You only need to
Expand Down
Loading

0 comments on commit b3830ae

Please sign in to comment.