Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create user advanced parameters #24

Merged
merged 4 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions ConfigCat.uplugin
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"FileVersion": 3,
"VersionName": "2.1.3",
"VersionName": "2.1.4",
"EngineVersion": "5.4",
"FriendlyName": "ConfigCat",
"Description": "ConfigCat is a hosted service for feature flag and configuration management. It lets you decouple feature releases from code deployments.",
Expand All @@ -19,12 +19,6 @@
"LoadingPhase": "PreDefault",
"PlatformAllowList": [ "Win64", "Mac", "Linux", "Android", "iOS" ]
},
{
"Name": "ConfigCatWrappers",
"Type": "Runtime",
"LoadingPhase": "PreDefault",
"PlatformAllowList": [ "Win64", "Mac", "Linux", "Android", "iOS" ]
},
{
"Name": "ConfigCatEditor",
"Type": "Editor",
Expand Down
1 change: 0 additions & 1 deletion Source/ConfigCat/ConfigCat.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public ConfigCat(ReadOnlyTargetRules Target) : base(Target)

PrivateDependencyModuleNames.AddRange(new[]
{
"ConfigCatWrappers",
"ConfigCatCppSdk"
});

Expand Down
8 changes: 4 additions & 4 deletions Source/ConfigCat/Private/ConfigCatSubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#include "ConfigCatLogger.h"
#include "ConfigCatNetworkAdapter.h"
#include "ConfigCatSettings.h"
#include "ConfigCatSettingsWrapper.h"
#include "ConfigCatEvaluationWrapper.h"
#include "ConfigCatUserWrapper.h"
#include "ConfigCatValueWrapper.h"

#include "Wrappers/ConfigCatSettingsWrapper.h"
#include "Wrappers/ConfigCatEvaluationWrapper.h"
#include "Wrappers/ConfigCatValueWrapper.h"

using namespace configcat;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) ConfigCat 2024. All Rights Reserved.

#include "ConfigCatEvaluationWrapper.h"
#include "Wrappers/ConfigCatEvaluationWrapper.h"

#include "ConfigCatCppSDK/Include/log.h"

#include "ConfigCatPercentageOptionWrapper.h"
#include "ConfigCatTargetingRuleWrapper.h"
#include "ConfigCatUserWrapper.h"
#include "ConfigCatValueWrapper.h"
#include "Wrappers/ConfigCatPercentageOptionWrapper.h"
#include "Wrappers/ConfigCatTargetingRuleWrapper.h"
#include "Wrappers/ConfigCatUserWrapper.h"
#include "Wrappers/ConfigCatValueWrapper.h"

UConfigCatEvaluationWrapper* UConfigCatEvaluationWrapper::CreateEvaluation(const configcat::EvaluationDetailsBase& InEvaluationDetails)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) ConfigCat 2024. All Rights Reserved.

#include "ConfigCatPercentageOptionWrapper.h"
#include "Wrappers/ConfigCatPercentageOptionWrapper.h"

#include "ConfigCatValueWrapper.h"
#include "Wrappers/ConfigCatValueWrapper.h"

UConfigCatPercentageOptionWrapper* UConfigCatPercentageOptionWrapper::CreatePercentageOption(const configcat::PercentageOption& InPercentageOption)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) ConfigCat 2024. All Rights Reserved.

#include "ConfigCatSettingValueContainerWrapper.h"
#include "Wrappers/ConfigCatSettingValueContainerWrapper.h"

#include "ConfigCatValueWrapper.h"
#include "Wrappers/ConfigCatValueWrapper.h"

UConfigCatSettingValueContainerWrapper* UConfigCatSettingValueContainerWrapper::CreateSettingValue(const configcat::SettingValueContainer& SettingValueContainer)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) ConfigCat 2024. All Rights Reserved.

#include "ConfigCatSettingsWrapper.h"
#include "Wrappers/ConfigCatSettingsWrapper.h"

