Skip to content

Commit 9853563

Browse files
committed
feat: add unregister
1 parent 4169db2 commit 9853563

File tree

1 file changed

+13
-0
lines changed
  • src/commonMain/kotlin/dev/zxilly/notify/sdk

1 file changed

+13
-0
lines changed

src/commonMain/kotlin/dev/zxilly/notify/sdk/Client.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ class Client private constructor(
102102
(resp.body() as Response<Boolean>).body
103103
}
104104

105+
suspend fun unregister(deviceID: String) = wrap {
106+
if (!isUUID(deviceID)) {
107+
throw Error("Device ID is not a valid UUID")
108+
}
109+
110+
val resp = client.delete("$endpoint/$userID/token/$deviceID")
111+
if (!resp.ok()) {
112+
val err: ErrorResponse = resp.body()
113+
throw Exception("Error code ${err.code}: ${err.body}")
114+
}
115+
(resp.body() as Response<Boolean>).body
116+
}
117+
105118
suspend fun <T> fetchMessage(postProcessor: List<MessageItem>.() -> List<T>) = wrap {
106119
val resp = client.get("$endpoint/$userID/record")
107120
if (!resp.ok()) {

0 commit comments

Comments
 (0)