Skip to content

Commit

Permalink
Added an option to load Remote Configs by the specific context keys u…
Browse files Browse the repository at this point in the history
…sing the `remoteConfig` method. (#62)
  • Loading branch information
SpertsyanKM authored Mar 8, 2024
1 parent 4431740 commit f924d7d
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 11 deletions.
4 changes: 2 additions & 2 deletions plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<param name="android-package" value="com.qonversion.android.sdk.QonversionPlugin"/>
</feature>
</config-file>
<framework src="io.qonversion.sandwich:sandwich:4.1.1" />
<framework src="io.qonversion.sandwich:sandwich:4.2.0" />
<source-file src="src/android/QonversionPlugin.java" target-dir="src/com/qonversion/android/sdk" />
<source-file src="src/android/EntitiesConverter.java" target-dir="src/com/qonversion/android/sdk" />
<source-file src="src/android/Utils.java" target-dir="src/com/qonversion/android/sdk" />
Expand All @@ -71,7 +71,7 @@
<source url="https://github.com/CocoaPods/Specs.git"/>
</config>
<pods use-frameworks="true">
<pod name="QonversionSandwich" spec="4.1.1" />
<pod name="QonversionSandwich" spec="4.2.0" />
</pods>
</podspec>
</platform>
Expand Down
4 changes: 2 additions & 2 deletions plugin/src/android/QonversionPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ public void restore(CallbackContext callbackContext) {
}

@PluginAction(thread = ExecutionThread.UI, actionName = "remoteConfig", isAutofinish = false)
public void remoteConfig(CallbackContext callbackContext) {
qonversionSandwich.remoteConfig(Utils.getResultListener(callbackContext));
public void remoteConfig(@Nullable String contextKey, CallbackContext callbackContext) {
qonversionSandwich.remoteConfig(contextKey, Utils.getResultListener(callbackContext));
}

@PluginAction(thread = ExecutionThread.UI, actionName = "attachUserToExperiment", isAutofinish = false)
Expand Down
3 changes: 2 additions & 1 deletion plugin/src/ios/CDVQonversionPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ - (void)checkTrialIntroEligibilityForProductIds:(CDVInvokedUrlCommand *)command

- (void)remoteConfig:(CDVInvokedUrlCommand *)command {
__block __weak CDVQonversionPlugin *weakSelf = self;
[self.qonversionSandwich remoteConfig:^(NSDictionary<NSString *,id> * _Nullable result, SandwichError * _Nullable error) {
NSString *contextKey = [command argumentAtIndex:0];
[self.qonversionSandwich remoteConfig:contextKey :^(NSDictionary<NSString *,id> * _Nullable result, SandwichError * _Nullable error) {
[weakSelf returnCordovaResult:result error:error command:command];
}];
}
Expand Down
9 changes: 8 additions & 1 deletion plugin/src/plugin/Mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ type QRemoteConfigurationSource = {
name: string;
type: string;
assignmentType: string;
contextKey: string | null | undefined;
};

type QExperiment = {
Expand Down Expand Up @@ -995,7 +996,13 @@ class Mapper {
const sourceType = this.convertRemoteConfigurationSourceType(remoteConfig.source.type);
const assignmentType = this.convertRemoteConfigurationAssignmentType(remoteConfig.source.assignmentType);

const source = new RemoteConfigurationSource(remoteConfig.source.id, remoteConfig.source.name, sourceType, assignmentType)
const source = new RemoteConfigurationSource(
remoteConfig.source.id,
remoteConfig.source.name,
sourceType,
assignmentType,
remoteConfig.source.contextKey ?? null,
)

return new RemoteConfig(remoteConfig.payload, experiment, source);
}
Expand Down
4 changes: 2 additions & 2 deletions plugin/src/plugin/QonversionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ export interface QonversionApi {
userInfo(): Promise<User>;

/**
* Returns Qonversion remote config object
* Returns Qonversion remote config object by {@link contextKey} or default one if the key is not specified.
* Use this function to get the remote config with specific payload and experiment info.
* @returns the promise with the remote config.
*/
remoteConfig(): Promise<RemoteConfig>
remoteConfig(contextKey: string | undefined): Promise<RemoteConfig>

/**
* This function should be used for the test purposes only. Do not forget to delete the usage of this function before the release.
Expand Down
4 changes: 2 additions & 2 deletions plugin/src/plugin/QonversionInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ export default class QonversionInternal implements QonversionApi {
return mappedUserInfo;
}

async remoteConfig(): Promise<RemoteConfig> {
let remoteConfig = await callNative<QRemoteConfig>('remoteConfig');
async remoteConfig(contextKey: string | undefined): Promise<RemoteConfig> {
let remoteConfig = await callNative<QRemoteConfig>('remoteConfig', [contextKey]);
// noinspection UnnecessaryLocalVariableJS
const mappedRemoteConfig: RemoteConfig = Mapper.convertRemoteConfig(
remoteConfig
Expand Down
10 changes: 9 additions & 1 deletion plugin/src/plugin/RemoteConfigurationSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ export class RemoteConfigurationSource {
name: string;
type: RemoteConfigurationSourceType;
assignmentType: RemoteConfigurationAssignmentType;
contextKey: string | null;

constructor(id: string, name: string, type: RemoteConfigurationSourceType, assignmentType: RemoteConfigurationAssignmentType) {
constructor(
id: string,
name: string,
type: RemoteConfigurationSourceType,
assignmentType: RemoteConfigurationAssignmentType,
contextKey: string | null,
) {
this.id = id;
this.name = name;
this.type = type;
this.assignmentType = assignmentType;
this.contextKey = contextKey;
}
}

0 comments on commit f924d7d

Please sign in to comment.