Skip to content

Commit e5c5648

Browse files
runningcodeclaude
andcommitted
feat(android-distribution): Improve API design based on review feedback
- Add lambda-based init pattern matching SentryAndroid.init - Rename checkForUpdate to checkForUpdateBlocking for clarity - Replace CompletableFuture with simple callback approach - Convert DistributionOptions to mutable builder pattern - Add example for buildConfiguration parameter 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent c5bcc9d commit e5c5648

File tree

2 files changed

+33
-18
lines changed

2 files changed

+33
-18
lines changed

sentry-android-distribution/src/main/java/io/sentry/android/distribution/Distribution.kt

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.content.Context
44
import android.content.Intent
55
import android.net.Uri
66
import io.sentry.android.distribution.internal.DistributionInternal
7-
import java.util.concurrent.CompletableFuture
87

98
/**
109
* The public Android SDK for Sentry Build Distribution.
@@ -14,13 +13,25 @@ import java.util.concurrent.CompletableFuture
1413
*/
1514
public object Distribution {
1615
/**
17-
* Initialize build distribution with the provided options. This should be called once per
16+
* Initialize build distribution with default options. This should be called once per process,
17+
* typically in Application.onCreate().
18+
*
19+
* @param context Android context
20+
*/
21+
public fun init(context: Context) {
22+
init(context) {}
23+
}
24+
25+
/**
26+
* Initialize build distribution with the provided configuration. This should be called once per
1827
* process, typically in Application.onCreate().
1928
*
2029
* @param context Android context
21-
* @param options Configuration options for build distribution
30+
* @param configuration Configuration handler for build distribution options
2231
*/
23-
public fun init(context: Context, options: DistributionOptions) {
32+
public fun init(context: Context, configuration: (DistributionOptions) -> Unit) {
33+
val options = DistributionOptions()
34+
configuration(options)
2435
DistributionInternal.init(context, options)
2536
}
2637

@@ -35,24 +46,24 @@ public object Distribution {
3546

3647
/**
3748
* Check for available updates synchronously (blocking call). This method will block the calling
38-
* thread while making the network request. Consider using checkForUpdateCompletableFuture for
49+
* thread while making the network request. Consider using checkForUpdate with callback for
3950
* non-blocking behavior.
4051
*
4152
* @param context Android context
4253
* @return UpdateStatus indicating if an update is available, up to date, or error
4354
*/
44-
public fun checkForUpdate(context: Context): UpdateStatus {
55+
public fun checkForUpdateBlocking(context: Context): UpdateStatus {
4556
return DistributionInternal.checkForUpdate(context)
4657
}
4758

4859
/**
49-
* Check for available updates using CompletableFuture for Java compatibility.
60+
* Check for available updates asynchronously using a callback.
5061
*
5162
* @param context Android context
52-
* @return CompletableFuture with UpdateStatus result
63+
* @param onResult Callback that will be called with the UpdateStatus result
5364
*/
54-
public fun checkForUpdateCompletableFuture(context: Context): CompletableFuture<UpdateStatus> {
55-
return DistributionInternal.checkForUpdateCompletableFuture(context)
65+
public fun checkForUpdate(context: Context, onResult: (UpdateStatus) -> Unit) {
66+
DistributionInternal.checkForUpdateAsync(context, onResult)
5667
}
5768

5869
/**
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
package io.sentry.android.distribution
22

33
/** Configuration options for Sentry Build Distribution. */
4-
public class DistributionOptions(
4+
public class DistributionOptions {
55
/** Organization authentication token for API access */
6-
public val orgAuthToken: String,
6+
public var orgAuthToken: String = ""
7+
78
/** Sentry organization slug */
8-
public val organizationSlug: String,
9+
public var organizationSlug: String = ""
10+
911
/** Sentry project slug */
10-
public val projectSlug: String,
12+
public var projectSlug: String = ""
13+
1114
/** Base URL for Sentry API (defaults to https://sentry.io) */
12-
public val sentryBaseUrl: String = "https://sentry.io",
13-
/** Optional build configuration name for filtering */
14-
public val buildConfiguration: String? = null,
15-
)
15+
public var sentryBaseUrl: String = "https://sentry.io"
16+
17+
/** Optional build configuration name for filtering (e.g., "debug", "release", "staging") */
18+
public var buildConfiguration: String? = null
19+
}

0 commit comments

Comments
 (0)