-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(insights): add algolia agent to insight (#381)
* add algolia agent to insight * apply lint changes
- Loading branch information
Showing
21 changed files
with
107 additions
and
49 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
2 changes: 2 additions & 0 deletions
2
instantsearch-core/src/commonMain/kotlin/com/algolia/instantsearch/core/InstantSearch.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
This file was deleted.
Oops, something went wrong.
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,15 +1,69 @@ | ||
plugins { | ||
kotlin("multiplatform") | ||
id("com.android.library") | ||
id("com.vanniktech.maven.publish") | ||
} | ||
|
||
android { | ||
namespace = "com.algolia.instantsearch.utils" | ||
compileSdk = 33 | ||
|
||
defaultConfig { | ||
minSdk = 21 | ||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
|
||
buildFeatures { | ||
buildConfig = false | ||
} | ||
|
||
testOptions.unitTests.apply { | ||
isIncludeAndroidResources = true | ||
isReturnDefaultValues = true | ||
} | ||
} | ||
|
||
kotlin { | ||
explicitApi() | ||
jvm() | ||
android { | ||
publishAllLibraryVariants() | ||
publishLibraryVariantsGroupedByFlavor = true | ||
} | ||
|
||
sourceSets { | ||
all { | ||
languageSettings.optIn("kotlin.RequiresOptIn") | ||
languageSettings.optIn("com.algolia.instantsearch.InternalInstantSearch") | ||
} | ||
|
||
val commonMain by getting | ||
|
||
val commonJvm by creating { | ||
dependsOn(commonMain) | ||
} | ||
|
||
val androidMain by getting { | ||
dependsOn(commonJvm) | ||
} | ||
|
||
val jvmMain by getting { | ||
dependsOn(commonJvm) | ||
} | ||
} | ||
} | ||
|
||
tasks { | ||
val copyTemplates = register<Copy>("copyTemplates") { | ||
from("src/commonMain/templates") | ||
into("$buildDir/generated/sources/templates/kotlin/main") | ||
val version = project.extensions.extraProperties["VERSION_NAME"] as String // require clean build | ||
expand("projectVersion" to version) | ||
filteringCharset = "UTF-8" | ||
} | ||
kotlin.sourceSets.commonMain.get().kotlin.srcDir(copyTemplates) | ||
} |
5 changes: 5 additions & 0 deletions
5
instantsearch-utils/src/androidMain/kotlin/com/algolia/instantsearch/platform/Env.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,5 @@ | ||
package com.algolia.instantsearch.platform | ||
|
||
import android.os.Build | ||
|
||
internal actual fun osVersion(): String = "Android (${Build.VERSION.SDK_INT})" |
File renamed without changes.
4 changes: 4 additions & 0 deletions
4
instantsearch-utils/src/commonMain/kotlin/com/algolia/instantsearch/platform/Env.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,4 @@ | ||
package com.algolia.instantsearch.platform | ||
|
||
/** Get current os version */ | ||
internal expect fun osVersion(): String |
8 changes: 8 additions & 0 deletions
8
instantsearch-utils/src/commonMain/kotlin/com/algolia/instantsearch/util/agent.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,8 @@ | ||
package com.algolia.instantsearch.util | ||
|
||
import com.algolia.instantsearch.BuildConfig | ||
import com.algolia.instantsearch.InternalInstantSearch | ||
import com.algolia.instantsearch.platform.osVersion | ||
|
||
@InternalInstantSearch | ||
public fun algoliaAgent(libName: String): String = "$libName (${BuildConfig.version}); ${osVersion()}" |
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,6 @@ | ||
package com.algolia.instantsearch | ||
|
||
@InternalInstantSearch | ||
public object BuildConfig { | ||
public const val version: String = "$projectVersion" | ||
} |
4 changes: 4 additions & 0 deletions
4
instantsearch-utils/src/jvmMain/kotlin/com/algolia/instantsearch/platform/Env.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,4 @@ | ||
package com.algolia.instantsearch.platform | ||
|
||
/** Get current os version */ | ||
internal actual fun osVersion(): String = "JVM (${System.getProperty("java.version")})" |
3 changes: 0 additions & 3 deletions
3
instantsearch/src/androidMain/kotlin/com/algolia/instantsearch/searcher/internal/Actual.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 |
---|---|---|
@@ -1,9 +1,6 @@ | ||
package com.algolia.instantsearch.searcher.internal | ||
|
||
import android.os.Build | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.Dispatchers | ||
|
||
internal actual val defaultDispatcher: CoroutineDispatcher = Dispatchers.IO | ||
|
||
internal actual val osVersion = "Android (${Build.VERSION.SDK_INT})" |
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
17 changes: 6 additions & 11 deletions
17
...search/src/commonMain/kotlin/com/algolia/instantsearch/searcher/internal/withUserAgent.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 |
---|---|---|
@@ -1,20 +1,15 @@ | ||
package com.algolia.instantsearch.searcher.internal | ||
|
||
import com.algolia.instantsearch.core.InstantSearch | ||
import com.algolia.instantsearch.extension.telemetrySchema | ||
import com.algolia.instantsearch.util.algoliaAgent | ||
import com.algolia.search.dsl.requestOptions | ||
import com.algolia.search.transport.RequestOptions | ||
import io.ktor.http.HttpHeaders | ||
|
||
internal fun RequestOptions?.withUserAgent(): RequestOptions { | ||
internal fun RequestOptions?.withAlgoliaAgent(): RequestOptions { | ||
return requestOptions(this) { | ||
header(HttpHeaders.UserAgent, userAgent()) | ||
} | ||
} | ||
|
||
private fun userAgent(): String { | ||
return buildString { | ||
append("$osVersion; ${InstantSearch.userAgent}") | ||
telemetrySchema()?.let { append("; $it") } | ||
parameter("X-Algolia-Agent", buildString { | ||
append(algoliaAgent("InstantSearchAndroid")) | ||
telemetrySchema()?.let { append("; $it") } | ||
}) | ||
} | ||
} |
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