aboutsummaryrefslogtreecommitdiff
path: root/lib.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib.php')
-rw-r--r--lib.php23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib.php b/lib.php
index 9f89bd8..b6321e4 100644
--- a/lib.php
+++ b/lib.php
@@ -187,6 +187,29 @@ function local_webhooks_restore_backup($data, $deleterecords = false) {
}
/**
+ * Send the event remotely to the service.
+ *
+ * @param array $event
+ * @param object $callback
+ * @return array
+ */
+function local_webhooks_send_request($event, $callback) {
+ global $CFG;
+
+ $event["host"] = parse_url($CFG->wwwroot)["host"];
+ $event["token"] = $callback->token;
+ $event["extra"] = $callback->other;
+
+ $curl = new curl();
+ $curl->setHeader(array("Content-Type: application/" . $callback->type));
+ $curl->post($callback->url, json_encode($event));
+
+ $response = $curl->getResponse();
+ local_webhooks_events::response_answer($callback->id, $response);
+ return $response;
+}
+
+/**
* Data serialization.
*
* @param array|object $data