-
Notifications
You must be signed in to change notification settings - Fork 16
/
HttpService.h
63 lines (48 loc) · 1.7 KB
/
HttpService.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/Actor.h"
#include "Runtime/Online/HTTP/Public/Http.h"
#include "Json.h"
#include "JsonUtilities.h"
#include "HttpService.generated.h"
USTRUCT()
struct FRequest_Login {
GENERATED_BODY()
UPROPERTY() FString email;
UPROPERTY() FString password;
FRequest_Login() {}
};
USTRUCT()
struct FResponse_Login {
GENERATED_BODY()
UPROPERTY() int id;
UPROPERTY() FString name;
UPROPERTY() FString hash;
FResponse_Login() {}
};
UCLASS(Blueprintable, hideCategories = (Rendering, Replication, Input, Actor, "Actor Tick"))
class TESTER2_API AHttpService : public AActor
{
GENERATED_BODY()
private:
FHttpModule* Http;
FString ApiBaseUrl = "http://murk.dev/api/";
FString AuthorizationHeader = TEXT("Authorization");
FString AuthorizationHash = TEXT("asdfasdf");
void SetAuthorizationHash(FString Hash);
TSharedRef<IHttpRequest> RequestWithRoute(FString Subroute);
void SetRequestHeaders(TSharedRef<IHttpRequest>& Request);
TSharedRef<IHttpRequest> GetRequest(FString Subroute);
TSharedRef<IHttpRequest> PostRequest(FString Subroute, FString ContentJsonString);
void Send(TSharedRef<IHttpRequest>& Request);
bool ResponseIsValid(FHttpResponsePtr Response, bool bWasSuccessful);
template <typename StructType>
void GetJsonStringFromStruct(StructType FilledStruct, FString& StringOutput);
template <typename StructType>
void GetStructFromJsonString(FHttpResponsePtr Response, StructType& StructOutput);
public:
AHttpService();
virtual void BeginPlay() override;
void Login(FRequest_Login LoginCredentials);
void LoginResponse(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
};