diff options
author | Valentin Popov <info@valentineus.link> | 2018-10-29 01:18:56 +0300 |
---|---|---|
committer | Valentin Popov <info@valentineus.link> | 2018-10-29 01:27:57 +0300 |
commit | 6c31017c8df2aede3d21da1227735ed0e2b8d918 (patch) | |
tree | a3df479aae048b01dbea0a0a0fd6b6c8ede43a99 | |
parent | 00309285ba45c8d36863f2ed5ba107164e6aa6fd (diff) | |
download | local_webhooks-6c31017c8df2aede3d21da1227735ed0e2b8d918.tar.xz local_webhooks-6c31017c8df2aede3d21da1227735ed0e2b8d918.zip |
External function to get service data
Signed-off-by: Valentin Popov <info@valentineus.link>
-rw-r--r-- | externallib.php | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/externallib.php b/externallib.php index c64fb84..010b173 100644 --- a/externallib.php +++ b/externallib.php @@ -24,6 +24,7 @@ defined('MOODLE_INTERNAL') || die(); +require_once($CFG->dirroot . '/local/webhooks/lib.php'); require_once($CFG->libdir . '/externallib.php'); /** @@ -34,4 +35,67 @@ require_once($CFG->libdir . '/externallib.php'); * @package local_webhooks */ class local_webhooks_external extends external_api { + /** + * Returns description of method parameters. + * + * @return \external_function_parameters + * + * @since Moodle 2.2 + * @since Moodle 2.9 Options available + */ + public static function get_service_parameters() { + return new external_function_parameters( + array( + 'serviceid' => new external_value(PARAM_INT, 'Service ID.'), + ) + ); + } + + /** + * Get information about the service. + * + * @param $serviceid + * + * @return array + * + * @since Moodle 2.2 + * @since Moodle 2.9 Options available + * + * @throws \dml_exception + * @throws \invalid_parameter_exception + * @throws \moodle_exception + * @throws \restricted_context_exception + */ + public static function get_service($serviceid) { + $parameters = self::validate_parameters(self::get_service_parameters(), array('serviceid' => $serviceid)); + + $context = context_system::instance(); + self::validate_context($context); + + return (array) local_webhooks_api::get_service($parameters['serviceid']); + } + + /** + * Returns description of method result value. + * + * @return \external_single_structure + * + * @since Moodle 2.2 + * @since Moodle 2.9 Options available + */ + public static function get_service_returns() { + return new external_single_structure( + array( + 'id' => new external_value(PARAM_INT, 'Service ID.'), + 'header' => new external_value(PARAM_RAW, 'Type of outgoing header.'), + 'name' => new external_value(PARAM_RAW, 'Name of the service.'), + 'point' => new external_value(PARAM_URL, 'Point of delivery of notifications.'), + 'status' => new external_value(PARAM_BOOL, 'Current status of the service.'), + 'token' => new external_value(PARAM_RAW, 'Token for verification of requests.'), + 'events' => new external_multiple_structure( + new external_value(PARAM_RAW, 'Event name.'), 'List of events.' + ), + ) + ); + } }
\ No newline at end of file |