From dfeec7ea7de530213afc3ffbdf52ce5a8fd4ee08 Mon Sep 17 00:00:00 2001 From: Kamo Spertsyan Date: Thu, 28 Mar 2024 12:49:33 +0300 Subject: [PATCH 1/2] Remote config list request implemented (#566) * Remote config list request implemented * Detekt fixes * CR fixes --- config/detekt/baseline.xml | 1 + .../com/qonversion/android/sdk/Qonversion.kt | 21 ++++++ .../android/sdk/dto/QRemoteConfig.kt | 2 + .../android/sdk/dto/QRemoteConfigList.kt | 13 ++++ .../sdk/internal/QRemoteConfigManager.kt | 70 +++++++++++++++--- .../sdk/internal/QonversionInternal.kt | 33 +++++++++ .../android/sdk/internal/api/Api.kt | 17 ++++- .../android/sdk/internal/api/RequestType.kt | 1 + .../internal/repository/DefaultRepository.kt | 72 ++++++++++++++----- .../sdk/internal/repository/QRepository.kt | 15 ++-- .../repository/RepositoryWithRateLimits.kt | 51 +++++++++---- .../internal/services/QRemoteConfigService.kt | 32 +++++---- .../sdk/listeners/QonversionCallback.kt | 6 ++ 13 files changed, 273 insertions(+), 61 deletions(-) create mode 100644 sdk/src/main/java/com/qonversion/android/sdk/dto/QRemoteConfigList.kt diff --git a/config/detekt/baseline.xml b/config/detekt/baseline.xml index b8f6af31..c85c3c27 100644 --- a/config/detekt/baseline.xml +++ b/config/detekt/baseline.xml @@ -271,6 +271,7 @@ TooManyFunctions:LegacyBillingClientWrapper.kt$LegacyBillingClientWrapper : BillingClientWrapperBaseIBillingClientWrapper TooManyFunctions:QAutomationsManager.kt$QAutomationsManager TooManyFunctions:QProductCenterManager.kt$QProductCenterManager : PurchasesListenerUserStateProvider + TooManyFunctions:QRemoteConfigManager.kt$QRemoteConfigManager TooManyFunctions:QRepository.kt$QRepository TooManyFunctions:Qonversion.kt$Qonversion TooManyFunctions:QonversionBillingService.kt$QonversionBillingService : PurchasesUpdatedListenerConnectionListenerBillingService diff --git a/sdk/src/main/java/com/qonversion/android/sdk/Qonversion.kt b/sdk/src/main/java/com/qonversion/android/sdk/Qonversion.kt index 3fce05a9..333b8a0f 100644 --- a/sdk/src/main/java/com/qonversion/android/sdk/Qonversion.kt +++ b/sdk/src/main/java/com/qonversion/android/sdk/Qonversion.kt @@ -15,6 +15,7 @@ import com.qonversion.android.sdk.listeners.QonversionEntitlementsCallback 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 @@ -129,6 +130,26 @@ interface Qonversion { */ fun remoteConfig(contextKey: String, callback: QonversionRemoteConfigCallback) + /** + * Returns Qonversion remote config objects by a list of [contextKeys]. + * Use this function to get the remote configs with specific payload and experiment info. + * @param includeEmptyContextKey - set to true if you want to include remote config + * with empty context key to the result + * @param callback - callback that will be called when response is received + */ + fun remoteConfigList( + contextKeys: List, + includeEmptyContextKey: Boolean, + callback: QonversionRemoteConfigListCallback + ) + + /** + * Returns Qonversion remote config objects for all existing context key (including empty one). + * Use this function to get the remote configs with specific payload and experiment info. + * @param callback - callback that will be called when response is received + */ + fun remoteConfigList(callback: QonversionRemoteConfigListCallback) + /** * This function should be used for the test purposes only. Do not forget to delete the usage of this function before the release. * Use this function to attach the user to the experiment. diff --git a/sdk/src/main/java/com/qonversion/android/sdk/dto/QRemoteConfig.kt b/sdk/src/main/java/com/qonversion/android/sdk/dto/QRemoteConfig.kt index d6d4257b..bad7f46e 100644 --- a/sdk/src/main/java/com/qonversion/android/sdk/dto/QRemoteConfig.kt +++ b/sdk/src/main/java/com/qonversion/android/sdk/dto/QRemoteConfig.kt @@ -11,4 +11,6 @@ data class QRemoteConfig internal constructor( @Json(name = "source") internal val sourceApi: QRemoteConfigurationSource? ) { val source: QRemoteConfigurationSource get() = sourceApi!! + + internal val isCorrect = sourceApi != null } diff --git a/sdk/src/main/java/com/qonversion/android/sdk/dto/QRemoteConfigList.kt b/sdk/src/main/java/com/qonversion/android/sdk/dto/QRemoteConfigList.kt new file mode 100644 index 00000000..f92ab54e --- /dev/null +++ b/sdk/src/main/java/com/qonversion/android/sdk/dto/QRemoteConfigList.kt @@ -0,0 +1,13 @@ +package com.qonversion.android.sdk.dto + +data class QRemoteConfigList internal constructor( + internal val remoteConfigs: List +) { + fun remoteConfigForContextKey(key: String): QRemoteConfig? { + return remoteConfigs.find { it.source.contextKey == key } + } + + val remoteConfigForEmptyContextKey: QRemoteConfig? = remoteConfigs.find { + it.source.contextKey == null + } +} diff --git a/sdk/src/main/java/com/qonversion/android/sdk/internal/QRemoteConfigManager.kt b/sdk/src/main/java/com/qonversion/android/sdk/internal/QRemoteConfigManager.kt index 4ea01f0d..9cd835f1 100644 --- a/sdk/src/main/java/com/qonversion/android/sdk/internal/QRemoteConfigManager.kt +++ b/sdk/src/main/java/com/qonversion/android/sdk/internal/QRemoteConfigManager.kt @@ -1,17 +1,20 @@ package com.qonversion.android.sdk.internal import com.qonversion.android.sdk.dto.QRemoteConfig +import com.qonversion.android.sdk.dto.QRemoteConfigList import com.qonversion.android.sdk.dto.QonversionError import com.qonversion.android.sdk.internal.provider.UserStateProvider import com.qonversion.android.sdk.internal.services.QRemoteConfigService import com.qonversion.android.sdk.listeners.QonversionExperimentAttachCallback import com.qonversion.android.sdk.listeners.QonversionRemoteConfigCallback +import com.qonversion.android.sdk.listeners.QonversionRemoteConfigListCallback import com.qonversion.android.sdk.listeners.QonversionRemoteConfigurationAttachCallback import javax.inject.Inject +private val EmptyContextKey: String? = null + internal class QRemoteConfigManager @Inject constructor( private val remoteConfigService: QRemoteConfigService, - private val internalConfig: InternalConfig ) { internal class LoadingState( var loadedConfig: QRemoteConfig? = null, @@ -59,7 +62,7 @@ internal class QRemoteConfigManager @Inject constructor( loadingState.isInProgress = true loadingState.loadedConfig = null - remoteConfigService.loadRemoteConfig(internalConfig.uid, contextKey, object : QonversionRemoteConfigCallback { + remoteConfigService.loadRemoteConfig(contextKey, object : QonversionRemoteConfigCallback { override fun onSuccess(remoteConfig: QRemoteConfig) { loadingState.loadedConfig = remoteConfig fireToCallbacks(contextKey) { onSuccess(remoteConfig) } @@ -71,30 +74,77 @@ internal class QRemoteConfigManager @Inject constructor( }) } + fun loadRemoteConfigList( + contextKeys: List, + includeEmptyContextKey: Boolean, + callback: QonversionRemoteConfigListCallback + ) { + val allKeys = if (includeEmptyContextKey) contextKeys + EmptyContextKey else contextKeys + if (allKeys.all { loadingStates[it]?.loadedConfig != null }) { + val configs = allKeys.mapNotNull { loadingStates[it]?.loadedConfig } + callback.onSuccess(QRemoteConfigList(configs)) + return + } + + remoteConfigService.loadRemoteConfigs( + contextKeys, + includeEmptyContextKey, + getRemoteConfigListCallbackWrapper(callback), + ) + } + + fun loadRemoteConfigList(callback: QonversionRemoteConfigListCallback) { + remoteConfigService.loadRemoteConfigs(getRemoteConfigListCallbackWrapper(callback)) + } + fun attachUserToExperiment(experimentId: String, groupId: String, callback: QonversionExperimentAttachCallback) { - loadingStates[null]?.loadedConfig = null - remoteConfigService.attachUserToExperiment(experimentId, groupId, internalConfig.uid, callback) + loadingStates[EmptyContextKey]?.loadedConfig = null + remoteConfigService.attachUserToExperiment(experimentId, groupId, callback) } fun detachUserFromExperiment(experimentId: String, callback: QonversionExperimentAttachCallback) { - loadingStates[null]?.loadedConfig = null - remoteConfigService.detachUserFromExperiment(experimentId, internalConfig.uid, callback) + loadingStates[EmptyContextKey]?.loadedConfig = null + remoteConfigService.detachUserFromExperiment(experimentId, callback) } fun attachUserToRemoteConfiguration( remoteConfigurationId: String, callback: QonversionRemoteConfigurationAttachCallback ) { - loadingStates[null]?.loadedConfig = null - remoteConfigService.attachUserToRemoteConfiguration(remoteConfigurationId, internalConfig.uid, callback) + loadingStates[EmptyContextKey]?.loadedConfig = null + remoteConfigService.attachUserToRemoteConfiguration(remoteConfigurationId, callback) } fun detachUserFromRemoteConfiguration( remoteConfigurationId: String, callback: QonversionRemoteConfigurationAttachCallback ) { - loadingStates[null]?.loadedConfig = null - remoteConfigService.detachUserFromRemoteConfiguration(remoteConfigurationId, internalConfig.uid, callback) + loadingStates[EmptyContextKey]?.loadedConfig = null + remoteConfigService.detachUserFromRemoteConfiguration(remoteConfigurationId, callback) + } + + private fun getRemoteConfigListCallbackWrapper( + callback: QonversionRemoteConfigListCallback + ): QonversionRemoteConfigListCallback { + // Remembering loading states for the case of user change - + // if it happens, we won't store remote configs for different user. + val localLoadingStates = loadingStates + return object : QonversionRemoteConfigListCallback { + override fun onSuccess(remoteConfigList: QRemoteConfigList) { + remoteConfigList.remoteConfigs.forEach { remoteConfig -> + val contextKey = remoteConfig.source.contextKey + val loadingState = localLoadingStates[contextKey] ?: LoadingState() + loadingState.loadedConfig = remoteConfig + localLoadingStates[contextKey] = loadingState + } + + callback.onSuccess(remoteConfigList) + } + + override fun onError(error: QonversionError) { + callback.onError(error) + } + } } private fun fireToCallbacks(contextKey: String?, action: QonversionRemoteConfigCallback.() -> Unit) { diff --git a/sdk/src/main/java/com/qonversion/android/sdk/internal/QonversionInternal.kt b/sdk/src/main/java/com/qonversion/android/sdk/internal/QonversionInternal.kt index 13b81d8e..99e38d97 100644 --- a/sdk/src/main/java/com/qonversion/android/sdk/internal/QonversionInternal.kt +++ b/sdk/src/main/java/com/qonversion/android/sdk/internal/QonversionInternal.kt @@ -12,6 +12,7 @@ import com.qonversion.android.sdk.dto.QPurchaseModel import com.qonversion.android.sdk.dto.QPurchaseUpdateModel import com.qonversion.android.sdk.dto.entitlements.QEntitlement import com.qonversion.android.sdk.dto.QRemoteConfig +import com.qonversion.android.sdk.dto.QRemoteConfigList import com.qonversion.android.sdk.dto.properties.QUserPropertyKey import com.qonversion.android.sdk.dto.QonversionError import com.qonversion.android.sdk.dto.eligibility.QEligibility @@ -33,6 +34,7 @@ import com.qonversion.android.sdk.listeners.QonversionRemoteConfigCallback import com.qonversion.android.sdk.listeners.QonversionEligibilityCallback import com.qonversion.android.sdk.listeners.QonversionUserCallback import com.qonversion.android.sdk.listeners.QEntitlementsUpdateListener +import com.qonversion.android.sdk.listeners.QonversionRemoteConfigListCallback import com.qonversion.android.sdk.listeners.QonversionRemoteConfigurationAttachCallback import com.qonversion.android.sdk.listeners.QonversionUserPropertiesCallback @@ -213,6 +215,37 @@ internal class QonversionInternal( }) ?: logLaunchErrorForFunctionName(object {}.javaClass.enclosingMethod?.name) } + override fun remoteConfigList( + contextKeys: List, + includeEmptyContextKey: Boolean, + callback: QonversionRemoteConfigListCallback + ) { + remoteConfigManager?.loadRemoteConfigList( + contextKeys, + includeEmptyContextKey, + object : QonversionRemoteConfigListCallback { + override fun onSuccess(remoteConfigList: QRemoteConfigList) { + postToMainThread { callback.onSuccess(remoteConfigList) } + } + + override fun onError(error: QonversionError) { + postToMainThread { callback.onError(error) } + } + }) ?: logLaunchErrorForFunctionName(object {}.javaClass.enclosingMethod?.name) + } + + override fun remoteConfigList(callback: QonversionRemoteConfigListCallback) { + remoteConfigManager?.loadRemoteConfigList(object : QonversionRemoteConfigListCallback { + override fun onSuccess(remoteConfigList: QRemoteConfigList) { + postToMainThread { callback.onSuccess(remoteConfigList) } + } + + override fun onError(error: QonversionError) { + postToMainThread { callback.onError(error) } + } + }) ?: logLaunchErrorForFunctionName(object {}.javaClass.enclosingMethod?.name) + } + override fun attachUserToExperiment( experimentId: String, groupId: String, diff --git a/sdk/src/main/java/com/qonversion/android/sdk/internal/api/Api.kt b/sdk/src/main/java/com/qonversion/android/sdk/internal/api/Api.kt index b207398c..7588bb0f 100644 --- a/sdk/src/main/java/com/qonversion/android/sdk/internal/api/Api.kt +++ b/sdk/src/main/java/com/qonversion/android/sdk/internal/api/Api.kt @@ -31,6 +31,7 @@ import retrofit2.http.DELETE import retrofit2.http.Path import retrofit2.http.QueryMap import retrofit2.http.Headers +import retrofit2.http.Query import retrofit2.http.Url internal interface Api { @@ -74,9 +75,23 @@ internal interface Api { @GET("v3/remote-config") fun remoteConfig( - @QueryMap params: Map + @Query("user_id") userId: String, + @Query("context_key") contextKey: String? ): Call + @GET("v3/remote-configs") + fun remoteConfigList( + @Query("user_id") userId: String, + @Query("all_context_keys") allContextKeys: Boolean = true, + ): Call> + + @GET("v3/remote-configs") + fun remoteConfigList( + @Query("user_id") userId: String, + @Query("context_key") contextKeys: List, + @Query("with_empty_context_key") includeEmptyContextKey: Boolean, + ): Call> + @POST("v3/experiments/{id}/users/{user_id}") fun attachUserToExperiment( @Path("id") experimentId: String, diff --git a/sdk/src/main/java/com/qonversion/android/sdk/internal/api/RequestType.kt b/sdk/src/main/java/com/qonversion/android/sdk/internal/api/RequestType.kt index 6f6d0c48..3fb3c5f5 100644 --- a/sdk/src/main/java/com/qonversion/android/sdk/internal/api/RequestType.kt +++ b/sdk/src/main/java/com/qonversion/android/sdk/internal/api/RequestType.kt @@ -3,6 +3,7 @@ package com.qonversion.android.sdk.internal.api internal enum class RequestType { Init, RemoteConfig, + RemoteConfigList, AttachUserToExperiment, DetachUserFromExperiment, Purchase, diff --git a/sdk/src/main/java/com/qonversion/android/sdk/internal/repository/DefaultRepository.kt b/sdk/src/main/java/com/qonversion/android/sdk/internal/repository/DefaultRepository.kt index cb330e30..6f728bb7 100644 --- a/sdk/src/main/java/com/qonversion/android/sdk/internal/repository/DefaultRepository.kt +++ b/sdk/src/main/java/com/qonversion/android/sdk/internal/repository/DefaultRepository.kt @@ -2,6 +2,7 @@ package com.qonversion.android.sdk.internal.repository import android.content.SharedPreferences import androidx.annotation.VisibleForTesting +import com.qonversion.android.sdk.dto.QRemoteConfigList import com.qonversion.android.sdk.dto.properties.QUserProperty import com.qonversion.android.sdk.listeners.QonversionEligibilityCallback import com.qonversion.android.sdk.dto.QonversionError @@ -48,6 +49,7 @@ import com.qonversion.android.sdk.internal.stringValue import com.qonversion.android.sdk.internal.toQonversionError import com.qonversion.android.sdk.listeners.QonversionExperimentAttachCallback import com.qonversion.android.sdk.listeners.QonversionRemoteConfigCallback +import com.qonversion.android.sdk.listeners.QonversionRemoteConfigListCallback import com.qonversion.android.sdk.listeners.QonversionRemoteConfigurationAttachCallback import retrofit2.Response @@ -82,22 +84,18 @@ internal class DefaultRepository internal constructor( initRequest(initRequestData.purchases, initRequestData.callback) } - override fun remoteConfig(userID: String, contextKey: String?, callback: QonversionRemoteConfigCallback) { - val queryParams = mapOf("user_id" to userID, "context_key" to contextKey) - .filterValues { it != null } - .mapValues { it.value!! } - - api.remoteConfig(queryParams).enqueue { + override fun remoteConfig(contextKey: String?, callback: QonversionRemoteConfigCallback) { + api.remoteConfig(uid, contextKey).enqueue { onResponse = { logger.debug("remoteConfigRequest - ${it.getLogMessage()}") val body = it.body() if (body == null) { callback.onError(errorMapper.getErrorFromResponse(it)) } else { - if (body.payload.isEmpty() && body.sourceApi == null) { - callback.onError(QonversionError(QonversionErrorCode.RemoteConfigurationNotAvailable)) - } else { + if (body.isCorrect) { callback.onSuccess(body) + } else { + callback.onError(QonversionError(QonversionErrorCode.RemoteConfigurationNotAvailable)) } } } @@ -109,14 +107,57 @@ internal class DefaultRepository internal constructor( } } + override fun remoteConfigList( + contextKeys: List, + includeEmptyContextKey: Boolean, + callback: QonversionRemoteConfigListCallback + ) { + api.remoteConfigList(uid, contextKeys, includeEmptyContextKey).enqueue { + onResponse = { + logger.debug("remoteConfigListRequest for specific context keys - ${it.getLogMessage()}") + val body = it.body() + if (body == null) { + callback.onError(errorMapper.getErrorFromResponse(it)) + } else { + val res = QRemoteConfigList(body.filter { config -> config.isCorrect }) + callback.onSuccess(res) + } + } + + onFailure = { + logger.release("remoteConfigRequest for specific context keys - failure - ${it.toQonversionError()}") + callback.onError(it.toQonversionError()) + } + } + } + + override fun remoteConfigList(callback: QonversionRemoteConfigListCallback) { + api.remoteConfigList(uid).enqueue { + onResponse = { + logger.debug("remoteConfigListRequest for all context keys - ${it.getLogMessage()}") + val body = it.body() + if (body == null) { + callback.onError(errorMapper.getErrorFromResponse(it)) + } else { + val res = QRemoteConfigList(body.filter { config -> config.isCorrect }) + callback.onSuccess(res) + } + } + + onFailure = { + logger.release("remoteConfigRequest for all context keys - failure - ${it.toQonversionError()}") + callback.onError(it.toQonversionError()) + } + } + } + override fun attachUserToExperiment( experimentId: String, groupId: String, - userId: String, callback: QonversionExperimentAttachCallback ) { val request = AttachUserRequest(groupId) - api.attachUserToExperiment(experimentId, userId, request).enqueue { + api.attachUserToExperiment(experimentId, uid, request).enqueue { onResponse = { logger.debug("attachUserToExperimentRequest - ${it.getLogMessage()}") if (it.isSuccessful) { @@ -135,10 +176,9 @@ internal class DefaultRepository internal constructor( override fun detachUserFromExperiment( experimentId: String, - userId: String, callback: QonversionExperimentAttachCallback ) { - api.detachUserFromExperiment(experimentId, userId).enqueue { + api.detachUserFromExperiment(experimentId, uid).enqueue { onResponse = { logger.debug("detachUserFromExperimentRequest - ${it.getLogMessage()}") if (it.isSuccessful) { @@ -157,10 +197,9 @@ internal class DefaultRepository internal constructor( override fun attachUserToRemoteConfiguration( remoteConfigurationId: String, - userId: String, callback: QonversionRemoteConfigurationAttachCallback ) { - api.attachUserToRemoteConfiguration(remoteConfigurationId, userId).enqueue { + api.attachUserToRemoteConfiguration(remoteConfigurationId, uid).enqueue { onResponse = { logger.debug("attachUserToRemoteConfigurationRequest - ${it.getLogMessage()}") if (it.isSuccessful) { @@ -179,10 +218,9 @@ internal class DefaultRepository internal constructor( override fun detachUserFromRemoteConfiguration( remoteConfigurationId: String, - userId: String, callback: QonversionRemoteConfigurationAttachCallback ) { - api.detachUserFromRemoteConfiguration(remoteConfigurationId, userId).enqueue { + api.detachUserFromRemoteConfiguration(remoteConfigurationId, uid).enqueue { onResponse = { logger.debug("detachUserFromRemoteConfigurationRequest - ${it.getLogMessage()}") if (it.isSuccessful) { diff --git a/sdk/src/main/java/com/qonversion/android/sdk/internal/repository/QRepository.kt b/sdk/src/main/java/com/qonversion/android/sdk/internal/repository/QRepository.kt index 3952957f..10aa90cc 100644 --- a/sdk/src/main/java/com/qonversion/android/sdk/internal/repository/QRepository.kt +++ b/sdk/src/main/java/com/qonversion/android/sdk/internal/repository/QRepository.kt @@ -13,36 +13,41 @@ import com.qonversion.android.sdk.listeners.QonversionEligibilityCallback import com.qonversion.android.sdk.listeners.QonversionExperimentAttachCallback import com.qonversion.android.sdk.listeners.QonversionLaunchCallback import com.qonversion.android.sdk.listeners.QonversionRemoteConfigCallback +import com.qonversion.android.sdk.listeners.QonversionRemoteConfigListCallback import com.qonversion.android.sdk.listeners.QonversionRemoteConfigurationAttachCallback internal interface QRepository { fun init(initRequestData: InitRequestData) - fun remoteConfig(userID: String, contextKey: String?, callback: QonversionRemoteConfigCallback) + fun remoteConfig(contextKey: String?, callback: QonversionRemoteConfigCallback) + + fun remoteConfigList( + contextKeys: List, + includeEmptyContextKey: Boolean, + callback: QonversionRemoteConfigListCallback + ) + + fun remoteConfigList(callback: QonversionRemoteConfigListCallback) fun attachUserToExperiment( experimentId: String, groupId: String, - userId: String, callback: QonversionExperimentAttachCallback ) fun detachUserFromExperiment( experimentId: String, - userId: String, callback: QonversionExperimentAttachCallback ) fun attachUserToRemoteConfiguration( remoteConfigurationId: String, - userId: String, callback: QonversionRemoteConfigurationAttachCallback ) fun detachUserFromRemoteConfiguration( remoteConfigurationId: String, - userId: String, callback: QonversionRemoteConfigurationAttachCallback ) diff --git a/sdk/src/main/java/com/qonversion/android/sdk/internal/repository/RepositoryWithRateLimits.kt b/sdk/src/main/java/com/qonversion/android/sdk/internal/repository/RepositoryWithRateLimits.kt index bdbd08c9..4da3ac28 100644 --- a/sdk/src/main/java/com/qonversion/android/sdk/internal/repository/RepositoryWithRateLimits.kt +++ b/sdk/src/main/java/com/qonversion/android/sdk/internal/repository/RepositoryWithRateLimits.kt @@ -16,6 +16,7 @@ import com.qonversion.android.sdk.listeners.QonversionEligibilityCallback import com.qonversion.android.sdk.listeners.QonversionExperimentAttachCallback import com.qonversion.android.sdk.listeners.QonversionLaunchCallback import com.qonversion.android.sdk.listeners.QonversionRemoteConfigCallback +import com.qonversion.android.sdk.listeners.QonversionRemoteConfigListCallback import com.qonversion.android.sdk.listeners.QonversionRemoteConfigurationAttachCallback internal class RepositoryWithRateLimits( @@ -32,70 +33,90 @@ internal class RepositoryWithRateLimits( } } - override fun remoteConfig(userID: String, contextKey: String?, callback: QonversionRemoteConfigCallback) { + override fun remoteConfig(contextKey: String?, callback: QonversionRemoteConfigCallback) { withRateLimitCheck( RequestType.RemoteConfig, - (userID + contextKey).hashCode(), + contextKey.hashCode(), { error -> callback.onError(error) } ) { - repository.remoteConfig(userID, contextKey, callback) + repository.remoteConfig(contextKey, callback) + } + } + + override fun remoteConfigList( + contextKeys: List, + includeEmptyContextKey: Boolean, + callback: QonversionRemoteConfigListCallback + ) { + withRateLimitCheck( + RequestType.RemoteConfigList, + contextKeys.hashCode(), + { error -> callback.onError(error) } + ) { + repository.remoteConfigList(contextKeys, includeEmptyContextKey, callback) + } + } + + override fun remoteConfigList(callback: QonversionRemoteConfigListCallback) { + withRateLimitCheck( + RequestType.RemoteConfigList, + 0, + { error -> callback.onError(error) } + ) { + repository.remoteConfigList(callback) } } override fun attachUserToExperiment( experimentId: String, groupId: String, - userId: String, callback: QonversionExperimentAttachCallback ) { withRateLimitCheck( RequestType.AttachUserToExperiment, - (experimentId + groupId + userId).hashCode(), + (experimentId + groupId).hashCode(), { error -> callback.onError(error) } ) { - repository.attachUserToExperiment(experimentId, groupId, userId, callback) + repository.attachUserToExperiment(experimentId, groupId, callback) } } override fun detachUserFromExperiment( experimentId: String, - userId: String, callback: QonversionExperimentAttachCallback ) { withRateLimitCheck( RequestType.DetachUserFromExperiment, - (experimentId + userId).hashCode(), + experimentId.hashCode(), { error -> callback.onError(error) } ) { - repository.detachUserFromExperiment(experimentId, userId, callback) + repository.detachUserFromExperiment(experimentId, callback) } } override fun attachUserToRemoteConfiguration( remoteConfigurationId: String, - userId: String, callback: QonversionRemoteConfigurationAttachCallback ) { withRateLimitCheck( RequestType.AttachUserToRemoteConfiguration, - (remoteConfigurationId + userId).hashCode(), + remoteConfigurationId.hashCode(), { error -> callback.onError(error) } ) { - repository.attachUserToRemoteConfiguration(remoteConfigurationId, userId, callback) + repository.attachUserToRemoteConfiguration(remoteConfigurationId, callback) } } override fun detachUserFromRemoteConfiguration( remoteConfigurationId: String, - userId: String, callback: QonversionRemoteConfigurationAttachCallback ) { withRateLimitCheck( RequestType.DetachUserFromRemoteConfiguration, - (remoteConfigurationId + userId).hashCode(), + remoteConfigurationId.hashCode(), { error -> callback.onError(error) } ) { - repository.detachUserFromRemoteConfiguration(remoteConfigurationId, userId, callback) + repository.detachUserFromRemoteConfiguration(remoteConfigurationId, callback) } } diff --git a/sdk/src/main/java/com/qonversion/android/sdk/internal/services/QRemoteConfigService.kt b/sdk/src/main/java/com/qonversion/android/sdk/internal/services/QRemoteConfigService.kt index 4ff9b453..5084766f 100644 --- a/sdk/src/main/java/com/qonversion/android/sdk/internal/services/QRemoteConfigService.kt +++ b/sdk/src/main/java/com/qonversion/android/sdk/internal/services/QRemoteConfigService.kt @@ -3,46 +3,52 @@ package com.qonversion.android.sdk.internal.services import com.qonversion.android.sdk.internal.repository.QRepository import com.qonversion.android.sdk.listeners.QonversionExperimentAttachCallback import com.qonversion.android.sdk.listeners.QonversionRemoteConfigCallback +import com.qonversion.android.sdk.listeners.QonversionRemoteConfigListCallback import com.qonversion.android.sdk.listeners.QonversionRemoteConfigurationAttachCallback import javax.inject.Inject internal class QRemoteConfigService @Inject constructor( private val repository: QRepository ) { - fun loadRemoteConfig( - userId: String, - contextKey: String?, - callback: QonversionRemoteConfigCallback + fun loadRemoteConfig(contextKey: String?, callback: QonversionRemoteConfigCallback) { + repository.remoteConfig(contextKey, callback) + } + + fun loadRemoteConfigs(callback: QonversionRemoteConfigListCallback) { + repository.remoteConfigList(callback) + } + + fun loadRemoteConfigs( + contextKeys: List, + includeEmptyContextKey: Boolean, + callback: QonversionRemoteConfigListCallback ) { - repository.remoteConfig(userId, contextKey, callback) + repository.remoteConfigList(contextKeys, includeEmptyContextKey, callback) } fun attachUserToExperiment( experimentId: String, groupId: String, - userId: String, callback: QonversionExperimentAttachCallback ) { - repository.attachUserToExperiment(experimentId, groupId, userId, callback) + repository.attachUserToExperiment(experimentId, groupId, callback) } - fun detachUserFromExperiment(experimentId: String, userId: String, callback: QonversionExperimentAttachCallback) { - repository.detachUserFromExperiment(experimentId, userId, callback) + fun detachUserFromExperiment(experimentId: String, callback: QonversionExperimentAttachCallback) { + repository.detachUserFromExperiment(experimentId, callback) } fun attachUserToRemoteConfiguration( remoteConfigurationId: String, - userId: String, callback: QonversionRemoteConfigurationAttachCallback ) { - repository.attachUserToRemoteConfiguration(remoteConfigurationId, userId, callback) + repository.attachUserToRemoteConfiguration(remoteConfigurationId, callback) } fun detachUserFromRemoteConfiguration( remoteConfigurationId: String, - userId: String, callback: QonversionRemoteConfigurationAttachCallback ) { - repository.detachUserFromRemoteConfiguration(remoteConfigurationId, userId, callback) + repository.detachUserFromRemoteConfiguration(remoteConfigurationId, callback) } } diff --git a/sdk/src/main/java/com/qonversion/android/sdk/listeners/QonversionCallback.kt b/sdk/src/main/java/com/qonversion/android/sdk/listeners/QonversionCallback.kt index 50db93c0..48deeeca 100644 --- a/sdk/src/main/java/com/qonversion/android/sdk/listeners/QonversionCallback.kt +++ b/sdk/src/main/java/com/qonversion/android/sdk/listeners/QonversionCallback.kt @@ -2,6 +2,7 @@ package com.qonversion.android.sdk.listeners import com.qonversion.android.sdk.dto.entitlements.QEntitlement import com.qonversion.android.sdk.dto.QRemoteConfig +import com.qonversion.android.sdk.dto.QRemoteConfigList import com.qonversion.android.sdk.dto.QonversionError import com.qonversion.android.sdk.internal.dto.QLaunchResult import com.qonversion.android.sdk.dto.QUser @@ -30,6 +31,11 @@ interface QonversionRemoteConfigCallback { fun onError(error: QonversionError) } +interface QonversionRemoteConfigListCallback { + fun onSuccess(remoteConfigList: QRemoteConfigList) + fun onError(error: QonversionError) +} + interface QonversionExperimentAttachCallback { fun onSuccess() fun onError(error: QonversionError) From 5ac91d25757fea6a48ac54bedd13f5ba500c46cd Mon Sep 17 00:00:00 2001 From: SpertsyanKM Date: Thu, 28 Mar 2024 13:02:00 +0000 Subject: [PATCH 2/2] [create-pull-request] automated change --- build.gradle | 2 +- fastlane/report.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 0aff0fa2..da865ef1 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask buildscript { ext { release = [ - versionName: "7.2.0", + versionName: "7.3.0", versionCode: 1 ] } diff --git a/fastlane/report.xml b/fastlane/report.xml index 1c012a86..5e9d8ba0 100644 --- a/fastlane/report.xml +++ b/fastlane/report.xml @@ -5,7 +5,7 @@ - +