Skip to content

Commit f0870f7

Browse files
committed
refactor: tighten Rokt accessor API and restore legacy docs
Keep only the no-arg public Rokt accessor with explicit start precondition, restore original public method documentation text, and make prepareAttributesAsync internal per review feedback.
1 parent df42198 commit f0870f7

2 files changed

Lines changed: 56 additions & 11 deletions

File tree

kits/rokt/rokt/src/main/kotlin/com/mparticle/kits/MParticleRoktExtensions.kt renamed to kits/rokt/rokt/src/main/kotlin/com/mparticle/kits/MParticleRokt.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,18 @@ package com.mparticle.rokt
33
import com.mparticle.MParticle
44
import com.mparticle.kits.Rokt
55

6-
/**
7-
* Kotlin-friendly accessor for the legacy Rokt API object.
8-
*/
9-
fun MParticle.Rokt(): Rokt = createRokt(this)
10-
116
/**
127
* Java-friendly accessors for the legacy Rokt API object.
138
*/
149
object MParticleRokt {
1510
@Suppress("FunctionName")
1611
@JvmStatic
17-
fun Rokt(mParticle: MParticle?): Rokt? = mParticle?.let { createRokt(it) }
18-
19-
@Suppress("FunctionName")
20-
@JvmStatic
21-
fun Rokt(): Rokt? = MParticle.getInstance()?.let { createRokt(it) }
12+
fun Rokt(): Rokt {
13+
val mParticle = requireNotNull(MParticle.getInstance()) {
14+
"MParticle must be started before calling MParticleRokt.Rokt()"
15+
}
16+
return createRokt(mParticle)
17+
}
2218
}
2319

2420
private fun createRokt(mParticle: MParticle): Rokt {

kits/rokt/rokt/src/main/kotlin/com/mparticle/kits/Rokt.kt

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,20 @@ import kotlinx.coroutines.flow.Flow
1212
import kotlinx.coroutines.flow.flowOf
1313
import java.lang.ref.WeakReference
1414

15+
/**
16+
* Public facade for interacting with the Rokt Kit through mParticle.
17+
*/
1518
class Rokt internal constructor(private val mKitManager: KitManager) {
19+
/**
20+
* Display a Rokt placement with the specified parameters.
21+
*
22+
* @param identifier The placement identifier
23+
* @param attributes User attributes to pass to Rokt
24+
* @param callbacks Optional callback for Rokt events
25+
* @param embeddedViews Optional map of embedded view placeholders
26+
* @param fontTypefaces Optional map of font typefaces
27+
* @param config Optional Rokt configuration
28+
*/
1629
@JvmOverloads
1730
fun selectPlacements(
1831
identifier: String,
@@ -43,37 +56,73 @@ class Rokt internal constructor(private val mKitManager: KitManager) {
4356
}
4457
}
4558

59+
/**
60+
* Get a Flow of Rokt events for the specified identifier.
61+
*
62+
* @param identifier The placement identifier to listen for events
63+
* @return A Flow emitting RoktEvent objects
64+
*/
4665
fun events(identifier: String): Flow<RoktEvent> = if (isEnabled()) {
4766
resolveRoktKit()?.second?.events(identifier) ?: flowOf()
4867
} else {
4968
flowOf()
5069
}
5170

71+
/**
72+
* Notify Rokt that a purchase has been finalized.
73+
*
74+
* @param placementId The placement identifier
75+
* @param catalogItemId The catalog item identifier
76+
* @param status Whether the purchase was successful
77+
*/
5278
fun purchaseFinalized(placementId: String, catalogItemId: String, status: Boolean) {
5379
if (isEnabled()) {
5480
resolveRoktKit()?.second?.purchaseFinalized(placementId, catalogItemId, status)
5581
}
5682
}
5783

84+
/**
85+
* Close any active Rokt placements.
86+
*/
5887
fun close() {
5988
if (isEnabled()) {
6089
resolveRoktKit()?.second?.close()
6190
}
6291
}
6392

93+
/**
94+
* Set the session id to use for the next execute call.
95+
*
96+
* This is useful for cases where you have a session id from a non-native integration,
97+
* e.g. WebView, and you want the session to be consistent across integrations.
98+
*
99+
* **Note:** Empty strings are ignored and will not update the session.
100+
*
101+
* @param sessionId The session id to be set. Must be a non-empty string.
102+
*/
64103
fun setSessionId(sessionId: String) {
65104
if (isEnabled()) {
66105
resolveRoktKit()?.second?.setSessionId(sessionId)
67106
}
68107
}
69108

109+
/**
110+
* Get the session id to use within a non-native integration e.g. WebView.
111+
*
112+
* @return The session id or null if no session is present or SDK is not initialized.
113+
*/
70114
fun getSessionId(): String? = if (isEnabled()) {
71115
resolveRoktKit()?.second?.getSessionId()
72116
} else {
73117
null
74118
}
75119

76-
fun prepareAttributesAsync(attributes: Map<String, String>) {
120+
/**
121+
* Prepare attributes asynchronously before executing a placement.
122+
*
123+
* @param attributes The attributes to prepare
124+
*/
125+
internal fun prepareAttributesAsync(attributes: Map<String, String>) {
77126
if (isEnabled()) {
78127
val resolved = resolveRoktKit()
79128
if (resolved != null) {

0 commit comments

Comments
 (0)