-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#76-support-auth-header): remove moko network dependency
- Loading branch information
Showing
17 changed files
with
200 additions
and
257 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
94 changes: 51 additions & 43 deletions
94
...c/commonMain/kotlin/app/meetacy/sdk/engine/ktor/requests/invitations/InvitationsEngine.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,73 +1,81 @@ | ||
package app.meetacy.sdk.engine.ktor.requests.invitations | ||
|
||
import app.meetacy.sdk.engine.ktor.requests.extencion.post | ||
import app.meetacy.sdk.engine.ktor.response.models.StatusTrueResponse | ||
import app.meetacy.sdk.engine.ktor.toInvitation | ||
import app.meetacy.sdk.engine.requests.* | ||
import app.meetacy.sdk.engine.requests.AcceptInvitationRequest | ||
import app.meetacy.sdk.engine.requests.CancelInvitationRequest | ||
import app.meetacy.sdk.engine.requests.CreateInvitationRequest | ||
import app.meetacy.sdk.engine.requests.DenyInvitationRequest | ||
import app.meetacy.sdk.types.url.Url | ||
import dev.icerock.moko.network.generated.apis.InvitationsApi | ||
import dev.icerock.moko.network.generated.apis.InvitationsApiImpl | ||
import io.ktor.client.* | ||
import kotlinx.serialization.json.Json | ||
import dev.icerock.moko.network.generated.models.AcceptInvitationRequest as GeneratedAcceptInvitationRequest | ||
import dev.icerock.moko.network.generated.models.CancelInvitationRequest as GeneratedCancelInvitationRequest | ||
import dev.icerock.moko.network.generated.models.CreateInvitationRequest as GeneratedCreateInvitationRequest | ||
import dev.icerock.moko.network.generated.models.DenyInvitationRequest as GeneratedDenyInvitationRequest | ||
import kotlinx.serialization.json.buildJsonObject | ||
import kotlinx.serialization.json.put | ||
|
||
internal class InvitationsEngine( | ||
private val baseUrl: Url, | ||
baseUrl: Url, | ||
private val httpClient: HttpClient, | ||
json: Json | ||
private val json: Json | ||
) { | ||
private val base: InvitationsApi = InvitationsApiImpl(baseUrl.string, httpClient, json) | ||
|
||
private val baseUrl = baseUrl / "invitations" | ||
suspend fun create( | ||
request: CreateInvitationRequest | ||
): CreateInvitationRequest.Response { | ||
val response = base.invitationsCreatePost( | ||
createInvitationRequest = GeneratedCreateInvitationRequest( | ||
meetingId = request.meetingId.string, | ||
userId = request.userId.string | ||
), | ||
apiVersion = request.apiVersion.int.toString(), | ||
authorization = request.token.string | ||
).result | ||
val url = baseUrl / "create" | ||
|
||
val jsonObject = buildJsonObject { | ||
put("meetingId", request.meetingId.string) | ||
put("userId", request.userId.string) | ||
} | ||
|
||
val string = post(url.string, jsonObject, httpClient, request) | ||
|
||
val response = json.decodeFromString<app.meetacy.sdk.engine.ktor.response.models.CreateInvitationResponse>(string).result | ||
|
||
return CreateInvitationRequest.Response(response.toInvitation()) | ||
} | ||
|
||
suspend fun accept( | ||
request: AcceptInvitationRequest | ||
) { | ||
base.invitationsAcceptPost( | ||
acceptInvitationRequest = GeneratedAcceptInvitationRequest( | ||
id = request.invitationId.string | ||
), | ||
apiVersion = request.apiVersion.int.toString(), | ||
authorization = request.token.string | ||
) | ||
): StatusTrueResponse { | ||
val url = baseUrl / "accept" | ||
|
||
val jsonObject = buildJsonObject { | ||
put("invitationId", request.invitationId.string) | ||
} | ||
|
||
val string = post(url.string, jsonObject, httpClient, request) | ||
|
||
return json.decodeFromString<StatusTrueResponse>(string) | ||
} | ||
|
||
suspend fun deny( | ||
request: DenyInvitationRequest | ||
) { | ||
base.invitationsDenyPost( | ||
denyInvitationRequest = GeneratedDenyInvitationRequest( | ||
id = request.invitationId.string | ||
), | ||
apiVersion = request.apiVersion.int.toString(), | ||
authorization = request.token.string | ||
) | ||
): StatusTrueResponse { | ||
val url = baseUrl / "deny" | ||
|
||
val jsonObject = buildJsonObject { | ||
put("invitationId", request.invitationId.string) | ||
} | ||
|
||
val string = post(url.string, jsonObject, httpClient, request) | ||
|
||
return json.decodeFromString<StatusTrueResponse>(string) | ||
} | ||
|
||
suspend fun cancel( | ||
request: CancelInvitationRequest | ||
) { | ||
base.invitationsCancelPost( | ||
cancelInvitationRequest = GeneratedCancelInvitationRequest( | ||
id = request.invitationId.string | ||
), | ||
apiVersion = request.apiVersion.int.toString(), | ||
authorization = request.token.string | ||
) | ||
): StatusTrueResponse { | ||
val url = baseUrl / "cancel" | ||
|
||
val jsonObject = buildJsonObject { | ||
put("invitationId", request.invitationId.string) | ||
} | ||
|
||
val string = post(url.string, jsonObject, httpClient, request) | ||
|
||
return json.decodeFromString<StatusTrueResponse>(string) | ||
} | ||
|
||
} |
Oops, something went wrong.