Skip to content

Commit 2b14023

Browse files
authored
Ref: use explicit api & consistency (#63)
* refactor to use explicit api * update visibility modifiers and naming * update changelog
1 parent e96fa30 commit 2b14023

File tree

34 files changed

+294
-427
lines changed

34 files changed

+294
-427
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- Improve Objc/Swift experience with @HiddenFromObjc ([#62](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/62))
88

9+
### Fixes
10+
11+
- ref: use explicit api & add code consistency ([#63](https://github.com/getsentry/sentry-kotlin-multiplatform/pull/63))
12+
913
## 0.0.3
1014

1115
### Fixes

sentry-kotlin-multiplatform/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ android {
2323
}
2424

2525
kotlin {
26+
explicitApi()
27+
2628
android {
2729
publishLibraryVariants("release")
2830
}

sentry-kotlin-multiplatform/src/androidMain/kotlin/io/sentry/kotlin/multiplatform/SentryInit.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ internal actual fun initSentry(context: Context?, configuration: OptionsConfigur
1212
}
1313
}
1414

15-
actual typealias Context = Context
15+
public actual typealias Context = Context

sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/Attachment.kt

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,47 @@ package io.sentry.kotlin.multiplatform
33
import io.sentry.kotlin.multiplatform.extensions.toByteArray
44
import io.sentry.kotlin.multiplatform.extensions.toNSData
55

6-
actual class Attachment : IAttachment {
6+
public actual class Attachment {
77

8-
lateinit var cocoaAttachment: CocoaAttachment
8+
internal lateinit var cocoaAttachment: CocoaAttachment
99

10-
actual override val filename: String
10+
public actual val filename: String
1111
get() = cocoaAttachment.filename
1212

13-
actual override val pathname: String?
13+
public actual val pathname: String?
1414
get() = cocoaAttachment.path
1515

16-
actual override val bytes: ByteArray?
16+
public actual val bytes: ByteArray?
1717
get() = cocoaAttachment.data?.toByteArray()
1818

19-
actual override val contentType: String?
19+
public actual val contentType: String?
2020
get() = cocoaAttachment.contentType
2121

22-
actual companion object {
23-
actual fun fromScreenshot(screenshotBytes: ByteArray): Attachment {
24-
val data = screenshotBytes.toNSData()
22+
public actual companion object {
23+
public actual fun fromScreenshot(screenshotBytes: ByteArray): Attachment {
2524
return Attachment(screenshotBytes, "screenshot.png", "image/png")
2625
}
2726
}
2827

29-
actual constructor(pathname: String) {
28+
public actual constructor(pathname: String) {
3029
cocoaAttachment = CocoaAttachment(pathname)
3130
}
3231

33-
actual constructor(pathname: String, filename: String) {
32+
public actual constructor(pathname: String, filename: String) {
3433
cocoaAttachment = CocoaAttachment(pathname, filename)
3534
}
3635

37-
actual constructor(pathname: String, filename: String, contentType: String?) {
36+
public actual constructor(pathname: String, filename: String, contentType: String?) {
3837
contentType?.let { cocoaAttachment = CocoaAttachment(pathname, filename, it) } ?: run {
3938
cocoaAttachment = CocoaAttachment(pathname, filename)
4039
}
4140
}
4241

43-
actual constructor(bytes: ByteArray, filename: String) {
42+
public actual constructor(bytes: ByteArray, filename: String) {
4443
cocoaAttachment = CocoaAttachment(bytes.toNSData(), filename)
4544
}
4645

47-
actual constructor(bytes: ByteArray, filename: String, contentType: String?) {
46+
public actual constructor(bytes: ByteArray, filename: String, contentType: String?) {
4847
contentType?.let { cocoaAttachment = CocoaAttachment(bytes.toNSData(), filename, it) } ?: run {
4948
cocoaAttachment = CocoaAttachment(bytes.toNSData(), filename)
5049
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import io.sentry.kotlin.multiplatform.protocol.Breadcrumb
1010
import io.sentry.kotlin.multiplatform.protocol.User
1111
import Scope.Sentry.SentryScope as PrivateCocoaScope
1212

13-
internal class ScopeCocoaImpl(private val scope: CocoaScope) : ISentryScope {
13+
internal class CocoaScopeProvider(private val scope: CocoaScope) : ScopeProvider {
1414

1515
/*
1616
This bridge exposes private Cocoa SDK API to fetch internal properties such as user, level, etc.

sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/SentryBridge.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import io.sentry.kotlin.multiplatform.protocol.UserFeedback
1212
import platform.Foundation.NSError
1313
import platform.Foundation.NSException
1414

15-
actual abstract class Context
15+
public actual abstract class Context
1616

1717
internal expect fun initSentry(configuration: OptionsConfiguration)
1818

@@ -68,21 +68,21 @@ internal actual object SentryBridge {
6868

6969
private fun configureScopeCallback(scopeCallback: ScopeCallback): (CocoaScope?) -> Unit {
7070
return { cocoaScope ->
71-
val cocoaScopeImpl = cocoaScope?.let {
72-
ScopeCocoaImpl(it)
71+
val cocoaScopeProvider = cocoaScope?.let {
72+
CocoaScopeProvider(it)
7373
}
74-
cocoaScopeImpl?.let {
74+
cocoaScopeProvider?.let {
7575
val scope = Scope(it)
7676
scopeCallback.invoke(scope)
7777
}
7878
}
7979
}
8080
}
8181

82-
fun Sentry.captureError(error: NSError) {
82+
public fun captureError(error: NSError) {
8383
SentrySDK.captureError(error)
8484
}
8585

86-
fun Sentry.captureException(exception: NSException) {
86+
public fun captureException(exception: NSException) {
8787
SentrySDK.captureException(exception)
8888
}

sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/BreadcrumbExtensions.kt

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,24 @@ package io.sentry.kotlin.multiplatform.extensions
22

33
import io.sentry.kotlin.multiplatform.CocoaBreadcrumb
44
import io.sentry.kotlin.multiplatform.protocol.Breadcrumb
5-
import io.sentry.kotlin.multiplatform.protocol.ISentryBreadcrumb
65

7-
internal fun ISentryBreadcrumb.toCocoaBreadcrumb(): CocoaBreadcrumb {
8-
val outerScope = this
9-
return CocoaBreadcrumb().apply {
10-
setMessage(outerScope.message)
11-
setType(outerScope.type)
12-
outerScope.category?.let { setCategory(it) }
13-
outerScope.level?.let { setLevel(it.toCocoaSentryLevel()) }
14-
setData(outerScope.getData()?.toMap())
15-
}
6+
internal fun Breadcrumb.toCocoaBreadcrumb() = CocoaBreadcrumb().apply {
7+
val scope = this@toCocoaBreadcrumb
8+
setMessage(scope.message)
9+
setType(scope.type)
10+
scope.category?.let { setCategory(it) }
11+
scope.level?.let { setLevel(it.toCocoaSentryLevel()) }
12+
setData(scope.getData()?.toMap())
1613
}
1714

18-
internal fun CocoaBreadcrumb.toKmpBreadcrumb(): Breadcrumb {
19-
return Breadcrumb().apply {
20-
val funScope = this@toKmpBreadcrumb
21-
message = funScope.message
22-
type = funScope.type
23-
category = funScope.category
24-
val map = funScope.data as? Map<String, Any>
25-
map?.let {
26-
this.setData(it.toMutableMap())
27-
}
28-
level = funScope.level?.toKmpSentryLevel()
15+
internal fun CocoaBreadcrumb.toKmpBreadcrumb() = Breadcrumb().apply {
16+
val scope = this@toKmpBreadcrumb
17+
message = scope.message
18+
type = scope.type
19+
category = scope.category
20+
val map = scope.data as? Map<String, Any>
21+
map?.let {
22+
this.setData(it.toMutableMap())
2923
}
24+
level = scope.level?.toKmpSentryLevel()
3025
}

sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/FoundationExtensions.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import platform.Foundation.allKeys
1111
import platform.Foundation.create
1212
import platform.posix.memcpy
1313

14-
fun <K, V> NSMutableDictionary.toMutableMap(): MutableMap<K, V> {
14+
internal fun <K, V> NSMutableDictionary.toMutableMap(): MutableMap<K, V> {
1515
val keys = this.allKeys
1616
val map = mutableMapOf<K, V>()
1717
for (key in keys) {
@@ -20,13 +20,13 @@ fun <K, V> NSMutableDictionary.toMutableMap(): MutableMap<K, V> {
2020
return map
2121
}
2222

23-
fun NSData.toByteArray(): ByteArray = ByteArray(this@toByteArray.length.toInt()).apply {
23+
internal fun NSData.toByteArray(): ByteArray = ByteArray(this@toByteArray.length.toInt()).apply {
2424
usePinned {
2525
memcpy(it.addressOf(0), this@toByteArray.bytes, this@toByteArray.length)
2626
}
2727
}
2828

29-
fun ByteArray.toNSData(): NSData = memScoped {
29+
internal fun ByteArray.toNSData(): NSData = memScoped {
3030
NSData.create(
3131
bytes = allocArrayOf(this@toNSData),
3232
length = this@toNSData.size.toULong().convert()

sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserExtensions.kt

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,19 @@ package io.sentry.kotlin.multiplatform.extensions
33
import io.sentry.kotlin.multiplatform.CocoaUser
44
import io.sentry.kotlin.multiplatform.protocol.User
55

6-
internal fun User.toCocoaUser(): CocoaUser {
7-
val outerScope = this
8-
return CocoaUser().apply {
9-
userId = outerScope.id
10-
username = outerScope.username
11-
email = outerScope.email
12-
ipAddress = outerScope.ipAddress
13-
}
6+
internal fun User.toCocoaUser() = CocoaUser().apply {
7+
val scope = this@toCocoaUser
8+
userId = scope.id
9+
username = scope.username
10+
email = scope.email
11+
ipAddress = scope.ipAddress
1412
}
1513

16-
internal fun CocoaUser.toKmpUser(): User {
17-
val outerScope = this
18-
return User().apply {
19-
id = outerScope.userId.toString()
20-
username = outerScope.username.toString()
21-
email = outerScope.email.toString()
22-
ipAddress = outerScope.ipAddress.toString()
23-
setData(outerScope.data)
24-
}
14+
internal fun CocoaUser.toKmpUser() = User().apply {
15+
val scope = this@toKmpUser
16+
id = scope.userId.toString()
17+
username = scope.username.toString()
18+
email = scope.email.toString()
19+
ipAddress = scope.ipAddress.toString()
20+
setData(scope.data)
2521
}

sentry-kotlin-multiplatform/src/commonAppleMain/kotlin/io/sentry/kotlin/multiplatform/extensions/UserFeedbackExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import io.sentry.kotlin.multiplatform.CocoaSentryId
44
import io.sentry.kotlin.multiplatform.CocoaUserFeedback
55
import io.sentry.kotlin.multiplatform.protocol.UserFeedback
66

7-
fun UserFeedback.toCocoaUserFeedback(): CocoaUserFeedback {
7+
internal fun UserFeedback.toCocoaUserFeedback(): CocoaUserFeedback {
88
val sentryId = CocoaSentryId(sentryId.toString())
99
return CocoaUserFeedback(sentryId).apply {
1010
comments = this@toCocoaUserFeedback.comments.toString()

0 commit comments

Comments
 (0)