diff --git a/README.md b/README.md index c05eab9d..46b3b0a8 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,10 @@ Key features: * Blueprintable FJsonObject wrapper with almost full support of Json features: different types of values, **arrays**, **binary data** content, both ways serializarion to FString, etc. * Blueprintable FJsonValue wrapper - **full Json features made for blueprints!** * Both bindable events and **latent functions** are provided to control the asynchronous requests -* [Parse](https://parse.com) REST API manager to start working with Parse out of the box! Check the [Wiki](https://github.com/ufna/VaRest/wiki) tab for plugin usage examples and installation notes. -Current version: **1.1 R 12** (UE 4.8-4.10) +Current version: **1.1 R 13** (UE 4.11) ![SCREENSHOT](SCREENSHOT.jpg) diff --git a/Source/VaRestEditorPlugin/Private/VaRest_BreakJson.cpp b/Source/VaRestEditorPlugin/Private/VaRest_BreakJson.cpp index 317a4a95..66cfeaaf 100644 --- a/Source/VaRestEditorPlugin/Private/VaRest_BreakJson.cpp +++ b/Source/VaRestEditorPlugin/Private/VaRest_BreakJson.cpp @@ -274,3 +274,5 @@ FText UVaRest_BreakJson::GetNodeTitle(ENodeTitleType::Type TitleType) const { return LOCTEXT("VaRest_Break_Json.NodeTitle", "Break Json"); } + +#undef LOCTEXT_NAMESPACE diff --git a/Source/VaRestPlugin/Classes/Json/VaRestRequestJSON.h b/Source/VaRestPlugin/Classes/Json/VaRestRequestJSON.h index 84c03549..faf5047a 100644 --- a/Source/VaRestPlugin/Classes/Json/VaRestRequestJSON.h +++ b/Source/VaRestPlugin/Classes/Json/VaRestRequestJSON.h @@ -69,7 +69,9 @@ namespace ERequestVerb GET, POST, PUT, - DEL UMETA(DisplayName="DELETE") + DEL UMETA(DisplayName="DELETE"), + /** Set CUSTOM verb by SetCustomVerb() function */ + CUSTOM }; } @@ -114,6 +116,10 @@ class VARESTPLUGIN_API UVaRestRequestJSON : public UObject UFUNCTION(BlueprintCallable, Category = "VaRest|Request") void SetVerb(ERequestVerb::Type Verb); + /** Set custom verb to the request */ + UFUNCTION(BlueprintCallable, Category = "VaRest|Request") + void SetCustomVerb(FString Verb); + /** Set content type to the request. If you're using the x-www-form-urlencoded, * params/constaints should be defined as key=ValueString pairs from Json data */ UFUNCTION(BlueprintCallable, Category = "VaRest|Request") @@ -268,4 +274,8 @@ class VARESTPLUGIN_API UVaRestRequestJSON : public UObject /** Http Response code */ int32 ResponseCode; + + /** Custom verb that will be used with RequestContentType == CUSTOM */ + FString CustomVerb; + }; diff --git a/Source/VaRestPlugin/Classes/Parse/VaRestParseManager.h b/Source/VaRestPlugin/Classes/Parse/VaRestParseManager.h deleted file mode 100644 index 50a53bef..00000000 --- a/Source/VaRestPlugin/Classes/Parse/VaRestParseManager.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2014 Vladimir Alyamkin. All Rights Reserved. - -#pragma once - -#include "VaRestParseManager.generated.h" - -/** - * Helper class to make Parse communication easier - */ -UCLASS(BlueprintType, Blueprintable) -class UVaRestParseManager : public UVaRestRequestJSON -{ - GENERATED_UCLASS_BODY() - - /** Creates new Parse request with defined verb and content type */ - UFUNCTION(BlueprintPure, meta = (DisplayName = "Construct Parse Request", HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"), Category = "VaRest|Parse") - static UVaRestParseManager* ConstructParseRequest(UObject* WorldContextObject, ERequestVerb::Type Verb, ERequestContentType::Type ContentType); - - /** Open the Parse URL (Attn.!! App Id and Api Key should be set before) */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Parse") - void ProcessParseURL(const FString& ParseModule = TEXT("classes"), const FString& ParseClass = TEXT("GameScore"), const FString& ParseObjectId = "", const FString& ParseSessionToken = ""); - - /** Set Parse authenication data */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Parse") - static void SetParseAuthData(FString AppId, FString ApiKey); - - - ////////////////////////////////////////////////////////////////////////// - // Quering helpers - - /** Create Json string that contains Pointer to the Parse Object */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Parse") - static FString ConstructPointer(const FString& ClassName, const FString& ObjectId); - - /** Create Json object that contains Pointer to the Parse Object */ - UFUNCTION(BlueprintPure, Category = "VaRest|Parse") - static UVaRestJsonObject* ConstructPointerObject(const FString& ClassName, const FString& ObjectId); - - /** Create Json object that contains a date */ - UFUNCTION(BlueprintPure, Category = "VaRest|Parse") - static UVaRestJsonObject* ConstructDateObject(const FDateTime& Date); - - /** Create Json object that instructs Parse to delete whatever field it is set to */ - UFUNCTION(BlueprintPure, Category = "VaRest|Parse") - static UVaRestJsonObject* ConstructDeleteOperation(); - - /** Create Json object that contains Facebook auth data */ - UFUNCTION(BlueprintPure, Category = "VaRest|Parse") - static UVaRestJsonObject* ConstructFacebookAuthDataObject(FString UserId, FString AccessToken, FString ExpirationDate); - - /** Construct simple WHERE query that contains only one condition. - * Attn!! String Values should containt quotes! */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Parse") - static FString ConstructWhereQuerySimple(const FString& Key, const FString& Value); - - /** Construct WHERE query based on conditions defined as Json */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Parse") - static FString ConstructWhereQuery(UVaRestJsonObject* JsonObject); - - /** A bit more happiness for our beautiful world */ - UFUNCTION(BlueprintCallable, Category = "VaRest|Parse") - static FString GetHappyMessage(); - - - ////////////////////////////////////////////////////////////////////////// - // Internal data -private: - /** Parse App Id */ - static FString ParseAppId; - - /** Parse Api Key */ - static FString ParseApiKey; - - /** Parse URL */ - static FString ParseURL; - -}; diff --git a/Source/VaRestPlugin/Private/Json/VaRestRequestJSON.cpp b/Source/VaRestPlugin/Private/Json/VaRestRequestJSON.cpp index be4cc09c..bbb57866 100644 --- a/Source/VaRestPlugin/Private/Json/VaRestRequestJSON.cpp +++ b/Source/VaRestPlugin/Private/Json/VaRestRequestJSON.cpp @@ -45,6 +45,11 @@ void UVaRestRequestJSON::SetVerb(ERequestVerb::Type Verb) RequestVerb = Verb; } +void UVaRestRequestJSON::SetCustomVerb(FString Verb) +{ + CustomVerb = Verb; +} + void UVaRestRequestJSON::SetContentType(ERequestContentType::Type ContentType) { RequestContentType = ContentType; @@ -239,19 +244,23 @@ void UVaRestRequestJSON::ProcessRequest(TSharedRef HttpRequest) switch (RequestVerb) { case ERequestVerb::GET: - HttpRequest->SetVerb("GET"); + HttpRequest->SetVerb(TEXT("GET")); break; case ERequestVerb::POST: - HttpRequest->SetVerb("POST"); + HttpRequest->SetVerb(TEXT("POST")); break; case ERequestVerb::PUT: - HttpRequest->SetVerb("PUT"); + HttpRequest->SetVerb(TEXT("PUT")); break; case ERequestVerb::DEL: - HttpRequest->SetVerb("DELETE"); + HttpRequest->SetVerb(TEXT("DELETE")); + break; + + case ERequestVerb::CUSTOM: + HttpRequest->SetVerb(CustomVerb); break; default: @@ -263,7 +272,7 @@ void UVaRestRequestJSON::ProcessRequest(TSharedRef HttpRequest) { case ERequestContentType::x_www_form_urlencoded_url: { - HttpRequest->SetHeader("Content-Type", "application/x-www-form-urlencoded"); + HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/x-www-form-urlencoded")); FString UrlParams = ""; uint16 ParamIdx = 0; @@ -290,7 +299,7 @@ void UVaRestRequestJSON::ProcessRequest(TSharedRef HttpRequest) } case ERequestContentType::x_www_form_urlencoded_body: { - HttpRequest->SetHeader("Content-Type", "application/x-www-form-urlencoded"); + HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/x-www-form-urlencoded")); FString UrlParams = ""; uint16 ParamIdx = 0; @@ -317,14 +326,14 @@ void UVaRestRequestJSON::ProcessRequest(TSharedRef HttpRequest) } case ERequestContentType::binary: { - HttpRequest->SetHeader("Content-Type", BinaryContentType); + HttpRequest->SetHeader(TEXT("Content-Type"), BinaryContentType); HttpRequest->SetContent(RequestBytes); break; } case ERequestContentType::json: { - HttpRequest->SetHeader("Content-Type", "application/json"); + HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json")); // Serialize data to json string FString OutputString; diff --git a/Source/VaRestPlugin/Private/Parse/VaRestParseManager.cpp b/Source/VaRestPlugin/Private/Parse/VaRestParseManager.cpp deleted file mode 100644 index 8d706c06..00000000 --- a/Source/VaRestPlugin/Private/Parse/VaRestParseManager.cpp +++ /dev/null @@ -1,138 +0,0 @@ -// Copyright 2014 Vladimir Alyamkin. All Rights Reserved. - -#include "VaRestPluginPrivatePCH.h" - -FString UVaRestParseManager::ParseURL(TEXT("https://api.parse.com/1/")); -FString UVaRestParseManager::ParseAppId(TEXT("")); -FString UVaRestParseManager::ParseApiKey(TEXT("")); - -UVaRestParseManager::UVaRestParseManager(const class FObjectInitializer& PCIP) - : Super(PCIP) -{ - -} - -UVaRestParseManager* UVaRestParseManager::ConstructParseRequest( - UObject* WorldContextObject, - ERequestVerb::Type Verb, - ERequestContentType::Type ContentType) -{ - return (UVaRestParseManager*)ConstructRequestExt(WorldContextObject, Verb, ContentType); -} - -void UVaRestParseManager::ProcessParseURL( - const FString& ParseModule, - const FString& ParseClass, - const FString& ParseObjectId, - const FString& ParseSessionToken) -{ - FString RequestUrl = ParseURL; - - // Build the full request url - if (!ParseModule.IsEmpty()) - { - RequestUrl += ParseModule; - - if (!ParseClass.IsEmpty()) - { - RequestUrl += "/" + ParseClass; - } - - if (!ParseObjectId.IsEmpty()) - { - RequestUrl += "/" + ParseObjectId; - } - } - - TSharedRef HttpRequest = FHttpModule::Get().CreateRequest(); - HttpRequest->SetURL(RequestUrl); - - HttpRequest->SetHeader("X-Parse-Application-Id", ParseAppId); - HttpRequest->SetHeader("X-Parse-REST-API-Key", ParseApiKey); - - if (!ParseSessionToken.IsEmpty()) - { - HttpRequest->SetHeader("X-Parse-Session-Token", ParseSessionToken); - } - - ProcessRequest(HttpRequest); -} - -void UVaRestParseManager::SetParseAuthData(FString AppId, FString ApiKey) -{ - ParseAppId = AppId; - ParseApiKey = ApiKey; -} - -////////////////////////////////////////////////////////////////////////// -// Quering helpers - -FString UVaRestParseManager::ConstructPointer(const FString& ClassName, const FString& ObjectId) -{ - return FString::Printf(TEXT("{\"__type\":\"Pointer\",\"className\":\"%s\",\"objectId\":\"%s\"}"), *ClassName, *ObjectId); -} - -UVaRestJsonObject* UVaRestParseManager::ConstructPointerObject(const FString& ClassName, const FString& ObjectId) -{ - UVaRestJsonObject* OutRestJsonObj = NewObject(); - - OutRestJsonObj->SetStringField(TEXT("__type"), TEXT("Pointer")); - OutRestJsonObj->SetStringField(TEXT("className"), ClassName); - OutRestJsonObj->SetStringField(TEXT("objectId"), ObjectId); - - return OutRestJsonObj; -} - -UVaRestJsonObject* UVaRestParseManager::ConstructDateObject(const FDateTime& Date) -{ - UVaRestJsonObject* OutRestJsonObj = NewObject(); - - OutRestJsonObj->SetStringField(TEXT("__type"), TEXT("Date")); - OutRestJsonObj->SetStringField(TEXT("iso"), Date.ToIso8601()); - - return OutRestJsonObj; -} - -UVaRestJsonObject* UVaRestParseManager::ConstructDeleteOperation() -{ - UVaRestJsonObject* OutRestJsonObj = NewObject(); - - OutRestJsonObj->SetStringField(TEXT("__op"), TEXT("Delete")); - - return OutRestJsonObj; -} - -UVaRestJsonObject* UVaRestParseManager::ConstructFacebookAuthDataObject(FString UserId, FString AccessToken, FString ExpirationDate) -{ - UVaRestJsonObject* OutRestJsonObj = NewObject(); - - UVaRestJsonObject* FacebookJsonObj = NewObject(); - - FacebookJsonObj->SetStringField(TEXT("id"), UserId); - FacebookJsonObj->SetStringField(TEXT("access_token"), AccessToken); - FacebookJsonObj->SetStringField(TEXT("expiration_date"), ExpirationDate); - - OutRestJsonObj->SetObjectField(TEXT("facebook"), FacebookJsonObj); - - return OutRestJsonObj; -} - -FString UVaRestParseManager::ConstructWhereQuerySimple(const FString& Key, const FString& Value) -{ - return FString::Printf(TEXT("where={\"%s\":%s}"), *Key, *Value); -} - -FString UVaRestParseManager::ConstructWhereQuery(UVaRestJsonObject* JsonObject) -{ - // Serialize json data to string - FString OutputString; - TSharedRef< TJsonWriter<> > Writer = TJsonWriterFactory<>::Create(&OutputString); - FJsonSerializer::Serialize(JsonObject->GetRootObject().ToSharedRef(), Writer); - - return TEXT("where=") + OutputString; -} - -FString UVaRestParseManager::GetHappyMessage() -{ - return FString("Happy New Year!"); -} diff --git a/Source/VaRestPlugin/Private/VaRestPlugin.cpp b/Source/VaRestPlugin/Private/VaRestPlugin.cpp index dedaed4f..3f22758f 100644 --- a/Source/VaRestPlugin/Private/VaRestPlugin.cpp +++ b/Source/VaRestPlugin/Private/VaRestPlugin.cpp @@ -11,7 +11,6 @@ class FVaRestPlugin : public IVaRestPlugin UVaRestJsonObject::StaticClass(); UVaRestJsonValue::StaticClass(); UVaRestRequestJSON::StaticClass(); - UVaRestParseManager::StaticClass(); } virtual void ShutdownModule() override diff --git a/Source/VaRestPlugin/VaRestPlugin.Build.cs b/Source/VaRestPlugin/VaRestPlugin.Build.cs index e37d64cd..affc6b47 100644 --- a/Source/VaRestPlugin/VaRestPlugin.Build.cs +++ b/Source/VaRestPlugin/VaRestPlugin.Build.cs @@ -6,16 +6,6 @@ namespace UnrealBuildTool.Rules { public class VaRestPlugin : ModuleRules { - private string ModulePath - { - get { return Path.GetDirectoryName(RulesCompiler.GetModuleFilename(this.GetType().Name)); } - } - - private string ThirdPartyPath - { - get { return Path.GetFullPath(Path.Combine(ModulePath, "../../ThirdParty/")); } - } - public VaRestPlugin(TargetInfo Target) { PrivateIncludePaths.AddRange( diff --git a/VaRestPlugin.uplugin b/VaRestPlugin.uplugin index 00d908cc..bce225b7 100644 --- a/VaRestPlugin.uplugin +++ b/VaRestPlugin.uplugin @@ -1,21 +1,22 @@ { - "FileVersion" : 3, + "FileVersion" : 3, "FriendlyName" : "VaRest", - "Version" : 12, - "VersionName" : "1.1-r12", + "Version" : 13, + "VersionName" : "1.1-r13", "CreatedBy" : "Vladimir Alyamkin", "CreatedByURL" : "http://alyamkin.com", - "EngineVersion" : 1579795, - "Description" : "Plugin that makes REST (JSON) server communication easy to use. Parse API helpers included.", + "EngineVersion" : "4.11.0", + "Description" : "Plugin that makes REST (JSON) server communication easy to use", "Category" : "Network", + "MarketplaceURL" : "com.epicgames.launcher://ue/marketplace/offers/e47be161e7a24e928560290abd5dcc4f", - "Modules" : + "Modules" : [ { "Name" : "VaRestPlugin", "Type" : "Runtime", - "LoadingPhase": "PreDefault" + "LoadingPhase": "PreDefault" }, { "Name": "VaRestEditorPlugin",