Skip to content

Commit

Permalink
Merge pull request #82 from meetacy/#79-support-search
Browse files Browse the repository at this point in the history
#79 support search
  • Loading branch information
y9san9 authored Nov 7, 2023
2 parents 68beb41 + ec82afc commit 56d25ff
Show file tree
Hide file tree
Showing 108 changed files with 1,459 additions and 1,204 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Gradle Cache Setup
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v2.4.2
- name: Gradle Sync
run: ./gradlew
- name: Add Sdk Version to Env
Expand All @@ -36,7 +36,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Gradle Cache Setup
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v2.4.2
- name: Gradle Sync
run: ./gradlew
- name: Add Sdk Version to Env
Expand All @@ -51,7 +51,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Gradle Cache Setup
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v2.4.2
- name: Gradle Sync
run: ./gradlew
- name: Add Sdk Version to Env
Expand All @@ -66,7 +66,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Gradle Cache Setup
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v2.4.2
- name: Konan Cache Setup
uses: actions/cache@v3
with:
Expand Down
28 changes: 24 additions & 4 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ jobs:

deploy-multiplatform:
runs-on: ubuntu-latest
outputs:
snapshot_version: ${{ steps.output_version.outputs.snapshot_version }}
steps:
- uses: actions/checkout@v3
- name: Gradle Cache Setup
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v2.4.2
with:
cache-read-only: ${{ github.ref != 'refs/heads/dev' }}
- name: Gradle Sync
Expand All @@ -31,13 +33,16 @@ jobs:
echo "snapshot_version=$snapshot_version" >> $GITHUB_ENV
- name: Publish ${{ env.snapshot_version }}
run: ./gradlew publishKotlinMultiplatformPublicationToMeetacySdkRepository
- name: Add Sdk Version to Output
id: output_version
run: echo "snapshot_version=${{ env.snapshot_version }}" >> $GITHUB_OUTPUT

