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

New get and set properties v3 requests #127

Merged
merged 6 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
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", "4.0.0"
s.dependency "Qonversion", "5.0.0"
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 = '5.0.2'
ext.qonversion_version = '6.0.0'
}

plugins {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import com.qonversion.android.sdk.automations.dto.AutomationsEvent
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.QEntitlement
import com.qonversion.android.sdk.dto.QRemoteConfig
import com.qonversion.android.sdk.dto.QUser
import com.qonversion.android.sdk.dto.eligibility.QEligibility
import com.qonversion.android.sdk.dto.entitlements.QEntitlement
import com.qonversion.android.sdk.dto.experiments.QExperiment
import com.qonversion.android.sdk.dto.experiments.QExperimentGroup
import com.qonversion.android.sdk.dto.experiments.QExperimentGroupType
import com.qonversion.android.sdk.dto.offerings.QOffering
import com.qonversion.android.sdk.dto.offerings.QOfferings
import com.qonversion.android.sdk.dto.products.QProduct
import com.qonversion.android.sdk.dto.properties.QUserProperties
import com.qonversion.android.sdk.dto.properties.QUserProperty

fun QonversionError.toSandwichError(): SandwichError {
return SandwichError(this)
Expand Down Expand Up @@ -113,6 +115,18 @@ fun QUser.toMap(): BridgeData {
)
}

fun QUserProperty.toMap(): BridgeData {
return mapOf(
"key" to key,
"value" to value,
)
}

fun QUserProperties.toMap(): BridgeData {
val propertiesData = properties.map { it.toMap() }
return mapOf("properties" to propertiesData)
}

fun Map<String, QEligibility>.toEligibilityMap(): BridgeData {
return mapValues { it.value.toMap() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ import androidx.preference.PreferenceManager
import com.qonversion.android.sdk.Qonversion
import com.qonversion.android.sdk.QonversionConfig
import com.qonversion.android.sdk.dto.QAttributionProvider
import com.qonversion.android.sdk.dto.QEntitlement
import com.qonversion.android.sdk.dto.QEntitlementsCacheLifetime
import com.qonversion.android.sdk.dto.QEnvironment
import com.qonversion.android.sdk.dto.QLaunchMode
import com.qonversion.android.sdk.dto.QRemoteConfig
import com.qonversion.android.sdk.dto.QUser
import com.qonversion.android.sdk.dto.QUserProperty
import com.qonversion.android.sdk.dto.QonversionError
import com.qonversion.android.sdk.dto.QonversionErrorCode
import com.qonversion.android.sdk.dto.eligibility.QEligibility
import com.qonversion.android.sdk.dto.entitlements.QEntitlement
import com.qonversion.android.sdk.dto.entitlements.QEntitlementsCacheLifetime
import com.qonversion.android.sdk.dto.offerings.QOfferings
import com.qonversion.android.sdk.dto.products.QProduct
import com.qonversion.android.sdk.dto.properties.QUserProperties
import com.qonversion.android.sdk.dto.properties.QUserPropertyKey
import com.qonversion.android.sdk.listeners.QEntitlementsUpdateListener
import com.qonversion.android.sdk.listeners.QonversionEligibilityCallback
import com.qonversion.android.sdk.listeners.QonversionEntitlementsCallback
Expand All @@ -27,6 +28,7 @@ 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.QonversionUserCallback
import com.qonversion.android.sdk.listeners.QonversionUserPropertiesCallback

private const val TAG = "Qonversion"

Expand Down Expand Up @@ -241,15 +243,27 @@ class QonversionSandwich(

fun setDefinedProperty(propertyKey: String, value: String) {
try {
val property = QUserProperty.valueOf(propertyKey)
Qonversion.shared.setProperty(property, value)
val property = QUserPropertyKey.valueOf(propertyKey)
Qonversion.shared.setUserProperty(property, value)
} catch (e: IllegalArgumentException) {
// Ignore property.
}
}

fun setCustomProperty(key: String, value: String) {
Qonversion.shared.setUserProperty(key, value)
Qonversion.shared.setCustomUserProperty(key, value)
}

fun userProperties(resultListener: ResultListener) {
Qonversion.shared.userProperties(object : QonversionUserPropertiesCallback {
override fun onSuccess(userProperties: QUserProperties) {
resultListener.onSuccess(userProperties.toMap())
}

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

fun logout() {
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', '4.0.0'
pod 'Qonversion', '5.0.0'
end

target 'Sample' do
Expand Down
29 changes: 28 additions & 1 deletion ios/sandwich/Mappers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ extension Qonversion.EntitlementRenewState {
}
}

extension Qonversion.Property {
extension Qonversion.UserPropertyKey {
static func fromString(_ string: String) -> Self? {
switch string {
case "Email":
Expand All @@ -203,12 +203,39 @@ extension Qonversion.Property {
case "FirebaseAppInstanceId":
return .firebaseAppInstanceId

case "FacebookAttribution":
return .facebookAttribution

case "AppSetId":
return .appSetId

default:
return nil
}
}
}

extension Qonversion.UserProperties {
func toMap() -> BridgeData {
var propertiesArray: Array<BridgeData> = properties.map { userProperty in
userProperty.toMap()
}

return [
"properties": propertiesArray,
];
}
}

extension Qonversion.UserProperty {
func toMap() -> BridgeData {
return [
"key": key,
"value": value,
];
}
}

extension Qonversion.Environment {
static func fromString(_ string: String?) -> Self? {
switch string {
Expand Down
20 changes: 16 additions & 4 deletions ios/sandwich/QonversionSandwich.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,25 @@ public class QonversionSandwich : NSObject {
}

@objc public func setDefinedProperty(_ property: String, value: String) {
guard let parsedProperty = Qonversion.Property.fromString(property) else { return }
guard let parsedProperty = Qonversion.UserPropertyKey.fromString(property) else { return }

Qonversion.shared().setProperty(parsedProperty, value: value)
Qonversion.shared().setUserProperty(parsedProperty, value: value)
}

@objc public func setCustomProperty(_ property: String, value: String) {
Qonversion.shared().setUserProperty(property, value: value)
Qonversion.shared().setCustomUserProperty(property, value: value)
}

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

let bridgeData: [String: Any]? = userProperties?.toMap().clearEmptyValues()

completion(bridgeData, nil)
}
}

@objc public func logout() {
Expand All @@ -196,7 +208,7 @@ public class QonversionSandwich : NSObject {
@objc public func userInfo(_ completion: @escaping BridgeCompletion) {
Qonversion.shared().userInfo { userInfo, error in
if let error = error as NSError? {
completion(nil, error.toSandwichError())
return completion(nil, error.toSandwichError())
}

let bridgeData: [String: Any]? = userInfo?.toMap().clearEmptyValues()
Expand Down
Loading