All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.stytch.java.b2b.api.scimconnections.SCIMConnections.kt Maven / Gradle / Ivy

There is a newer version: 6.7.0
Show newest version
package com.stytch.java.b2b.api.scimconnections

// !!!
// WARNING: This file is autogenerated
// Only modify code within MANUAL() sections
// or your changes may be overwritten later!
// !!!

import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
import com.stytch.java.b2b.models.scimconnections.CreateRequest
import com.stytch.java.b2b.models.scimconnections.CreateRequestOptions
import com.stytch.java.b2b.models.scimconnections.CreateResponse
import com.stytch.java.b2b.models.scimconnections.DeleteRequest
import com.stytch.java.b2b.models.scimconnections.DeleteRequestOptions
import com.stytch.java.b2b.models.scimconnections.DeleteResponse
import com.stytch.java.b2b.models.scimconnections.GetRequest
import com.stytch.java.b2b.models.scimconnections.GetRequestOptions
import com.stytch.java.b2b.models.scimconnections.GetResponse
import com.stytch.java.b2b.models.scimconnections.RotateCancelRequest
import com.stytch.java.b2b.models.scimconnections.RotateCancelRequestOptions
import com.stytch.java.b2b.models.scimconnections.RotateCancelResponse
import com.stytch.java.b2b.models.scimconnections.RotateCompleteRequest
import com.stytch.java.b2b.models.scimconnections.RotateCompleteRequestOptions
import com.stytch.java.b2b.models.scimconnections.RotateCompleteResponse
import com.stytch.java.b2b.models.scimconnections.RotateStartRequest
import com.stytch.java.b2b.models.scimconnections.RotateStartRequestOptions
import com.stytch.java.b2b.models.scimconnections.RotateStartResponse
import com.stytch.java.b2b.models.scimconnections.UpdateRequest
import com.stytch.java.b2b.models.scimconnections.UpdateRequestOptions
import com.stytch.java.b2b.models.scimconnections.UpdateResponse
import com.stytch.java.common.InstantAdapter
import com.stytch.java.common.StytchResult
import com.stytch.java.http.HttpClient
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.future.asCompletableFuture
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.concurrent.CompletableFuture

public interface Connections {
    /**
     * Update a SCIM Connection. /%}
     */
    public suspend fun update(
        data: UpdateRequest,
        methodOptions: UpdateRequestOptions? = null,
    ): StytchResult

    /**
     * Update a SCIM Connection. /%}
     */
    public fun update(
        data: UpdateRequest,
        methodOptions: UpdateRequestOptions? = null,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Update a SCIM Connection. /%}
     */
    public fun updateCompletable(
        data: UpdateRequest,
        methodOptions: UpdateRequestOptions? = null,
    ): CompletableFuture>

    /**
     * Deletes a SCIM Connection. /%}
     */
    public suspend fun delete(
        data: DeleteRequest,
        methodOptions: DeleteRequestOptions? = null,
    ): StytchResult

    /**
     * Deletes a SCIM Connection. /%}
     */
    public fun delete(
        data: DeleteRequest,
        methodOptions: DeleteRequestOptions? = null,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Deletes a SCIM Connection. /%}
     */
    public fun deleteCompletable(
        data: DeleteRequest,
        methodOptions: DeleteRequestOptions? = null,
    ): CompletableFuture>

    /**
     * Start a SCIM token rotation. /%}
     */
    public suspend fun rotateStart(
        data: RotateStartRequest,
        methodOptions: RotateStartRequestOptions? = null,
    ): StytchResult

    /**
     * Start a SCIM token rotation. /%}
     */
    public fun rotateStart(
        data: RotateStartRequest,
        methodOptions: RotateStartRequestOptions? = null,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Start a SCIM token rotation. /%}
     */
    public fun rotateStartCompletable(
        data: RotateStartRequest,
        methodOptions: RotateStartRequestOptions? = null,
    ): CompletableFuture>

    /**
     * Completes a SCIM token rotation. This will complete the current token rotation process and update the active token to
     * be the new token supplied in the [start SCIM token rotation](https://stytch.com/docs/b2b/api/scim-rotate-token-start)
     * response. /%}
     */
    public suspend fun rotateComplete(
        data: RotateCompleteRequest,
        methodOptions: RotateCompleteRequestOptions? = null,
    ): StytchResult

