aboutsummaryrefslogtreecommitdiff
path: root/lib.php
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2017-12-27 19:43:36 +0300
committerValentin Popov <info@valentineus.link>2017-12-27 19:43:36 +0300
commit91bf79f0307b65d5c505d86b731be248fc093790 (patch)
treed28d87729e2487374ddb598e7dec099af14642f7 /lib.php
parent7d1a0b9fec31f6bb37004e02ae7d41380506e51f (diff)
downloadlocal_webhooks-91bf79f0307b65d5c505d86b731be248fc093790.tar.xz
local_webhooks-91bf79f0307b65d5c505d86b731be248fc093790.zip
Added function to send the request
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