Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 310 and 401] [Versions 39 and 401]

   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  /**
  18   * Google Drive Rest API.
  19   *
  20   * @package    repository_googledocs
  21   * @copyright  2017 Damyon Wiese
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace repository_googledocs;
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * Google Drive Rest API.
  30   *
  31   * @copyright  2017 Damyon Wiese
  32   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class rest extends \core\oauth2\rest {
  35  
  36      /**
  37       * Define the functions of the rest API.
  38       *
  39       * @return array Example:
  40       *  [ 'listFiles' => [ 'method' => 'get', 'endpoint' => 'http://...', 'args' => [ 'folder' => PARAM_STRING ] ] ]
  41       */
  42      public function get_api_functions() {
  43          return [
  44              'list' => [
  45                  'endpoint' => 'https://www.googleapis.com/drive/v3/files',
  46                  'method' => 'get',
  47                  'args' => [
  48                      'corpus' => PARAM_RAW,
  49                      'orderBy' => PARAM_RAW,
  50                      'fields' => PARAM_RAW,
  51                      'pageSize' => PARAM_INT,
  52                      'pageToken' => PARAM_RAW,
  53                      'q' => PARAM_RAW,
  54                      'spaces' => PARAM_RAW,
  55                      'supportsAllDrives' => PARAM_RAW,
  56                      'includeItemsFromAllDrives' => PARAM_RAW,
  57                      'corpora' => PARAM_RAW
  58                  ],
  59                  'response' => 'json'
  60              ],
  61              'get' => [
  62                  'endpoint' => 'https://www.googleapis.com/drive/v3/files/{fileid}',
  63                  'method' => 'get',
  64                  'args' => [
  65                      'fields' => PARAM_RAW,
  66                      'fileid' => PARAM_RAW
  67                  ],
  68                  'response' => 'json'
  69              ],
  70              'copy' => [
  71                  'endpoint' => 'https://www.googleapis.com/drive/v3/files/{fileid}/copy',
  72                  'method' => 'post',
  73                  'args' => [
  74                      'fields' => PARAM_RAW,
  75                      'fileid' => PARAM_RAW
  76                  ],
  77                  'response' => 'json'
  78              ],
  79              'delete' => [
  80                  'endpoint' => 'https://www.googleapis.com/drive/v3/files/{fileid}',
  81                  'method' => 'delete',
  82                  'args' => [
  83                      'fileid' => PARAM_RAW
  84                  ],
  85                  'response' => 'json'
  86              ],
  87              'create' => [
  88                  'endpoint' => 'https://www.googleapis.com/drive/v3/files',
  89                  'method' => 'post',
  90                  'args' => [
  91                      'fields' => PARAM_RAW
  92                  ],
  93                  'response' => 'json'
  94              ],
  95              'update' => [
  96                  'endpoint' => 'https://www.googleapis.com/drive/v3/files/{fileid}',
  97                  'method' => 'patch',
  98                  'args' => [
  99                      'fileid' => PARAM_RAW,
 100                      'fields' => PARAM_RAW,
 101                      'addParents' => PARAM_RAW,
 102                      'removeParents' => PARAM_RAW
 103                  ],
 104                  'response' => 'json'
 105              ],
 106              'create_permission' => [
 107                  'endpoint' => 'https://www.googleapis.com/drive/v3/files/{fileid}/permissions',
 108                  'method' => 'post',
 109                  'args' => [
 110                      'fileid' => PARAM_RAW,
 111                      'emailMessage' => PARAM_RAW,
 112                      'sendNotificationEmail' => PARAM_RAW,
 113                      'transferOwnership' => PARAM_RAW,
 114                  ],
 115                  'response' => 'json'
 116              ],
 117              'update_permission' => [
 118                  'endpoint' => 'https://www.googleapis.com/drive/v3/files/{fileid}/permissions/{permissionid}',
 119                  'method' => 'patch',
 120                  'args' => [
 121                      'fileid' => PARAM_RAW,
 122                      'permissionid' => PARAM_RAW,
 123                      'emailMessage' => PARAM_RAW,
 124                      'sendNotificationEmail' => PARAM_RAW,
 125                      'transferOwnership' => PARAM_RAW,
 126                  ],
 127                  'response' => 'json'
 128              ],
 129              'shared_drives_list' => [
 130                  'endpoint' => 'https://www.googleapis.com/drive/v3/drives',
 131                  'method' => 'get',
 132                  'args' => [
 133                      'pageSize' => PARAM_INT,
 134                      'pageToken' => PARAM_RAW,
 135                      'q' => PARAM_RAW,
 136                      'useDomainAdminAccess' => PARAM_RAW,
 137                  ],
 138                  'response' => 'json',
 139              ],
 140          ];
 141      }
 142  }