Skip to content

Commit

Permalink
Added functions for requesting remote config list by multiple context…
Browse files Browse the repository at this point in the history
… keys (#175)

* Added functions for requesting remote config list by multiple context keys

* CR fix
  • Loading branch information
SpertsyanKM authored Apr 1, 2024
1 parent c4e9bd0 commit c0abc3b
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 12 deletions.
2 changes: 1 addition & 1 deletion QonversionSandwich.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ Pod::Spec.new do |s|
s.source_files = 'ios/sandwich/**/*.{h,m,swift}'
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }

s.dependency "Qonversion", "5.7.0"
s.dependency "Qonversion", "5.8.2"
end
2 changes: 1 addition & 1 deletion android/sandwich/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.qonversion_version = '7.2.0'
ext.qonversion_version = '7.3.1'
}

plugins {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.qonversion.android.sdk.automations.dto.QActionResult
import com.qonversion.android.sdk.automations.dto.QScreenPresentationConfig
import com.qonversion.android.sdk.automations.dto.QScreenPresentationStyle
import com.qonversion.android.sdk.dto.QRemoteConfig
import com.qonversion.android.sdk.dto.QRemoteConfigList
import com.qonversion.android.sdk.dto.QRemoteConfigurationAssignmentType
import com.qonversion.android.sdk.dto.QRemoteConfigurationSource
import com.qonversion.android.sdk.dto.QRemoteConfigurationSourceType
Expand Down Expand Up @@ -238,6 +239,12 @@ fun Map<String, QEligibility>.toEligibilityMap(): BridgeData {
return mapValues { it.value.toMap() }
}

fun QRemoteConfigList.toMap(): BridgeData {
return mapOf(
"remoteConfigs" to remoteConfigs.map { it.toMap() }
)
}

fun QRemoteConfig.toMap(): BridgeData {
return mapOf(
"payload" to payload,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.qonversion.android.sdk.dto.QPurchaseModel
import com.qonversion.android.sdk.dto.QPurchaseUpdateModel
import com.qonversion.android.sdk.dto.QPurchaseUpdatePolicy
import com.qonversion.android.sdk.dto.QRemoteConfig
import com.qonversion.android.sdk.dto.QRemoteConfigList
import com.qonversion.android.sdk.dto.QUser
import com.qonversion.android.sdk.dto.QonversionError
import com.qonversion.android.sdk.dto.QonversionErrorCode
Expand All @@ -30,6 +31,7 @@ import com.qonversion.android.sdk.listeners.QonversionExperimentAttachCallback
import com.qonversion.android.sdk.listeners.QonversionOfferingsCallback
import com.qonversion.android.sdk.listeners.QonversionProductsCallback
import com.qonversion.android.sdk.listeners.QonversionRemoteConfigCallback
import com.qonversion.android.sdk.listeners.QonversionRemoteConfigListCallback
import com.qonversion.android.sdk.listeners.QonversionRemoteConfigurationAttachCallback
import com.qonversion.android.sdk.listeners.QonversionUserCallback
import com.qonversion.android.sdk.listeners.QonversionUserPropertiesCallback
Expand Down Expand Up @@ -273,6 +275,34 @@ class QonversionSandwich(
}
}

fun remoteConfigList(contextKeys: List<String>, includeEmptyContextKey: Boolean, resultListener: ResultListener) {
val callback = object : QonversionRemoteConfigListCallback {
override fun onSuccess(remoteConfigList: QRemoteConfigList) {
resultListener.onSuccess(remoteConfigList.toMap())
}

override fun onError(error: QonversionError) {
resultListener.onError(error.toSandwichError())
}
}

Qonversion.shared.remoteConfigList(contextKeys, includeEmptyContextKey, callback)
}

fun remoteConfigList(resultListener: ResultListener) {
val callback = object : QonversionRemoteConfigListCallback {
override fun onSuccess(remoteConfigList: QRemoteConfigList) {
resultListener.onSuccess(remoteConfigList.toMap())
}

override fun onError(error: QonversionError) {
resultListener.onError(error.toSandwichError())
}
}

Qonversion.shared.remoteConfigList(callback)
}

fun attachUserToExperiment(experimentId: String, groupId: String, resultListener: ResultListener) {
Qonversion.shared.attachUserToExperiment(experimentId, groupId, object : QonversionExperimentAttachCallback {
override fun onSuccess() {
Expand Down
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ platform :ios, '9.0'
use_frameworks!

target 'QonversionSandwich' do
pod 'Qonversion', '5.7.0'
pod 'Qonversion', '5.8.2'
end

target 'Sample' do
Expand Down
18 changes: 9 additions & 9 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PODS:
- Qonversion (5.7.0):
- Qonversion/Main (= 5.7.0)
- Qonversion/Main (5.7.0)
- QonversionSandwich (4.1.0):
- Qonversion (= 5.7.0)
- Qonversion (5.8.2):
- Qonversion/Main (= 5.8.2)
- Qonversion/Main (5.8.2)
- QonversionSandwich (4.1.1):
- Qonversion (= 5.8.2)

DEPENDENCIES:
- Qonversion (= 5.7.0)
- Qonversion (= 5.8.2)
- QonversionSandwich (from `../`)

SPEC REPOS:
Expand All @@ -18,9 +18,9 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
Qonversion: 28eb7795cb52b83de3461898cf1c2b527545f860
QonversionSandwich: 97cf70512ef460c11e86a793eddc34a2d18cac7e
Qonversion: db2c1948a0a27523e2c913858347a019bdebb82c
QonversionSandwich: cb26638883fbf1ad79671aecbd431174cf99b972

PODFILE CHECKSUM: 581ca77b0f4843311f8495ef4e66e0dac6016e85
PODFILE CHECKSUM: 4bda1bc024feeec34eb5a152d592c2e039f14c41

COCOAPODS: 1.13.0
8 changes: 8 additions & 0 deletions ios/sandwich/Mappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,14 @@ extension SKProductDiscount {
}
}

extension Qonversion.RemoteConfigList {
func toMap() -> BridgeData {
return [
"remoteConfigs": remoteConfigs.map { $0.toMap() }
]
}
}

extension Qonversion.RemoteConfig {
func toMap() -> BridgeData {
return [
Expand Down
26 changes: 26 additions & 0 deletions ios/sandwich/QonversionSandwich.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,32 @@ public class QonversionSandwich : NSObject {
Qonversion.shared().remoteConfig(sandwichCompletion)
}

@objc public func remoteConfigList(_ contextKeys: [String], includeEmptyContextKey: Bool, _ completion: @escaping BridgeCompletion) {
let sandwichCompletion: Qonversion.RemoteConfigListCompletionHandler = { remoteConfigList, error in
if let error = error as NSError? {
return completion(nil, error.toSandwichError())
}

let bridgeData: [String: Any]? = remoteConfigList?.toMap().clearEmptyValues()
completion(bridgeData, nil)
}

Qonversion.shared().remoteConfigList(contextKeys: contextKeys, includeEmptyContextKey: includeEmptyContextKey, completion: sandwichCompletion)
}

@objc public func remoteConfigList(_ completion: @escaping BridgeCompletion) {
let sandwichCompletion: Qonversion.RemoteConfigListCompletionHandler = { remoteConfigList, error in
if let error = error as NSError? {
return completion(nil, error.toSandwichError())
}

let bridgeData: [String: Any]? = remoteConfigList?.toMap().clearEmptyValues()
completion(bridgeData, nil)
}

Qonversion.shared().remoteConfigList(sandwichCompletion)
}

@objc public func attachUserToExperiment(with experimentId: String, groupId: String, completion: @escaping BridgeCompletion) {
Qonversion.shared().attachUser(toExperiment: experimentId, groupId: groupId) { success, error in
if let error = error as NSError? {
Expand Down

0 comments on commit c0abc3b

Please sign in to comment.