1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 namespace tiny_premium\external; 18 19 use context; 20 use core_external\external_api; 21 use core_external\external_function_parameters; 22 use core_external\external_single_structure; 23 use core_external\external_value; 24 25 /** 26 * External API for Tiny Premium. 27 * 28 * @package tiny_premium 29 * @copyright 2023 David Woloszyn <david.woloszyn@moodle.com> 30 * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 31 */ 32 class get_api_key extends external_api { 33 34 /** 35 * Describes the parameters for Tiny Premium API key. 36 * 37 * @return external_function_parameters 38 * @since Moodle 4.3 39 */ 40 public static function execute_parameters(): external_function_parameters { 41 return new external_function_parameters([ 42 'contextid' => new external_value(PARAM_INT, 'The current context ID.', VALUE_REQUIRED), 43 ]); 44 } 45 46 /** 47 * External function to get the Tiny Premium API key. 48 * 49 * @param int $contextid 50 * @return array 51 * @since Moodle 4.3 52 */ 53 public static function execute(int $contextid): array { 54 [ 55 'contextid' => $contextid, 56 ] = self::validate_parameters(self::execute_parameters(), [ 57 'contextid' => $contextid, 58 ]); 59 60 $context = context::instance_by_id($contextid); 61 self::validate_context($context); 62 return [ 63 'apikey' => get_config('tiny_premium', 'apikey'), 64 ]; 65 } 66 67 /** 68 * Describes the data returned from the external function. 69 * 70 * @return external_single_structure 71 * @since Moodle 4.3 72 */ 73 public static function execute_returns(): external_single_structure { 74 return new external_single_structure([ 75 'apikey' => new external_value(PARAM_ALPHANUM, 'The API key for Tiny Premium'), 76 ]); 77 } 78 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body