Skip to content

Commit 55de090

Browse files
committed
kotlin: Add operational webhook endpoint API
1 parent b0af708 commit 55de090

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.svix.kotlin
2+
3+
import com.svix.kotlin.models.Ordering
4+
5+
class OperationalWebhookEndpointListOptions : ListOptions() {
6+
var order: Ordering? = null
7+
8+
fun order(order: Ordering) = apply { this.order = order }
9+
10+
override fun iterator(iterator: String) = apply { super.iterator(iterator) }
11+
12+
override fun limit(limit: Int) = apply { super.limit(limit) }
13+
}

kotlin/lib/src/main/kotlin/Svix.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ class Svix(token: String, options: SvixOptions = SvixOptions()) {
2323
val message = Message(token, options)
2424
val messageAttempt = MessageAttempt(token, options)
2525
val statistics = Statistics(token, options)
26+
val operationalWebhookEndpoint = OperationalWebhookEndpoint(token, options)
2627
}

0 commit comments

Comments
 (0)