forked from customerio/customerio-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: updated client to support react native user agent
- Loading branch information
Showing
7 changed files
with
90 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,41 @@ | ||
package io.customer.sdk.data.store | ||
|
||
import java.util.* | ||
|
||
/** | ||
* Date class to hold information about the package client app is using. | ||
* | ||
* This class only holds info that can have multiple values e.g. source | ||
* package type (Android, ReactNative, etc.) and not the information that | ||
* cannot be change (e.g. the SDK version) | ||
* Sealed class to hold information about the SDK wrapper and package that the | ||
* client app is using. | ||
* | ||
* @property source name of the client source to append with user-agent | ||
* @property identifier name only used to identify client, can be anything; | ||
* default value is lowercase of the name | ||
* @property source name of the client to append with user-agent. | ||
* @property sdkVersion version of the SDK used. | ||
*/ | ||
sealed class Client( | ||
val source: String, | ||
private val identifier: String? = source.lowercase(Locale.ENGLISH) | ||
val sdkVersion: String | ||
) { | ||
object Android : Client(source = "Android") | ||
object ReactNative : Client(source = "ReactNative") | ||
object Expo : Client(source = "Expo") | ||
class Other(value: String) : Client(source = value, identifier = null) | ||
override fun toString(): String = "$source Client/$sdkVersion" | ||
|
||
/** | ||
* Simpler class for Android clients. | ||
*/ | ||
class Android(sdkVersion: String) : Client(source = "Android", sdkVersion = sdkVersion) | ||
|
||
/** | ||
* Simpler class for ReactNative clients. | ||
*/ | ||
class ReactNative(sdkVersion: String) : Client(source = "ReactNative", sdkVersion = sdkVersion) | ||
|
||
/** | ||
* Simpler class for Expo clients. | ||
*/ | ||
class Expo(sdkVersion: String) : Client(source = "Expo", sdkVersion = sdkVersion) | ||
|
||
companion object { | ||
fun fromSource(source: String): Client { | ||
val identifier = source.lowercase(Locale.ENGLISH) | ||
return listOf(Android, ReactNative, Expo).find { client -> | ||
client.identifier == identifier | ||
} ?: Other(value = source) | ||
} | ||
} | ||
/** | ||
* Other class to allow adding custom sources for clients that are not | ||
* supported above. | ||
* <p/> | ||
* Use this only if the client platform is not available in the above list. | ||
*/ | ||
class Other( | ||
source: String, | ||
sdkVersion: String | ||
) : Client(source = source, sdkVersion = sdkVersion) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
sdk/src/sharedTest/java/io/customer/sdk/data/store/ClientTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.customer.sdk.data.store | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import io.customer.commontest.BaseTest | ||
import org.amshove.kluent.shouldBeEqualTo | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class ClientTest : BaseTest() { | ||
@Test | ||
fun initialize_givenAndroid_expectAndroidClient() { | ||
val androidClient = Client.Android(sdkVersion = "2.6.3") | ||
|
||
androidClient.toString().shouldBeEqualTo(expected = "Android Client/2.6.3") | ||
} | ||
|
||
@Test | ||
fun initialize_givenExpo_expectExpoClient() { | ||
val expoClient = Client.Expo(sdkVersion = "3.9.7") | ||
|
||
expoClient.toString().shouldBeEqualTo(expected = "Expo Client/3.9.7") | ||
} | ||
|
||
@Test | ||
fun initialize_givenReactNative_expectReactNativeClient() { | ||
val reactNativeClient = Client.ReactNative(sdkVersion = "7.3.2") | ||
|
||
reactNativeClient.toString().shouldBeEqualTo(expected = "ReactNative Client/7.3.2") | ||
} | ||
|
||
@Test | ||
fun initialize_givenOther_expectOtherClient() { | ||
val iOSClient = Client.Other(source = "iOS", sdkVersion = "4.6.7") | ||
|
||
iOSClient.toString().shouldBeEqualTo(expected = "iOS Client/4.6.7") | ||
} | ||
} |