    /**
     * Completes a SCIM token rotation. This will complete the current token rotation process and update the active token to
     * be the new token supplied in the [start SCIM token rotation](https://stytch.com/docs/b2b/api/scim-rotate-token-start)
     * response. /%}
     */
    public fun rotateComplete(
        data: RotateCompleteRequest,
        methodOptions: RotateCompleteRequestOptions? = null,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Completes a SCIM token rotation. This will complete the current token rotation process and update the active token to
     * be the new token supplied in the [start SCIM token rotation](https://stytch.com/docs/b2b/api/scim-rotate-token-start)
     * response. /%}
     */
    public fun rotateCompleteCompletable(
        data: RotateCompleteRequest,
        methodOptions: RotateCompleteRequestOptions? = null,
    ): CompletableFuture>

    /**
     * Cancel a SCIM token rotation. This will cancel the current token rotation process, keeping the original token active.
     * /%}
     */
    public suspend fun rotateCancel(
        data: RotateCancelRequest,
        methodOptions: RotateCancelRequestOptions? = null,
    ): StytchResult

    /**
     * Cancel a SCIM token rotation. This will cancel the current token rotation process, keeping the original token active.
     * /%}
     */
    public fun rotateCancel(
        data: RotateCancelRequest,
        methodOptions: RotateCancelRequestOptions? = null,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Cancel a SCIM token rotation. This will cancel the current token rotation process, keeping the original token active.
     * /%}
     */
    public fun rotateCancelCompletable(
        data: RotateCancelRequest,
        methodOptions: RotateCancelRequestOptions? = null,
    ): CompletableFuture>

    /**
     * Create a new SCIM Connection. /%}
     */
    public suspend fun create(
        data: CreateRequest,
        methodOptions: CreateRequestOptions? = null,
    ): StytchResult

    /**
     * Create a new SCIM Connection. /%}
     */
    public fun create(
        data: CreateRequest,
        methodOptions: CreateRequestOptions? = null,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Create a new SCIM Connection. /%}
     */
    public fun createCompletable(
        data: CreateRequest,
        methodOptions: CreateRequestOptions? = null,
    ): CompletableFuture>

    /**
     * Get SCIM Connections. /%}
     */
    public suspend fun get(
        data: GetRequest,
        methodOptions: GetRequestOptions? = null,
    ): StytchResult

    /**
     * Get SCIM Connections. /%}
     */
    public fun get(
        data: GetRequest,
        methodOptions: GetRequestOptions? = null,
        callback: (StytchResult) -> Unit,
    )

    /**
     * Get SCIM Connections. /%}
     */
    public fun getCompletable(
        data: GetRequest,
        methodOptions: GetRequestOptions? = null,
    ): CompletableFuture>
}

internal class ConnectionsImpl(
    private val httpClient: HttpClient,
    private val coroutineScope: CoroutineScope,
) : Connections {
    private val moshi = Moshi.Builder().add(InstantAdapter()).build()

    override suspend fun update(
        data: UpdateRequest,
        methodOptions: UpdateRequestOptions?,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()
            methodOptions?.let {
                headers = methodOptions.addHeaders(headers)
            }

            val asJson = moshi.adapter(UpdateRequest::class.java).toJson(data)
            httpClient.put("/v1/b2b/scim/${data.organizationId}/connections/${data.connectionId}", asJson, headers)
        }

    override fun update(
        data: UpdateRequest,
        methodOptions: UpdateRequestOptions?,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(update(data, methodOptions))
        }
    }

    override fun updateCompletable(
        data: UpdateRequest,
        methodOptions: UpdateRequestOptions?,
    ): CompletableFuture> =
        coroutineScope.async {
            update(data, methodOptions)
        }.asCompletableFuture()

    override suspend fun delete(
        data: DeleteRequest,
        methodOptions: DeleteRequestOptions?,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()
            methodOptions?.let {
                headers = methodOptions.addHeaders(headers)
            }

            httpClient.delete("/v1/b2b/scim/${data.organizationId}/connections/${data.connectionId}", headers)
        }

