-
Notifications
You must be signed in to change notification settings - Fork 12
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
feat(clients): add Kotlin API client #1400
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
c718442
feat: add koltin client generation
aallam bdcb707
apply review changes
aallam cc840eb
fix path encoding
aallam 12cf653
add github action release ci
aallam 0549175
fix: scripts tests
shortcuts ca1f41d
fix class names in builder functions
aallam 6e3c4a4
fix: cts methods and clients
aallam 27bd206
oneof workaround for cts tests
aallam e4b91cf
add kotlin to the ci's artifacts
aallam a0c9c8e
refact: use Duration for timeouts
aallam e819680
Merge branch 'main' into feat/kotlin
aallam c1b5e13
increase cache version
aallam c70a06c
update ci actions
aallam 36013ca
add kotlin constant to setRunVariables.ts
aallam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.0.22 | ||
0.0.23 |
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 |
---|---|---|
|
@@ -31,3 +31,4 @@ dist | |
generators/bin | ||
|
||
**/java/bin/ | ||
**/kotlin/bin/ |
46 changes: 46 additions & 0 deletions
46
clients/algoliasearch-client-kotlin/.github/workflows/release.yml
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,46 @@ | ||
name: Publish Artifacts | ||
|
||
on: | ||
push: | ||
branches: | ||
- next | ||
|
||
jobs: | ||
publish: | ||
name: Publish to Sonatype | ||
runs-on: macos-11 | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Configure JDK | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: temurin | ||
java-version: 11 | ||
|
||
- name: Setup Gradle | ||
uses: gradle/gradle-build-action@v2 | ||
|
||
- name: Compile | ||
run: ./gradlew assemble | ||
|
||
- name: Upload Artifacts | ||
run: ./gradlew publish | ||
env: | ||
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.SONATYPE_NEXUS_USERNAME }} | ||
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.SONATYPE_NEXUS_PASSWORD }} | ||
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_PRIVATE_KEY }} | ||
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_PRIVATE_KEY_ID }} | ||
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PRIVATE_KEY_PASSWORD }} | ||
|
||
- name: Check Snapshot | ||
id: snapshot | ||
run: | | ||
if [[ $(cat ./gradle.properties | grep 'VERSION_NAME=.*-SNAPSHOT') ]]; then | ||
echo "IS_SNAPSHOT=true" >> $GITHUB_OUTPUT | ||
fi | ||
|
||
- name: Release Artifacts | ||
if: ${{ steps.snapshot.outputs.IS_SNAPSHOT != 'true' }} | ||
run: ./gradlew closeAndReleaseRepository |
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,19 @@ | ||
# Gradle | ||
.gradle | ||
gradlew.bat | ||
build | ||
local.properties | ||
reports | ||
build | ||
|
||
# IntelliJ IDEA | ||
.idea | ||
*.iml | ||
*.ipl | ||
*.iws | ||
classes/ | ||
idea-classes/ | ||
coverage-error.log | ||
|
||
# Java | ||
*.hprof |
16 changes: 16 additions & 0 deletions
16
clients/algoliasearch-client-kotlin/.openapi-generator-ignore
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,16 @@ | ||
# OpenAPI Generator Ignore | ||
# Generated by openapi-generator https://github.com/openapitools/openapi-generator | ||
|
||
# Use this file to prevent files from being overwritten by the generator. | ||
# The patterns follow closely to .gitignore or .dockerignore. | ||
|
||
api/** | ||
docs/** | ||
src/** | ||
README.md | ||
|
||
## Gradle | ||
gradle/** | ||
gradlew.bat | ||
build.gradle.kts | ||
settings.gradle.kts |
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,70 @@ | ||
<p align="center"> | ||
<a href="https://www.algolia.com"> | ||
<img alt="Algolia for Kotlin" src="https://raw.githubusercontent.com/algolia/algoliasearch-client-common/master/banners/kotlin.png" > | ||
</a> | ||
|
||
<h4 align="center">The perfect starting point to integrate <a href="https://algolia.com" target="_blank">Algolia</a> within your Kotlin project</h4> | ||
|
||
<p align="center"> | ||
<a href="https://search.maven.org/search?q=a:algoliasearch-client-kotlin"><img src="https://img.shields.io/maven-central/v/com.algolia/algoliasearch-client-kotlin?label=Download" alt="Latest version"></img></a> | ||
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="Licence"></img></a> | ||
</p> | ||
</p> | ||
|
||
<p align="center"> | ||
<a href="https://www.algolia.com/doc/api-client/getting-started/install/kotlin/" target="_blank">Documentation</a> • | ||
<a href="https://discourse.algolia.com" target="_blank">Community Forum</a> • | ||
<a href="http://stackoverflow.com/questions/tagged/algolia" target="_blank">Stack Overflow</a> • | ||
<a href="https://github.com/algolia/algoliasearch-client-kotlin/issues" target="_blank">Report a bug</a> • | ||
<a href="https://www.algolia.com/doc/api-client/troubleshooting/faq/kotlin/" target="_blank">FAQ</a> • | ||
<a href="https://www.algolia.com/support" target="_blank">Support</a> | ||
</p> | ||
|
||
## ✨ Features | ||
|
||
- The Kotlin client is compatible with Kotlin `1.6` and higher. | ||
- It is compatible with Kotlin project on the JVM, such as backend and Android applications. | ||
- It relies on the open source Kotlin libraries for seamless integration into Kotlin projects: | ||
- [Kotlin multiplatform](https://kotlinlang.org/docs/reference/multiplatform.html). | ||
- [Kotlinx serialization](https://github.com/Kotlin/kotlinx.serialization) for json parsing. | ||
- [Kotlinx coroutines](https://github.com/Kotlin/kotlinx.coroutines) for asynchronous operations. | ||
- [Ktor](https://github.com/ktorio/ktor) HTTP client. | ||
- The Kotlin client integrates the actual Algolia documentation in each source file: Request parameters, response fields, methods and concepts; all are documented and link to the corresponding url of the Algolia doc website. | ||
- The client is thread-safe. You can use `SearchClient`, `AnalyticsClient`, and `InsightsClient` in a multithreaded environment. | ||
|
||
## 💡 Getting Started | ||
|
||
Install the Kotlin client by adding the following dependency to your `gradle.build` file: | ||
|
||
```gradle | ||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation "com.algolia:algoliasearch-client-kotlin:$version" | ||
} | ||
``` | ||
Also, choose and add to your dependencies one of [Ktor http client engines](https://ktor.io/docs/http-client-engines.html). | ||
Alternatively, you can use [algoliasearch-client-kotlin-bom](/client-bom). | ||
For full documentation, visit the **[Algolia Kotlin API Client](https://www.algolia.com/doc/api-client/getting-started/install/kotlin/)**. | ||
|
||
### Guides | ||
|
||
- [Getting started](https://github.com/algolia/algoliasearch-client-kotlin/tree/master/docs/GettingStarted.md) | ||
- [DSL](https://github.com/algolia/algoliasearch-client-kotlin/tree/master/docs/DSL.md) | ||
- [Serialization](https://github.com/algolia/algoliasearch-client-kotlin/tree/master/docs/Serialization.md) | ||
- [ExceptionHandling](https://github.com/algolia/algoliasearch-client-kotlin/tree/master/docs/ExceptionHandling.md) | ||
- [Configure the HTTP client](https://github.com/algolia/algoliasearch-client-kotlin/tree/master/docs/HTTPClient.md) | ||
|
||
## ❓ Troubleshooting | ||
|
||
Encountering an issue? Before reaching out to support, we recommend heading to our [FAQ](https://www.algolia.com/doc/api-client/troubleshooting/faq/kotlin/) where you will find answers for the most common issues and gotchas with the client. | ||
|
||
## Use the Dockerfile | ||
|
||
If you want to contribute to this project without installing all its dependencies, you can use our Docker image. Please check our [dedicated guide](DOCKER_README.md) to learn more. | ||
|
||
## 📄 License | ||
|
||
Algolia Kotlin API Client is an open-sourced software licensed under the [MIT license](LICENSE). |
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,30 @@ | ||
import com.diffplug.gradle.spotless.SpotlessExtension | ||
|
||
@Suppress("DSL_SCOPE_VIOLATION") | ||
plugins { | ||
alias(libs.plugins.kotlin.multiplaform) apply false | ||
alias(libs.plugins.kotlinx.serialization) apply false | ||
alias(libs.plugins.kotlinx.binary.validator) apply false | ||
alias(libs.plugins.maven.publish) apply false | ||
alias(libs.plugins.spotless) apply false | ||
} | ||
|
||
subprojects { | ||
apply(plugin = "com.diffplug.spotless") | ||
configure<SpotlessExtension> { | ||
kotlin { | ||
target("**/*.kt") | ||
ktlint() | ||
.editorConfigOverride( | ||
mapOf( | ||
"ktlint_standard_no-wildcard-imports" to "disabled", | ||
"ktlint_standard_trailing-comma-on-declaration-site" to "disabled", | ||
), | ||
) | ||
} | ||
} | ||
} | ||
|
||
tasks.register<Delete>("clean") { | ||
delete(rootProject.buildDir) | ||
} |
16 changes: 16 additions & 0 deletions
16
clients/algoliasearch-client-kotlin/client-bom/build.gradle.kts
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,16 @@ | ||
plugins { | ||
id("com.vanniktech.maven.publish") | ||
id("java-platform") | ||
} | ||
|
||
dependencies { | ||
constraints { | ||
api(projects.client) | ||
api(libs.ktor.client.android) | ||
api(libs.ktor.client.apache) | ||
api(libs.ktor.client.cio) | ||
api(libs.ktor.client.java) | ||
api(libs.ktor.client.jetty) | ||
api(libs.ktor.client.okhttp) | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
clients/algoliasearch-client-kotlin/client-bom/gradle.properties
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,2 @@ | ||
POM_NAME=Algolia Search API Client for Kotlin | ||
POM_ARTIFACT_ID=algoliasearch-client-kotlin-bom |
44 changes: 44 additions & 0 deletions
44
clients/algoliasearch-client-kotlin/client/build.gradle.kts
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,44 @@ | ||
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi | ||
import org.jetbrains.kotlin.konan.target.HostManager | ||
|
||
plugins { | ||
kotlin("multiplatform") | ||
kotlin("plugin.serialization") | ||
id("com.vanniktech.maven.publish") | ||
id("com.diffplug.spotless") | ||
id("binary-compatibility-validator") | ||
} | ||
|
||
@OptIn(ExperimentalKotlinGradlePluginApi::class) | ||
kotlin { | ||
targetHierarchy.default() | ||
|
||
explicitApi() | ||
jvm() | ||
|
||
if (HostManager.hostIsMac) { | ||
iosX64() | ||
iosArm64() | ||
iosSimulatorArm64() | ||
} | ||
|
||
sourceSets { | ||
all { | ||
languageSettings { | ||
optIn("kotlinx.coroutines.ExperimentalCoroutinesApi") | ||
optIn("kotlinx.serialization.ExperimentalSerializationApi") | ||
optIn("com.algolia.client.InternalAlgoliaClient") | ||
} | ||
} | ||
val commonMain by getting { | ||
dependencies { | ||
api(libs.ktor.client.core) | ||
api(libs.kotlinx.serialization.json) | ||
api(libs.ktor.client.logging) | ||
implementation(libs.ktor.client.serialization.json) | ||
implementation(libs.ktor.client.content.negotiation) | ||
implementation(libs.kotlin.datetime) | ||
} | ||
} | ||
} | ||
} |
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,2 @@ | ||
POM_NAME=Algolia Search API Client for Kotlin | ||
POM_ARTIFACT_ID=algoliasearch-client-kotlin |
22 changes: 22 additions & 0 deletions
22
...ch-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/InternalAlgoliaClient.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,22 @@ | ||
package com.algolia.client | ||
|
||
/** | ||
* API marked with this annotation is internal, and it is not intended to be used outside Algolia API client. | ||
* It could be modified or removed without any notice. Using it could cause undefined behaviour and/or any unexpected | ||
* effects. | ||
*/ | ||
@Target( | ||
AnnotationTarget.CLASS, | ||
AnnotationTarget.TYPEALIAS, | ||
AnnotationTarget.FUNCTION, | ||
AnnotationTarget.PROPERTY, | ||
AnnotationTarget.FIELD, | ||
AnnotationTarget.CONSTRUCTOR, | ||
AnnotationTarget.PROPERTY_SETTER, | ||
AnnotationTarget.PROPERTY_SETTER, | ||
) | ||
@RequiresOptIn( | ||
level = RequiresOptIn.Level.ERROR, | ||
message = "This API is internal in Algolia API client and should not be used. It could be removed or changed without notice.", | ||
) | ||
public annotation class InternalAlgoliaClient |
9 changes: 9 additions & 0 deletions
9
...ient-kotlin/client/src/commonMain/kotlin/com/algolia/client/configuration/AgentSegment.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,9 @@ | ||
package com.algolia.client.configuration | ||
|
||
/** | ||
* Represents a segment of algolia agent header. | ||
* | ||
* @property value segment string value | ||
* @property version optional version | ||
*/ | ||
public data class AgentSegment(val value: String, val version: String? = null) |
10 changes: 10 additions & 0 deletions
10
...h-client-kotlin/client/src/commonMain/kotlin/com/algolia/client/configuration/CallType.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,10 @@ | ||
package com.algolia.client.configuration | ||
|
||
/** | ||
* Indicate whether the HTTP call performed is of type [Read] (GET) or [Write] (POST, PUT ..). Used | ||
* to determined which timeout duration to use. | ||
*/ | ||
public enum class CallType { | ||
Read, | ||
Write, | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add
kotlin: true
inmain.yml
where we call restore-artifacts pls ? otherwise this is ignoredThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!