#include "ConfigCatPercentageOptionWrapper.h"
#include "ConfigCatTargetingRuleWrapper.h"
#include "ConfigCatValueWrapper.h"
#include "Wrappers/ConfigCatPercentageOptionWrapper.h"
#include "Wrappers/ConfigCatTargetingRuleWrapper.h"
#include "Wrappers/ConfigCatValueWrapper.h"

using namespace configcat;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) ConfigCat 2024. All Rights Reserved.

#include "ConfigCatTargetingRuleWrapper.h"
#include "Wrappers/ConfigCatTargetingRuleWrapper.h"

#include "ConfigCatSettingValueContainerWrapper.h"
#include "ConfigCatPercentageOptionWrapper.h"
#include "ConfigCatValueWrapper.h"
#include "Wrappers/ConfigCatSettingValueContainerWrapper.h"
#include "Wrappers/ConfigCatPercentageOptionWrapper.h"
#include "Wrappers/ConfigCatValueWrapper.h"

UConfigCatUserConditionWrapper* UConfigCatUserConditionWrapper::CreateUserCondition(const configcat::UserCondition& InUserCondition)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
// Copyright (c) ConfigCat 2024. All Rights Reserved.

#include "ConfigCatUserWrapper.h"
#include "Wrappers/ConfigCatUserWrapper.h"

#include <ConfigCatCppSDK/Include/configcatuser.h>

using namespace configcat;

namespace
{
const ConfigCatUser::AttributeValue* GetUserAttributeForKey(const std::shared_ptr<ConfigCatUser>& User, const FString& Key)
{
if (!User)
{
return {};
}

const std::string AttributeKey = TCHAR_TO_UTF8(*Key);
return User->getAttribute(AttributeKey);
}
}