    override fun delete(
        data: DeleteRequest,
        methodOptions: DeleteRequestOptions?,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(delete(data, methodOptions))
        }
    }

    override fun deleteCompletable(
        data: DeleteRequest,
        methodOptions: DeleteRequestOptions?,
    ): CompletableFuture> =
        coroutineScope.async {
            delete(data, methodOptions)
        }.asCompletableFuture()

    override suspend fun rotateStart(
        data: RotateStartRequest,
        methodOptions: RotateStartRequestOptions?,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()
            methodOptions?.let {
                headers = methodOptions.addHeaders(headers)
            }

            val asJson = moshi.adapter(RotateStartRequest::class.java).toJson(data)
            httpClient.post("/v1/b2b/scim/${data.organizationId}/connections/${data.connectionId}/rotate/start", asJson, headers)
        }

    override fun rotateStart(
        data: RotateStartRequest,
        methodOptions: RotateStartRequestOptions?,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(rotateStart(data, methodOptions))
        }
    }

    override fun rotateStartCompletable(
        data: RotateStartRequest,
        methodOptions: RotateStartRequestOptions?,
    ): CompletableFuture> =
        coroutineScope.async {
            rotateStart(data, methodOptions)
        }.asCompletableFuture()

    override suspend fun rotateComplete(
        data: RotateCompleteRequest,
        methodOptions: RotateCompleteRequestOptions?,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()
            methodOptions?.let {
                headers = methodOptions.addHeaders(headers)
            }

            val asJson = moshi.adapter(RotateCompleteRequest::class.java).toJson(data)
            httpClient.post("/v1/b2b/scim/${data.organizationId}/connections/${data.connectionId}/rotate/complete", asJson, headers)
        }

    override fun rotateComplete(
        data: RotateCompleteRequest,
        methodOptions: RotateCompleteRequestOptions?,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(rotateComplete(data, methodOptions))
        }
    }

    override fun rotateCompleteCompletable(
        data: RotateCompleteRequest,
        methodOptions: RotateCompleteRequestOptions?,
    ): CompletableFuture> =
        coroutineScope.async {
            rotateComplete(data, methodOptions)
        }.asCompletableFuture()

    override suspend fun rotateCancel(
        data: RotateCancelRequest,
        methodOptions: RotateCancelRequestOptions?,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()
            methodOptions?.let {
                headers = methodOptions.addHeaders(headers)
            }

            val asJson = moshi.adapter(RotateCancelRequest::class.java).toJson(data)
            httpClient.post("/v1/b2b/scim/${data.organizationId}/connections/${data.connectionId}/rotate/cancel", asJson, headers)
        }

    override fun rotateCancel(
        data: RotateCancelRequest,
        methodOptions: RotateCancelRequestOptions?,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(rotateCancel(data, methodOptions))
        }
    }

    override fun rotateCancelCompletable(
        data: RotateCancelRequest,
        methodOptions: RotateCancelRequestOptions?,
    ): CompletableFuture> =
        coroutineScope.async {
            rotateCancel(data, methodOptions)
        }.asCompletableFuture()

    override suspend fun create(
        data: CreateRequest,
        methodOptions: CreateRequestOptions?,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()
            methodOptions?.let {
                headers = methodOptions.addHeaders(headers)
            }

            val asJson = moshi.adapter(CreateRequest::class.java).toJson(data)
            httpClient.post("/v1/b2b/scim/${data.organizationId}/connections", asJson, headers)
        }

    override fun create(
        data: CreateRequest,
        methodOptions: CreateRequestOptions?,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(create(data, methodOptions))
        }
    }

    override fun createCompletable(
        data: CreateRequest,
        methodOptions: CreateRequestOptions?,
    ): CompletableFuture> =
        coroutineScope.async {
            create(data, methodOptions)
        }.asCompletableFuture()

    override suspend fun get(
        data: GetRequest,
        methodOptions: GetRequestOptions?,
    ): StytchResult =
        withContext(Dispatchers.IO) {
            var headers = emptyMap()
            methodOptions?.let {
                headers = methodOptions.addHeaders(headers)
            }

            val asJson = moshi.adapter(GetRequest::class.java).toJson(data)
            val type = Types.newParameterizedType(Map::class.java, String::class.java, Any::class.java)
            val adapter: JsonAdapter> = moshi.adapter(type)
            val asMap = adapter.fromJson(asJson) ?: emptyMap()
            httpClient.get("/v1/b2b/scim/${data.organizationId}/connections", asMap, headers)
        }

    override fun get(
        data: GetRequest,
        methodOptions: GetRequestOptions?,
        callback: (StytchResult) -> Unit,
    ) {
        coroutineScope.launch {
            callback(get(data, methodOptions))
        }
    }

    override fun getCompletable(
        data: GetRequest,
        methodOptions: GetRequestOptions?,
    ): CompletableFuture> =
        coroutineScope.async {
            get(data, methodOptions)
        }.asCompletableFuture()
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy