Skip to content

Commit

Permalink
Merge pull request #1 from MyUNiDAYS/extended-context-values
Browse files Browse the repository at this point in the history
Added ability to send attributes with a context.
  • Loading branch information
Reedyuk authored Apr 18, 2024
2 parents b56adcf + 3fb8df4 commit ad4e4ad
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 16 deletions.
2 changes: 1 addition & 1 deletion library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ kotlin {
isStatic = true
}
pod("LaunchDarkly") {
version = "~> 9.0"
version = "9.6.0"
}
}

Expand Down
2 changes: 1 addition & 1 deletion library/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ signing.keyId=""
signing.password=""

MODULE_PACKAGE_NAME=com.myunidays
MODULE_VERSION_NUMBER=0.0.8
MODULE_VERSION_NUMBER=0.1.0
MODULE_NAME=launchdarkly

OPEN_SOURCE_REPO=https://oss.sonatype.org/service/local/staging/deploy/maven2/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
package com.myunidays.launchdarkly

actual class LDContext internal constructor(val android: com.launchdarkly.sdk.LDContext) {
actual constructor(key: String, kind: String) : this(key, ContextKind(kind))
actual constructor(key: String, kind: ContextKind) :
this(com.launchdarkly.sdk.LDContext.create(kind.android, key))
actual constructor(
key: String,
kind: String,
values: Map<String, LDValue>,
privateAttributes: List<String>
) : this(key, ContextKind(kind), values, privateAttributes)

@Suppress("SpreadOperator")
actual constructor(
key: String,
kind: ContextKind,
values: Map<String, LDValue>,
privateAttributes: List<String>
) : this(
com.launchdarkly.sdk.LDContext.builder(key).let { builder ->
builder
.kind(kind.android)
.privateAttributes(*privateAttributes.toTypedArray())
values.forEach { (k, v) ->
builder.trySet(k, v.android)
}
builder.build()
}
)

actual companion object {
@Suppress("SpreadOperator")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.myunidays.launchdarkly

actual class LDValue internal constructor(val android: com.launchdarkly.sdk.LDValue) {
actual constructor(value: String) : this(com.launchdarkly.sdk.LDValue.of(value))

actual fun stringValue(): String? = android.stringValue()
actual fun type(): LDValueType = android.type.toValueType()
actual fun value(): Any? = when (type()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
package com.myunidays.launchdarkly

expect class LDContext(key: String, kind: String = "user") {
expect class LDContext(
key: String,
kind: String,
values: Map<String, LDValue>,
privateAttributes: List<String>
) {

@Suppress("UnusedPrivateProperty")
constructor(key: String, kind: ContextKind = ContextKind())
constructor(
key: String,
kind: ContextKind = ContextKind(),
values: Map<String, LDValue> = emptyMap(),
privateAttributes: List<String> = emptyList()
)

companion object {
fun createMulti(contexts: List<LDContext>): LDContext
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.myunidays.launchdarkly

expect class LDValue {
expect class LDValue(value: String) {
fun stringValue(): String?

fun value(): Any?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
package com.myunidays.launchdarkly

actual class LDContext internal constructor(val ios: cocoapods.LaunchDarkly.LDContext) {
actual constructor(key: String, kind: String) : this(key, ContextKind(kind))
actual constructor(key: String, kind: ContextKind) :
this(
cocoapods.LaunchDarkly.LDContextBuilder(key)
.apply { kindWithKind(kind.kind) }
.build()
.success()!!
)
actual constructor(
key: String,
kind: String,
values: Map<String, LDValue>,
privateAttributes: List<String>
) : this(key, ContextKind(kind), values, privateAttributes)

actual constructor(
key: String,
kind: ContextKind,
values: Map<String, LDValue>,
privateAttributes: List<String>
) : this(
cocoapods.LaunchDarkly.LDContextBuilder(key).let { contextBuilder ->
contextBuilder.kindWithKind(kind.kind)
privateAttributes.forEach {
contextBuilder.addPrivateAttributeWithReference(cocoapods.LaunchDarkly.Reference(it))
}
values.forEach { (k, v) ->
contextBuilder.trySetValueWithName(k, v.ios)
}
contextBuilder.build().success()!!
}
)

actual companion object {
actual fun createMulti(contexts: List<LDContext>): LDContext {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.myunidays.launchdarkly

actual class LDValue internal constructor(val ios: cocoapods.LaunchDarkly.LDValue) {
actual constructor(value: String) : this(cocoapods.LaunchDarkly.LDValue.ofString(value))
actual fun stringValue(): String? = ios.stringValue()
actual fun type(): LDValueType = ios.getType().toValueType()

Expand Down

0 comments on commit ad4e4ad

Please sign in to comment.