From 91bf79f0307b65d5c505d86b731be248fc093790 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 27 Dec 2017 20:43:36 +0400 Subject: Added function to send the request --- lib.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib.php') diff --git a/lib.php b/lib.php index 9f89bd8..b6321e4 100644 --- a/lib.php +++ b/lib.php @@ -186,6 +186,29 @@ function local_webhooks_restore_backup($data, $deleterecords = false) { local_webhooks_events::backup_restored(); } +/** + * 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. * -- cgit v1.2.3