Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ecm/revision #190

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ android.enableJetifier=true
# URL to Klaviyo server
klaviyoServerUrl=https://a.klaviyo.com

# Klaviyo API Revision
klaviyoApiRevision=2023-07-15

# SDK name
klaviyoAndroidSDKName=android

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ internal open class KlaviyoApiRequest(
const val HEADER_KLAVIYO_ATTEMPT = "X-Klaviyo-Attempt-Count"
const val HEADER_RETRY_AFTER = "Retry-After"
const val TYPE_JSON = "application/json"
const val V3_REVISION = "2023-07-15"

const val HTTP_OK = HttpURLConnection.HTTP_OK
const val HTTP_ACCEPTED = HttpURLConnection.HTTP_ACCEPTED
Expand Down Expand Up @@ -173,7 +172,7 @@ internal open class KlaviyoApiRequest(
override val headers: MutableMap<String, String> = mutableMapOf(
HEADER_CONTENT to TYPE_JSON,
HEADER_ACCEPT to TYPE_JSON,
HEADER_REVISION to V3_REVISION,
HEADER_REVISION to Registry.config.apiRevision,
HEADER_USER_AGENT to DeviceProperties.userAgent,
HEADER_KLAVIYO_MOBILE to "1",
HEADER_KLAVIYO_ATTEMPT to "$attempts/${Registry.config.networkMaxAttempts}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal abstract class BaseApiRequestTest<T> : BaseTest() where T : KlaviyoApiR
open val expectedHeaders = mapOf(
"Content-Type" to "application/json",
"Accept" to "application/json",
"Revision" to "2023-07-15",
"Revision" to "1234-56-78",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bring me back to the 1200s

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't worry, our API revision policies will fall forward 790 years

"User-Agent" to "Mock User Agent",
"X-Klaviyo-Mobile" to "1",
"X-Klaviyo-Attempt-Count" to "0/50" // Note: 0/50 is just the default, it increments to 1/50 before a real send!
Expand Down
3 changes: 3 additions & 0 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ subprojects {
localProperties.load(new FileInputStream(rootProject.file("local.properties")))
}
def serverTarget = localProperties["localKlaviyoServerUrl"] ?: klaviyoServerUrl
def apiRevision = localProperties["localKlaviyoApiRevision"] ?: klaviyoApiRevision

defaultConfig {
minSdkVersion versionFor(project, "version.android.minSdk") as Integer
Expand Down Expand Up @@ -46,12 +47,14 @@ subprojects {
minifyEnabled false
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
buildConfigField "String", "KLAVIYO_SERVER_URL", "\"${serverTarget}\""
buildConfigField "String", "KLAVIYO_API_REVISION", "\"${apiRevision}\""
buildConfigField "String", "VERSION", "\"${versionFor(project, "version.klaviyo.versionName")}\""
buildConfigField "String", "NAME", "\"${klaviyoAndroidSDKName}\""
}
debug {
debuggable = true
buildConfigField "String", "KLAVIYO_SERVER_URL", "\"${serverTarget}\""
buildConfigField "String", "KLAVIYO_API_REVISION", "\"${apiRevision}\""
buildConfigField "String", "VERSION", "\"${versionFor(project, "version.klaviyo.versionName")}\""
buildConfigField "String", "NAME", "\"${klaviyoAndroidSDKName}\""
}
Expand Down
2 changes: 2 additions & 0 deletions sdk/core/src/main/java/com/klaviyo/core/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.klaviyo.core.networking.NetworkMonitor
interface Config {
val isDebugBuild: Boolean
val baseUrl: String
val apiRevision: String
val sdkName: String
val sdkVersion: String

Expand All @@ -27,6 +28,7 @@ interface Config {
fun apiKey(apiKey: String): Builder
fun applicationContext(context: Context): Builder
fun baseUrl(baseUrl: String): Builder
fun apiRevision(apiRevision: String): Builder
fun sdkName(name: String): Builder
fun sdkVersion(version: String): Builder
fun debounceInterval(debounceInterval: Int): Builder
Expand Down
10 changes: 10 additions & 0 deletions sdk/core/src/main/java/com/klaviyo/core/config/KlaviyoConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,12 @@ object KlaviyoConfig : Config {

override var baseUrl: String = BuildConfig.KLAVIYO_SERVER_URL
private set
override var apiRevision: String = BuildConfig.KLAVIYO_API_REVISION
private set
override var sdkName: String = BuildConfig.NAME
private set
override var sdkVersion: String = BuildConfig.VERSION
private set
override lateinit var apiKey: String private set
override lateinit var applicationContext: Context private set
override var debounceInterval = DEBOUNCE_INTERVAL
Expand Down Expand Up @@ -129,6 +133,7 @@ object KlaviyoConfig : Config {
private var apiKey: String = ""
private var applicationContext: Context? = null
private var baseUrl: String? = null
private var apiRevision: String? = null
private var sdkName: String? = null
private var sdkVersion: String? = null
private var debounceInterval: Int = DEBOUNCE_INTERVAL
Expand Down Expand Up @@ -159,6 +164,10 @@ object KlaviyoConfig : Config {
this.baseUrl = baseUrl
}

override fun apiRevision(apiRevision: String): Config.Builder = apply {
this.apiRevision = apiRevision
}

override fun sdkName(name: String): Config.Builder = apply {
this.sdkName = name
}
Expand Down Expand Up @@ -244,6 +253,7 @@ object KlaviyoConfig : Config {
packageInfo.assertRequiredPermissions(requiredPermissions)

baseUrl?.let { KlaviyoConfig.baseUrl = it }
apiRevision?.let { KlaviyoConfig.apiRevision = it }
sdkName?.let { KlaviyoConfig.sdkName = it }
sdkVersion?.let { KlaviyoConfig.sdkVersion = it }
KlaviyoConfig.apiKey = apiKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ abstract class BaseTest {
every { networkFlushIntervals } returns longArrayOf(10_000, 30_000, 60_000)
every { networkJitterRange } returns 0..0
every { baseUrl } returns "https://test.fake-klaviyo.com"
every { apiRevision } returns "1234-56-78"
}
protected val mockLifecycleMonitor = mockk<LifecycleMonitor>().apply {
every { onActivityEvent(any()) } returns Unit
Expand Down
Loading