deploy-jvm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Gradle Cache Setup
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v2.4.2
with:
cache-read-only: ${{ github.ref != 'refs/heads/dev' }}
- name: Gradle Sync
Expand All @@ -54,7 +59,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Gradle Cache Setup
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v2.4.2
with:
cache-read-only: ${{ github.ref != 'refs/heads/dev' }}
- name: Gradle Sync
Expand All @@ -71,7 +76,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Gradle Cache Setup
uses: gradle/gradle-build-action@v2
uses: gradle/gradle-build-action@v2.4.2
with:
cache-read-only: ${{ github.ref != 'refs/heads/dev' }}
- name: Konan Cache Setup
Expand All @@ -90,3 +95,18 @@ jobs:
./gradlew publishIosX64PublicationToMeetacySdkRepository \
publishIosSimulatorArm64PublicationToMeetacySdkRepository \
publishIosArm64PublicationToMeetacySdkRepository
create-release:
runs-on: ubuntu-latest
needs:
- deploy-multiplatform
- deploy-jvm
- deploy-js
- deploy-konan
steps:
- name: Create Release
uses: actions/create-release@v1
with:
tag_name: ${{ needs.deploy-multiplatform.outputs.snapshot_version }}
release_name: Build ${{ needs.deploy-multiplatform.outputs.snapshot_version }}
prerelease: true
3 changes: 3 additions & 0 deletions api/api-ktor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ dependencies {
commonMainImplementation(libs.ktorClientLogging)
commonMainImplementation(libs.ktorClientWebSockets)
commonMainImplementation(libs.rsocketKtorClient)
commonMainImplementation(libs.ktorClientContentNegotiation)
commonMainImplementation(libs.ktorSerializationJson)

commonMainApi(projects.api)
commonMainImplementation(projects.types.serializable)

jvmTestImplementation(libs.ktorClientCio)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package app.meetacy.sdk.engine.ktor

import app.meetacy.sdk.types.auth.Token
import app.meetacy.sdk.version.ApiVersion
import io.ktor.client.request.*
import io.ktor.http.*

public fun HttpRequestBuilder.apiVersion(apiVersion: ApiVersion) {
header("Api-Version", apiVersion.int)
}

public fun HttpRequestBuilder.token(token: Token) {
header(HttpHeaders.Authorization, token.string)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import app.meetacy.sdk.engine.ktor.requests.friends.FriendsEngine
import app.meetacy.sdk.engine.ktor.requests.invitations.InvitationsEngine
import app.meetacy.sdk.engine.ktor.requests.meetings.MeetingsEngine
import app.meetacy.sdk.engine.ktor.requests.notifications.NotificationsEngine
import app.meetacy.sdk.engine.ktor.requests.search.SearchEngine
import app.meetacy.sdk.engine.ktor.requests.updates.UpdatesEngine
import app.meetacy.sdk.engine.ktor.requests.users.UsersEngine
import app.meetacy.sdk.engine.ktor.response.ServerResponse
Expand All @@ -21,7 +22,11 @@ import app.meetacy.sdk.types.url.parametersOf
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.plugins.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.plugins.websocket.*
import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
import io.ktor.utils.io.errors.*
import io.rsocket.kotlin.ktor.client.RSocketSupport
import kotlinx.coroutines.CancellationException
Expand All @@ -39,19 +44,66 @@ public class KtorMeetacyEngine(

private val httpClient = httpClient.config {
expectSuccess = true

install(ContentNegotiation) {
json(json)
}
defaultRequest {
header(HttpHeaders.ContentType, ContentType.Application.Json)
}
}
private val rsocketClient = httpClient.config {
expectSuccess = true
install(WebSockets)
install(RSocketSupport)
}

private val auth = AuthEngine(baseUrl, this.httpClient, this.json)
private val users = UsersEngine(baseUrl, this.httpClient, this.json)
private val friends = FriendsEngine(baseUrl, this.httpClient, this.json)
private val meetings = MeetingsEngine(baseUrl, this.httpClient, this.json)
private val files = FilesEngine(baseUrl, this.httpClient)
private val invitations = InvitationsEngine(baseUrl, this.httpClient, this.json)
private val notifications = NotificationsEngine(baseUrl, this.httpClient, this.json)
private val updates = UpdatesEngine(baseUrl, this.httpClient, this.json)
private val auth = AuthEngine(
baseUrl = baseUrl,
httpClient = this.httpClient
)

private val users = UsersEngine(
baseUrl = baseUrl,
httpClient = this.httpClient
)

private val friends = FriendsEngine(
baseUrl = baseUrl,
httpClient = this.httpClient,
rsocketClient = rsocketClient,
json = this.json
)

private val meetings = MeetingsEngine(
baseUrl = baseUrl,
httpClient = this.httpClient
)

private val files = FilesEngine(
baseUrl = baseUrl,
httpClient = this.httpClient
)

private val invitations = InvitationsEngine(
baseUrl = baseUrl,
httpClient = this.httpClient
)

private val notifications = NotificationsEngine(
baseUrl = baseUrl,
httpClient = this.httpClient
)

private val search = SearchEngine(
baseUrl = baseUrl,
httpClient = this.httpClient
)

private val updates = UpdatesEngine(
baseUrl = baseUrl,
rsocketClient = rsocketClient,
json = this.json
)

override fun getFileUrl(
id: FileId
Expand Down Expand Up @@ -93,12 +145,13 @@ public class KtorMeetacyEngine(
// notifications
is ReadNotificationRequest -> notifications.read(request) as T
is ListNotificationsRequest -> notifications.list(request) as T
// search
is SearchRequest -> search.search(request) as T
// updates
is EmitUpdatesRequest -> updates.stream(request) as T
// not yet supported
is LinkEmailRequest -> notSupported()
is ConfirmEmailRequest -> notSupported()
is TokenProviderEmpty -> notSupported()
}
}

Expand All @@ -107,7 +160,7 @@ public class KtorMeetacyEngine(
block()
} catch (exception: ResponseException) {
val response = try {
json.decodeFromString<ServerResponse.Error>(exception.response.body())
json.decodeFromString<ServerResponse<Nothing>>(exception.response.body()) as ServerResponse.Error
} catch (exception: Throwable) {
throw MeetacyInternalException(cause = exception)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import app.meetacy.sdk.engine.ktor.response.ServerResponse
import app.meetacy.sdk.exception.MeetacyConnectionException
import app.meetacy.sdk.exception.MeetacyInternalException
import app.meetacy.sdk.exception.meetacyApiError
import io.ktor.client.*
import io.ktor.http.*
import io.ktor.utils.io.errors.*
import io.rsocket.kotlin.RSocket
import io.rsocket.kotlin.RSocketError
import io.rsocket.kotlin.ktor.client.rSocket
import kotlinx.coroutines.CancellationException
import kotlinx.serialization.json.Json

Expand All @@ -19,9 +23,9 @@ internal inline fun <T> handleRSocketExceptions(
} catch (exception: RSocketError) {
when (exception) {
is RSocketError.Custom -> {
val response = json.decodeFromString<ServerResponse.Error>(
val response = json.decodeFromString<ServerResponse<Nothing>>(
string = exception.message ?: meetacyApiError(message = "Message should be present when throwing custom error")
)
) as ServerResponse.Error
throw getException(response)
}
else -> {
Expand Down
Loading

0 comments on commit 56d25ff

Please sign in to comment.