-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from OliverAbdulrahim/feature/webhooks
Feature: allow the creation and deletion of webhooks
- Loading branch information
Showing
3 changed files
with
93 additions
and
11 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
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/org/conservationco/asana/extensions/webhooks/Webhooks.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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.conservationco.asana.extensions.webhooks | ||
|
||
import com.asana.models.Webhook | ||
import com.google.gson.JsonElement | ||
import org.conservationco.asana.AsanaConfig | ||
|
||
class Webhooks( | ||
private val config: AsanaConfig, | ||
) { | ||
|
||
private val client = config.client | ||
|
||
fun createWebhook(resourceGid: String, targetUrl: String): Webhook = | ||
client.webhooks | ||
.createWebhook() | ||
.data("resource", resourceGid) | ||
.data("target", targetUrl) | ||
.execute() | ||
|
||
fun deleteWebhook(webhookGid: String): JsonElement { | ||
return client.webhooks | ||
.deleteWebhook(webhookGid) | ||
.execute() | ||
} | ||
|
||
fun getWebhook(webhookGid: String): JsonElement { | ||
|
||
return client.webhooks | ||
.deleteWebhook(webhookGid) | ||
.execute() | ||
} | ||
|
||
fun getWebhooks(resourceGid: String, workspaceGid: String): List<Webhook> { | ||
return client.webhooks | ||
.getWebhooks(resourceGid, workspaceGid) | ||
.execute() | ||
} | ||
|
||
fun deleteWebhooks(resourceGid: String, workspaceGid: String) = | ||
getWebhooks(resourceGid, workspaceGid) | ||
.forEach { deleteWebhook(it.gid) } | ||
|
||
} |