|
| 1 | +package com.svix.kotlin |
| 2 | + |
| 3 | +import com.svix.kotlin.exceptions.ApiException |
| 4 | +import com.svix.kotlin.internal.apis.WebhookEndpointApi as OperationalWebhookEndpointApi |
| 5 | +import com.svix.kotlin.models.OperationalWebhookEndpointIn |
| 6 | +import com.svix.kotlin.models.OperationalWebhookEndpointOut |
| 7 | +import com.svix.kotlin.models.OperationalWebhookEndpointSecretOut |
| 8 | +import com.svix.kotlin.models.OperationalWebhookEndpointSecretIn |
| 9 | +import com.svix.kotlin.models.OperationalWebhookEndpointUpdate |
| 10 | +import com.svix.kotlin.models.ListResponseOperationalWebhookEndpointOut |
| 11 | + |
| 12 | +class OperationalWebhookEndpoint internal constructor(token: String, options: SvixOptions) { |
| 13 | + val api = OperationalWebhookEndpointApi(options.serverUrl) |
| 14 | + |
| 15 | + init { |
| 16 | + api.accessToken = token |
| 17 | + api.userAgent = options.getUA() |
| 18 | + options.initialRetryDelayMillis?.let { api.initialRetryDelayMillis = it } |
| 19 | + options.numRetries?.let { api.numRetries = it } |
| 20 | + } |
| 21 | + |
| 22 | + suspend fun list( |
| 23 | + options: OperationalWebhookEndpointListOptions = OperationalWebhookEndpointListOptions(), |
| 24 | + ): ListResponseOperationalWebhookEndpointOut { |
| 25 | + try { |
| 26 | + return api.listOperationalWebhookEndpoints( |
| 27 | + options.limit, |
| 28 | + options.iterator, |
| 29 | + options.order, |
| 30 | + ) |
| 31 | + } catch (e: Exception) { |
| 32 | + throw ApiException.wrap(e) |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + suspend fun create( |
| 37 | + endpointIn: OperationalWebhookEndpointIn, |
| 38 | + options: PostOptions = PostOptions(), |
| 39 | + ): OperationalWebhookEndpointOut { |
| 40 | + try { |
| 41 | + return api.createOperationalWebhookEndpoint( |
| 42 | + endpointIn, |
| 43 | + options.idempotencyKey, |
| 44 | + ) |
| 45 | + } catch (e: Exception) { |
| 46 | + throw ApiException.wrap(e) |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + suspend fun get( |
| 51 | + endpointId: String, |
| 52 | + ): OperationalWebhookEndpointOut { |
| 53 | + try { |
| 54 | + return api.getOperationalWebhookEndpoint(endpointId) |
| 55 | + } catch (e: Exception) { |
| 56 | + throw ApiException.wrap(e) |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + suspend fun update( |
| 61 | + endpointId: String, |
| 62 | + endpointUpdate: OperationalWebhookEndpointUpdate, |
| 63 | + ): OperationalWebhookEndpointOut { |
| 64 | + try { |
| 65 | + return api.updateOperationalWebhookEndpoint( |
| 66 | + endpointId, |
| 67 | + endpointUpdate, |
| 68 | + ) |
| 69 | + } catch (e: Exception) { |
| 70 | + throw ApiException.wrap(e) |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + suspend fun delete( |
| 75 | + endpointId: String, |
| 76 | + ) { |
| 77 | + try { |
| 78 | + api.deleteOperationalWebhookEndpoint(endpointId) |
| 79 | + } catch (e: Exception) { |
| 80 | + throw ApiException.wrap(e) |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + suspend fun getSecret( |
| 85 | + endpointId: String, |
| 86 | + ): OperationalWebhookEndpointSecretOut { |
| 87 | + try { |
| 88 | + return api.getOperationalWebhookEndpointSecret( |
| 89 | + endpointId, |
| 90 | + ) |
| 91 | + } catch (e: Exception) { |
| 92 | + throw ApiException.wrap(e) |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + suspend fun rotateSecret( |
| 97 | + endpointId: String, |
| 98 | + endpointSecretRotateIn: OperationalWebhookEndpointSecretIn, |
| 99 | + options: PostOptions = PostOptions(), |
| 100 | + ) { |
| 101 | + try { |
| 102 | + api.rotateOperationalWebhookEndpointSecret( |
| 103 | + endpointId, |
| 104 | + endpointSecretRotateIn, |
| 105 | + options.idempotencyKey, |
| 106 | + ) |
| 107 | + } catch (e: Exception) { |
| 108 | + throw ApiException.wrap(e) |
| 109 | + } |
| 110 | + } |
| 111 | +} |
0 commit comments