diff options
author | Valentin Popov <info@valentineus.link> | 2017-10-27 11:22:55 +0300 |
---|---|---|
committer | Valentin Popov <info@valentineus.link> | 2017-10-27 11:22:55 +0300 |
commit | 0e4b7bc4d9966020e5546bc5c39a9853c0e1bca7 (patch) | |
tree | 6f8686798028693c5741a4d94021f17e291359da /classes/handler.php | |
parent | d6d13338e31896034f69228a396d8cbdce81a97c (diff) | |
download | local_webhooks-0e4b7bc4d9966020e5546bc5c39a9853c0e1bca7.tar.xz local_webhooks-0e4b7bc4d9966020e5546bc5c39a9853c0e1bca7.zip |
Event registration is added
Diffstat (limited to 'classes/handler.php')
-rw-r--r-- | classes/handler.php | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/classes/handler.php b/classes/handler.php index 5bc5473..6cf1cc1 100644 --- a/classes/handler.php +++ b/classes/handler.php @@ -28,8 +28,6 @@ defined("MOODLE_INTERNAL") || die(); require_once($CFG->libdir . "/filelib.php"); -use curl; - /** * Defines how to work with events. * @@ -100,9 +98,29 @@ class handler { * @param object $callback */ private static function send($data, $callback) { - $curl = new curl(); + $curl = new \curl(); $curl->setHeader(array("Content-Type: application/$callback->type")); $curl->post($callback->url, json_encode($data)); - return $curl->getResponse(); + $response = $curl->getResponse(); + self::logger($callback, $response); + return $response; + } + + /** + * Event logging. + * + * @param array $response + * @param object $callback + */ + private static function logger($callback, $response) { + $event = \local_webhooks\event\response_get::create(array( + "context" => \context_system::instance(0), + "objectid" => $callback->id, + "other" => array( + "status" => $response["HTTP/1.1"] + ) + )); + + $event->trigger(); } }
\ No newline at end of file |