diff options
author | Valentin Popov <info@valentineus.link> | 2017-12-27 19:43:36 +0300 |
---|---|---|
committer | Valentin Popov <info@valentineus.link> | 2017-12-27 19:43:36 +0300 |
commit | 91bf79f0307b65d5c505d86b731be248fc093790 (patch) | |
tree | d28d87729e2487374ddb598e7dec099af14642f7 | |
parent | 7d1a0b9fec31f6bb37004e02ae7d41380506e51f (diff) | |
download | local_webhooks-91bf79f0307b65d5c505d86b731be248fc093790.tar.xz local_webhooks-91bf79f0307b65d5c505d86b731be248fc093790.zip |
Added function to send the request
-rw-r--r-- | lib.php | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -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 |