UConfigCatUserWrapper* UConfigCatUserWrapper::CreateUser(const FString& Id, const FString& Email, const FString& Country, const TMap<FString, FString>& Attributes)
{
const std::string& UserId = TCHAR_TO_UTF8(*Id);
Expand All @@ -24,6 +38,11 @@ UConfigCatUserWrapper* UConfigCatUserWrapper::CreateUser(const FString& Id, cons
return CreateUser(ConfigCatUser::create(UserId, UserEmail, UserCountry, UserAttributes));
}

UConfigCatUserWrapper* UConfigCatUserWrapper::CreateUser(const FString& Id, const FString& Email, const FString& Country)
{
return CreateUser(Id, Email, Country, {});
}

UConfigCatUserWrapper* UConfigCatUserWrapper::CreateUser(const std::shared_ptr<configcat::ConfigCatUser>& InUser)
{
UConfigCatUserWrapper* Result = NewObject<UConfigCatUserWrapper>();
Expand All @@ -45,7 +64,7 @@ FString UConfigCatUserWrapper::GetStringAttribute(const FString& Key) const
{
if (HasStringAttribute(Key))
{
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(Key);
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(User, Key);
return UTF8_TO_TCHAR(std::get<std::string>(*Attribute).c_str());
}

Expand All @@ -56,7 +75,7 @@ double UConfigCatUserWrapper::GetNumberAttribute(const FString& Key) const
{
if (HasNumberAttribute(Key))
{
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(Key);
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(User, Key);
return std::get<double>(*Attribute);
}

Expand All @@ -67,7 +86,7 @@ FDateTime UConfigCatUserWrapper::GetTimeAttribute(const FString& Key) const
{
if (HasTimeAttribute(Key))
{
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(Key);
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(User, Key);
const auto TimeSinceEpoch = std::get<date_time_t>(*Attribute).time_since_epoch().count();
return FDateTime::FromUnixTimestamp(TimeSinceEpoch);
}
Expand All @@ -79,7 +98,7 @@ TArray<FString> UConfigCatUserWrapper::GetStringArrayAttribute(const FString& Ke
{
if (HasStringArrayAttribute(Key))
{
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(Key);
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(User, Key);
TArray<FString> Result;
const std::vector<std::string> ArrayAttribute = std::get<std::vector<std::string>>(*Attribute);
for (const std::string& ArrayIt : ArrayAttribute)
Expand All @@ -99,35 +118,24 @@ bool UConfigCatUserWrapper::HasAnyAttribute(const FString& Key) const

bool UConfigCatUserWrapper::HasStringAttribute(const FString& Key) const
{
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(Key);
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(User, Key);
return Attribute && std::holds_alternative<std::string>(*Attribute);
}

bool UConfigCatUserWrapper::HasNumberAttribute(const FString& Key) const
{
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(Key);
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(User, Key);
return Attribute && std::holds_alternative<double>(*Attribute);
}

bool UConfigCatUserWrapper::HasTimeAttribute(const FString& Key) const
{
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(Key);
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(User, Key);
return Attribute && std::holds_alternative<date_time_t>(*Attribute);
}

bool UConfigCatUserWrapper::HasStringArrayAttribute(const FString& Key) const
{
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(Key);
const ConfigCatUser::AttributeValue* Attribute = GetUserAttributeForKey(User, Key);
return Attribute && std::holds_alternative<std::vector<std::string>>(*Attribute);
}

const ConfigCatUser::AttributeValue* UConfigCatUserWrapper::GetUserAttributeForKey(const FString& Key) const
{
if (!User)
{
return {};
}

const std::string AttributeKey = TCHAR_TO_UTF8(*Key);
return User->getAttribute(AttributeKey);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) ConfigCat 2024. All Rights Reserved.

#include "ConfigCatValueWrapper.h"
#include "Wrappers/ConfigCatValueWrapper.h"

UConfigCatValueWrapper* UConfigCatValueWrapper::CreateValue(const configcat::SettingValue& InValue)
{
Expand Down
2 changes: 2 additions & 0 deletions Source/ConfigCat/Public/ConfigCatSubsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <Subsystems/GameInstanceSubsystem.h>
#include <memory>

#include "Wrappers/ConfigCatUserWrapper.h"

#include "ConfigCatSubsystem.generated.h"

class UConfigCatSettingsWrapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class UConfigCatUserWrapper;
class UConfigCatValueWrapper;

UCLASS(DisplayName="Config Cat Evaluation")
class CONFIGCATWRAPPERS_API UConfigCatEvaluationWrapper : public UObject
class CONFIGCAT_API UConfigCatEvaluationWrapper : public UObject
{
GENERATED_BODY()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class UConfigCatValueWrapper;

UCLASS(DisplayName="Config Cat Percentage Option")
class CONFIGCATWRAPPERS_API UConfigCatPercentageOptionWrapper : public UObject
class CONFIGCAT_API UConfigCatPercentageOptionWrapper : public UObject
{
GENERATED_BODY()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class UConfigCatValueWrapper;
UCLASS(DisplayName="Config Cat Setting Value Container")
class CONFIGCATWRAPPERS_API UConfigCatSettingValueContainerWrapper : public UObject
class CONFIGCAT_API UConfigCatSettingValueContainerWrapper : public UObject
{
GENERATED_BODY()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum class EConfigCatSettingTypeWrapper : uint8
};

UCLASS(DisplayName="Config Cat Setting")
class CONFIGCATWRAPPERS_API UConfigCatSettingWrapper : public UObject
class CONFIGCAT_API UConfigCatSettingWrapper : public UObject
{
GENERATED_BODY()

Expand Down Expand Up @@ -54,7 +54,7 @@ class CONFIGCATWRAPPERS_API UConfigCatSettingWrapper : public UObject
};

UCLASS(DisplayName="Config Cat Settings")
class CONFIGCATWRAPPERS_API UConfigCatSettingsWrapper : public UObject
class CONFIGCAT_API UConfigCatSettingsWrapper : public UObject
{
GENERATED_BODY()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ enum class EConfigCatUserComparator : uint8
};

UCLASS(DisplayName="Config Cat User Condition")
class CONFIGCATWRAPPERS_API UConfigCatUserConditionWrapper : public UObject
class CONFIGCAT_API UConfigCatUserConditionWrapper : public UObject
{
GENERATED_BODY()

Expand Down Expand Up @@ -94,7 +94,7 @@ enum class EConfigCatPrerequisiteFlagComparator : uint8
};

UCLASS(DisplayName="Config Cat Prerequisite Flag Condition")
class CONFIGCATWRAPPERS_API UConfigCatPrerequisiteFlagConditionWrapper : public UObject
class CONFIGCAT_API UConfigCatPrerequisiteFlagConditionWrapper : public UObject
{
GENERATED_BODY()

Expand All @@ -120,7 +120,7 @@ enum class EConfigCatSegmentComparator : uint8
};

UCLASS(DisplayName="Config Cat Segment Condition")
class CONFIGCATWRAPPERS_API UConfigCatSegmentConditionWrapper : public UObject
class CONFIGCAT_API UConfigCatSegmentConditionWrapper : public UObject
{
GENERATED_BODY()

Expand All @@ -136,7 +136,7 @@ class CONFIGCATWRAPPERS_API UConfigCatSegmentConditionWrapper : public UObject
};

USTRUCT(BlueprintType)
struct CONFIGCATWRAPPERS_API FConfigCatConditionContainer
struct CONFIGCAT_API FConfigCatConditionContainer
{
GENERATED_BODY()

Expand All @@ -161,7 +161,7 @@ struct FConfigCatThenContainer
};

UCLASS(DisplayName="Config Cat Targeting Rule")
class CONFIGCATWRAPPERS_API UConfigCatTargetingRuleWrapper : public UObject
class CONFIGCAT_API UConfigCatTargetingRuleWrapper : public UObject
{
GENERATED_BODY()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@

#pragma once

#include <ConfigCatCppSDK/Include/configcatuser.h>

#include <Misc/DateTime.h>

#include <memory>

#include "ConfigCatUserWrapper.generated.h"

namespace configcat
{
class ConfigCatUser;
}

UCLASS(DisplayName="Config Cat User")
class CONFIGCATWRAPPERS_API UConfigCatUserWrapper : public UObject
class CONFIGCAT_API UConfigCatUserWrapper : public UObject
{
GENERATED_BODY()

public:
UFUNCTION(BlueprintPure, Category = "ConfigCat|User")
UFUNCTION(BlueprintPure, Category = "ConfigCat|User", meta = (AdvancedDisplay = "Email, Country, Attributes"))
static UConfigCatUserWrapper* CreateUser(const FString& Id, const FString& Email, const FString& Country, const TMap<FString, FString>& Attributes);
static UConfigCatUserWrapper* CreateUser(const FString& Id, const FString& Email = TEXT(""), const FString& Country = TEXT(""));
static UConfigCatUserWrapper* CreateUser(const std::shared_ptr<configcat::ConfigCatUser>& InUser);

/**
* Gets the Id of a ConfigCatUser
*/
* Gets the Id of a ConfigCatUser
*/
UFUNCTION(BlueprintPure, Category = "ConfigCat|User")
FString GetIdentifier() const;

Expand All @@ -46,7 +51,4 @@ class CONFIGCATWRAPPERS_API UConfigCatUserWrapper : public UObject
bool HasStringArrayAttribute(const FString& Key) const;

std::shared_ptr<configcat::ConfigCatUser> User;

private:
const configcat::ConfigCatUser::AttributeValue* GetUserAttributeForKey(const FString& Key) const;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "ConfigCatValueWrapper.generated.h"

UCLASS(DisplayName="Config Cat SettingValue")
class CONFIGCATWRAPPERS_API UConfigCatValueWrapper : public UObject
class CONFIGCAT_API UConfigCatValueWrapper : public UObject
{
GENERATED_BODY()

Expand Down
Loading
Loading