This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
462 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright 2016 Vladimir Alyamkin. All Rights Reserved. | ||
|
||
#pragma once | ||
|
||
#include "Kismet/BlueprintFunctionLibrary.h" | ||
|
||
#include "VaRestTypes.h" | ||
#include "VaRestLibrary.generated.h" | ||
|
||
class UVaRestRequestJSON; | ||
class UVaRestJsonObject; | ||
|
||
DECLARE_DYNAMIC_DELEGATE_OneParam(FVaRestCallDelegate, UVaRestRequestJSON*, Request); | ||
|
||
USTRUCT() | ||
struct FVaRestCallResponse | ||
{ | ||
GENERATED_USTRUCT_BODY() | ||
|
||
UPROPERTY() | ||
UVaRestRequestJSON* Request; | ||
|
||
UPROPERTY() | ||
UObject* WorldContextObject; | ||
|
||
UPROPERTY() | ||
FVaRestCallDelegate Callback; | ||
|
||
FDelegateHandle CompleteDelegateHandle; | ||
FDelegateHandle FailDelegateHandle; | ||
|
||
FVaRestCallResponse() | ||
: Request(nullptr) | ||
, WorldContextObject(nullptr) | ||
{ | ||
} | ||
|
||
}; | ||
|
||
/** | ||
* Usefull tools for REST communications | ||
*/ | ||
UCLASS() | ||
class UVaRestLibrary : public UBlueprintFunctionLibrary | ||
{ | ||
GENERATED_BODY() | ||
|
||
|
||
////////////////////////////////////////////////////////////////////////// | ||
// Helpers | ||
|
||
public: | ||
/** Applies percent-encoding to text */ | ||
UFUNCTION(BlueprintCallable, Category = "VaRest|Utility") | ||
static FString PercentEncode(const FString& Source); | ||
|
||
/** | ||
* Encodes a FString into a Base64 string | ||
* | ||
* @param Source The string 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")) | ||
static FString Base64Encode(const FString& Source); | ||
|
||
/** | ||
* Decodes a Base64 string into a FString | ||
* | ||
* @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")) | ||
static bool Base64Decode(const FString& Source, FString& Dest); | ||
|
||
|
||
////////////////////////////////////////////////////////////////////////// | ||
// 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<UVaRestRequestJSON*, FVaRestCallResponse> RequestMap; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2016 Vladimir Alyamkin. All Rights Reserved. | ||
|
||
#pragma once | ||
|
||
/** Verb (GET, PUT, POST) used by the request */ | ||
UENUM(BlueprintType) | ||
enum class ERequestVerb : uint8 | ||
{ | ||
GET, | ||
POST, | ||
PUT, | ||
DEL UMETA(DisplayName = "DELETE"), | ||
/** Set CUSTOM verb by SetCustomVerb() function */ | ||
CUSTOM | ||
}; | ||
|
||
/** Content type (json, urlencoded, etc.) used by the request */ | ||
UENUM(BlueprintType) | ||
enum class ERequestContentType : uint8 | ||
{ | ||
x_www_form_urlencoded_url UMETA(DisplayName = "x-www-form-urlencoded (URL)"), | ||
x_www_form_urlencoded_body UMETA(DisplayName = "x-www-form-urlencoded (Request Body)"), | ||
json, | ||
binary | ||
}; | ||
|
||
/** Enumerates the current state of an Http request */ | ||
UENUM(BlueprintType) | ||
enum class ERequestStatus : uint8 | ||
{ | ||
/** Has not been started via ProcessRequest() */ | ||
NotStarted, | ||
/** Currently being ticked and processed */ | ||
Processing, | ||
/** Finished but failed */ | ||
Failed, | ||
/** Failed because it was unable to connect (safe to retry) */ | ||
Failed_ConnectionError, | ||
/** Finished and was successful */ | ||
Succeeded | ||
}; |
Oops, something went wrong.