@@ -18,69 +18,69 @@ |
||
| 18 | 18 | **/ |
| 19 | 19 | class CanvasPestImmutable extends CanvasPest |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * {@inheritDoc} |
|
| 23 | - * |
|
| 24 | - * @deprecated CanvasPestImmutable only supports GET calls to the API |
|
| 25 | - * |
|
| 26 | - * @param string $path Path to the API endpoint of this call |
|
| 27 | - * @param string|string[] $data (Optional) Query parameters for this call |
|
| 28 | - * @param string|string[] $headers (Optional) Any additional HTTP headers |
|
| 29 | - * for this call |
|
| 30 | - * @return void |
|
| 31 | - * |
|
| 32 | - * @throws CanvasPestImmutable_Exception IMMUTABLE All calls to this method |
|
| 33 | - * will cause an exception |
|
| 34 | - **/ |
|
| 35 | - public function put($path, $data = array(), $headers = array()) |
|
| 36 | - { |
|
| 37 | - throw new CanvasPestImmutable_Exception( |
|
| 38 | - 'Only GET calls to the API are allowed from CanvasPestImmutable.', |
|
| 39 | - CanvasPestImmutable_Exception::IMMUTABLE |
|
| 40 | - ); |
|
| 41 | - } |
|
| 21 | + /** |
|
| 22 | + * {@inheritDoc} |
|
| 23 | + * |
|
| 24 | + * @deprecated CanvasPestImmutable only supports GET calls to the API |
|
| 25 | + * |
|
| 26 | + * @param string $path Path to the API endpoint of this call |
|
| 27 | + * @param string|string[] $data (Optional) Query parameters for this call |
|
| 28 | + * @param string|string[] $headers (Optional) Any additional HTTP headers |
|
| 29 | + * for this call |
|
| 30 | + * @return void |
|
| 31 | + * |
|
| 32 | + * @throws CanvasPestImmutable_Exception IMMUTABLE All calls to this method |
|
| 33 | + * will cause an exception |
|
| 34 | + **/ |
|
| 35 | + public function put($path, $data = array(), $headers = array()) |
|
| 36 | + { |
|
| 37 | + throw new CanvasPestImmutable_Exception( |
|
| 38 | + 'Only GET calls to the API are allowed from CanvasPestImmutable.', |
|
| 39 | + CanvasPestImmutable_Exception::IMMUTABLE |
|
| 40 | + ); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * {@inheritDoc} |
|
| 45 | - * |
|
| 46 | - * @deprecated CanvasPestImmutable only supports GET calls to the API |
|
| 47 | - * |
|
| 48 | - * @param string $path Path to the API endpoint of this call |
|
| 49 | - * @param string|string[] $data (Optional) Query parameters for this call |
|
| 50 | - * @param string|string[] $headers (Optional) Any additional HTTP headers |
|
| 51 | - * for this call |
|
| 52 | - * @return void |
|
| 53 | - * |
|
| 54 | - * @throws CanvasPestImmutable_Exception IMMUTABLE All calls to this method |
|
| 55 | - * will cause an exception |
|
| 56 | - **/ |
|
| 57 | - public function post($path, $data = array(), $headers = array()) |
|
| 58 | - { |
|
| 59 | - throw new CanvasPestImmutable_Exception( |
|
| 60 | - 'Only GET calls to the API are allowed from CanvasPestImmutable.', |
|
| 61 | - CanvasPestImmutable_Exception::IMMUTABLE |
|
| 62 | - ); |
|
| 63 | - } |
|
| 43 | + /** |
|
| 44 | + * {@inheritDoc} |
|
| 45 | + * |
|
| 46 | + * @deprecated CanvasPestImmutable only supports GET calls to the API |
|
| 47 | + * |
|
| 48 | + * @param string $path Path to the API endpoint of this call |
|
| 49 | + * @param string|string[] $data (Optional) Query parameters for this call |
|
| 50 | + * @param string|string[] $headers (Optional) Any additional HTTP headers |
|
| 51 | + * for this call |
|
| 52 | + * @return void |
|
| 53 | + * |
|
| 54 | + * @throws CanvasPestImmutable_Exception IMMUTABLE All calls to this method |
|
| 55 | + * will cause an exception |
|
| 56 | + **/ |
|
| 57 | + public function post($path, $data = array(), $headers = array()) |
|
| 58 | + { |
|
| 59 | + throw new CanvasPestImmutable_Exception( |
|
| 60 | + 'Only GET calls to the API are allowed from CanvasPestImmutable.', |
|
| 61 | + CanvasPestImmutable_Exception::IMMUTABLE |
|
| 62 | + ); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * {@inheritDoc} |
|
| 67 | - * |
|
| 68 | - * @deprecated CanvasPestImmutable only supports GET calls to the API |
|
| 69 | - * |
|
| 70 | - * @param string $path Path to the API endpoint of this call |
|
| 71 | - * @param string|string[] $data (Optional) Query parameters for this call |
|
| 72 | - * @param string|string[] $headers (Optional) Any additional HTTP headers |
|
| 73 | - * for this call |
|
| 74 | - * @return void |
|
| 75 | - * |
|
| 76 | - * @throws CanvasPestImmutable_Exception IMMUTABLE All calls to this method |
|
| 77 | - * will cause an exception |
|
| 78 | - **/ |
|
| 79 | - public function delete($path, $data = array(), $headers = array()) |
|
| 80 | - { |
|
| 81 | - throw new CanvasPestImmutable_Exception( |
|
| 82 | - 'Only GET calls to the API are allowed from CanvasPestImmutable.', |
|
| 83 | - CanvasPestImmutable_Exception::IMMUTABLE |
|
| 84 | - ); |
|
| 85 | - } |
|
| 65 | + /** |
|
| 66 | + * {@inheritDoc} |
|
| 67 | + * |
|
| 68 | + * @deprecated CanvasPestImmutable only supports GET calls to the API |
|
| 69 | + * |
|
| 70 | + * @param string $path Path to the API endpoint of this call |
|
| 71 | + * @param string|string[] $data (Optional) Query parameters for this call |
|
| 72 | + * @param string|string[] $headers (Optional) Any additional HTTP headers |
|
| 73 | + * for this call |
|
| 74 | + * @return void |
|
| 75 | + * |
|
| 76 | + * @throws CanvasPestImmutable_Exception IMMUTABLE All calls to this method |
|
| 77 | + * will cause an exception |
|
| 78 | + **/ |
|
| 79 | + public function delete($path, $data = array(), $headers = array()) |
|
| 80 | + { |
|
| 81 | + throw new CanvasPestImmutable_Exception( |
|
| 82 | + 'Only GET calls to the API are allowed from CanvasPestImmutable.', |
|
| 83 | + CanvasPestImmutable_Exception::IMMUTABLE |
|
| 84 | + ); |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -20,261 +20,261 @@ |
||
| 20 | 20 | class CanvasPest extends \Battis\Educoder\Pest |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** Name of the parameter controlling the number of responses per page */ |
|
| 24 | - const PARAM_PER_PAGE = 'per_page'; |
|
| 23 | + /** Name of the parameter controlling the number of responses per page */ |
|
| 24 | + const PARAM_PER_PAGE = 'per_page'; |
|
| 25 | 25 | |
| 26 | - /** @var string[] $headers Additional headers to be passed to the API with each call */ |
|
| 27 | - protected $headers; |
|
| 26 | + /** @var string[] $headers Additional headers to be passed to the API with each call */ |
|
| 27 | + protected $headers; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Construct a new CanvasPest |
|
| 31 | - * |
|
| 32 | - * @api |
|
| 33 | - * |
|
| 34 | - * @param string $apiInstanceUrl URL of the API instance (e.g. |
|
| 35 | - * `'https://canvas.instructure.com/api/v1'`) |
|
| 36 | - * @param string $apiAuthorizationToken (Optional) API access token for the |
|
| 37 | - * API instance (if not provided now, it will need to be provided later) |
|
| 38 | - * |
|
| 39 | - * @see CanvasPest::setupToken() To configure the API access token later |
|
| 40 | - **/ |
|
| 41 | - public function __construct($apiInstanceUrl, $apiAuthorizationToken = null) |
|
| 42 | - { |
|
| 43 | - parent::__construct($apiInstanceUrl); |
|
| 44 | - if (!empty($apiAuthorizationToken)) { |
|
| 45 | - $this->setupToken($apiAuthorizationToken); |
|
| 46 | - } |
|
| 47 | - } |
|
| 29 | + /** |
|
| 30 | + * Construct a new CanvasPest |
|
| 31 | + * |
|
| 32 | + * @api |
|
| 33 | + * |
|
| 34 | + * @param string $apiInstanceUrl URL of the API instance (e.g. |
|
| 35 | + * `'https://canvas.instructure.com/api/v1'`) |
|
| 36 | + * @param string $apiAuthorizationToken (Optional) API access token for the |
|
| 37 | + * API instance (if not provided now, it will need to be provided later) |
|
| 38 | + * |
|
| 39 | + * @see CanvasPest::setupToken() To configure the API access token later |
|
| 40 | + **/ |
|
| 41 | + public function __construct($apiInstanceUrl, $apiAuthorizationToken = null) |
|
| 42 | + { |
|
| 43 | + parent::__construct($apiInstanceUrl); |
|
| 44 | + if (!empty($apiAuthorizationToken)) { |
|
| 45 | + $this->setupToken($apiAuthorizationToken); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Set up a new API access token to access this instance |
|
| 51 | - * |
|
| 52 | - * @param string $token API access token |
|
| 53 | - * |
|
| 54 | - * @throws CanvasPest_Exception INVALID_TOKEN on an empty or non-string token value |
|
| 55 | - **/ |
|
| 56 | - public function setupToken($token) |
|
| 57 | - { |
|
| 58 | - if (is_string($token) && !empty($token)) { |
|
| 59 | - $this->headers['Authorization'] = "Bearer $token"; |
|
| 60 | - } elseif ($this->throw_exceptions) { |
|
| 61 | - throw new CanvasPest_Exception( |
|
| 62 | - 'API authorization token must be a non-zero-length string', |
|
| 63 | - CanvasPest_Exception::INVALID_TOKEN |
|
| 64 | - ); |
|
| 65 | - } |
|
| 66 | - } |
|
| 49 | + /** |
|
| 50 | + * Set up a new API access token to access this instance |
|
| 51 | + * |
|
| 52 | + * @param string $token API access token |
|
| 53 | + * |
|
| 54 | + * @throws CanvasPest_Exception INVALID_TOKEN on an empty or non-string token value |
|
| 55 | + **/ |
|
| 56 | + public function setupToken($token) |
|
| 57 | + { |
|
| 58 | + if (is_string($token) && !empty($token)) { |
|
| 59 | + $this->headers['Authorization'] = "Bearer $token"; |
|
| 60 | + } elseif ($this->throw_exceptions) { |
|
| 61 | + throw new CanvasPest_Exception( |
|
| 62 | + 'API authorization token must be a non-zero-length string', |
|
| 63 | + CanvasPest_Exception::INVALID_TOKEN |
|
| 64 | + ); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Preprocess API call parameters before use |
|
| 70 | - * |
|
| 71 | - * Force maximum response page size, if not already defined. |
|
| 72 | - * |
|
| 73 | - * @param string[] $data Array of parameters for the next API call |
|
| 74 | - * |
|
| 75 | - * @return string[] Updated array of parameters |
|
| 76 | - * |
|
| 77 | - * @see CanvasArray::MAXIMUM_PER_PAGE Maximum number of responses per page |
|
| 78 | - * @see CanvasPest::PARAM_PER_PAGE Page size parameter |
|
| 79 | - **/ |
|
| 80 | - private function preprocessData($data) |
|
| 81 | - { |
|
| 82 | - if (is_array($data) && !array_key_exists(self::PARAM_PER_PAGE, $data)) { |
|
| 83 | - $data[self::PARAM_PER_PAGE] = CanvasArray::MAXIMUM_PER_PAGE; |
|
| 84 | - } |
|
| 85 | - return $data; |
|
| 86 | - } |
|
| 68 | + /** |
|
| 69 | + * Preprocess API call parameters before use |
|
| 70 | + * |
|
| 71 | + * Force maximum response page size, if not already defined. |
|
| 72 | + * |
|
| 73 | + * @param string[] $data Array of parameters for the next API call |
|
| 74 | + * |
|
| 75 | + * @return string[] Updated array of parameters |
|
| 76 | + * |
|
| 77 | + * @see CanvasArray::MAXIMUM_PER_PAGE Maximum number of responses per page |
|
| 78 | + * @see CanvasPest::PARAM_PER_PAGE Page size parameter |
|
| 79 | + **/ |
|
| 80 | + private function preprocessData($data) |
|
| 81 | + { |
|
| 82 | + if (is_array($data) && !array_key_exists(self::PARAM_PER_PAGE, $data)) { |
|
| 83 | + $data[self::PARAM_PER_PAGE] = CanvasArray::MAXIMUM_PER_PAGE; |
|
| 84 | + } |
|
| 85 | + return $data; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Prepare API request headers |
|
| 90 | - * |
|
| 91 | - * Flatten headers from an associative array to a numerically indexed array |
|
| 92 | - * of `"Name: Value"` style entries like `CURLOPT_HTTPHEADER` expects. |
|
| 93 | - * Numerically indexed arrays are not modified. |
|
| 94 | - * |
|
| 95 | - * Extended by CanvasPest to include the API access token in the |
|
| 96 | - * `Authorization` header. |
|
| 97 | - * |
|
| 98 | - * @param string[] $headers |
|
| 99 | - * @return string[] |
|
| 100 | - **/ |
|
| 101 | - protected function prepHeaders($headers) |
|
| 102 | - { |
|
| 103 | - return parent::prepHeaders(array_merge($this->headers, $headers)); |
|
| 104 | - } |
|
| 88 | + /** |
|
| 89 | + * Prepare API request headers |
|
| 90 | + * |
|
| 91 | + * Flatten headers from an associative array to a numerically indexed array |
|
| 92 | + * of `"Name: Value"` style entries like `CURLOPT_HTTPHEADER` expects. |
|
| 93 | + * Numerically indexed arrays are not modified. |
|
| 94 | + * |
|
| 95 | + * Extended by CanvasPest to include the API access token in the |
|
| 96 | + * `Authorization` header. |
|
| 97 | + * |
|
| 98 | + * @param string[] $headers |
|
| 99 | + * @return string[] |
|
| 100 | + **/ |
|
| 101 | + protected function prepHeaders($headers) |
|
| 102 | + { |
|
| 103 | + return parent::prepHeaders(array_merge($this->headers, $headers)); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Parse the API response into an object (or collection of objects). |
|
| 108 | - * |
|
| 109 | - * For queries to individually identified endpoints (e.g. |
|
| 110 | - * `accounts/1/users/123`), return a CanvasObject representing the API response |
|
| 111 | - * describing _that_ individually identified object affected by the query. |
|
| 112 | - * |
|
| 113 | - * For queries to generic endpoints (e.g. `accounts/1/users`), return a |
|
| 114 | - * traversable CanvasArray (of CanvasObjects) representing the API response |
|
| 115 | - * describing the list of objects affected by the query. |
|
| 116 | - * |
|
| 117 | - * @param string $response JSON-encoded response from the API |
|
| 118 | - * |
|
| 119 | - * @return CanvasObject|CanvasArray |
|
| 120 | - **/ |
|
| 121 | - protected function postprocessResponse($response) |
|
| 122 | - { |
|
| 123 | - if (substr($response, 0, 1) == '{') { |
|
| 124 | - return new CanvasObject($response); |
|
| 125 | - } elseif (substr($response, 0, 1) == '[') { |
|
| 126 | - return new CanvasArray($response, $this); |
|
| 127 | - } else { |
|
| 128 | - throw new CanvasPest_Exception( |
|
| 129 | - $response, |
|
| 130 | - CanvasPest_Exception::INVALID_JSON_RESPONSE |
|
| 131 | - ); |
|
| 132 | - } |
|
| 133 | - } |
|
| 106 | + /** |
|
| 107 | + * Parse the API response into an object (or collection of objects). |
|
| 108 | + * |
|
| 109 | + * For queries to individually identified endpoints (e.g. |
|
| 110 | + * `accounts/1/users/123`), return a CanvasObject representing the API response |
|
| 111 | + * describing _that_ individually identified object affected by the query. |
|
| 112 | + * |
|
| 113 | + * For queries to generic endpoints (e.g. `accounts/1/users`), return a |
|
| 114 | + * traversable CanvasArray (of CanvasObjects) representing the API response |
|
| 115 | + * describing the list of objects affected by the query. |
|
| 116 | + * |
|
| 117 | + * @param string $response JSON-encoded response from the API |
|
| 118 | + * |
|
| 119 | + * @return CanvasObject|CanvasArray |
|
| 120 | + **/ |
|
| 121 | + protected function postprocessResponse($response) |
|
| 122 | + { |
|
| 123 | + if (substr($response, 0, 1) == '{') { |
|
| 124 | + return new CanvasObject($response); |
|
| 125 | + } elseif (substr($response, 0, 1) == '[') { |
|
| 126 | + return new CanvasArray($response, $this); |
|
| 127 | + } else { |
|
| 128 | + throw new CanvasPest_Exception( |
|
| 129 | + $response, |
|
| 130 | + CanvasPest_Exception::INVALID_JSON_RESPONSE |
|
| 131 | + ); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - /** |
|
| 136 | - * Reformat query parameters for Canvas |
|
| 137 | - * |
|
| 138 | - * Specifically, Canvas expects no numeric indices for base array parameters. |
|
| 139 | - * |
|
| 140 | - * @param mixed $data |
|
| 141 | - * |
|
| 142 | - * @return string |
|
| 143 | - **/ |
|
| 144 | - protected function http_build_query($data) |
|
| 145 | - { |
|
| 146 | - return preg_replace('/%5B\d+%5D/simU', '[]', http_build_query($data)); |
|
| 147 | - } |
|
| 135 | + /** |
|
| 136 | + * Reformat query parameters for Canvas |
|
| 137 | + * |
|
| 138 | + * Specifically, Canvas expects no numeric indices for base array parameters. |
|
| 139 | + * |
|
| 140 | + * @param mixed $data |
|
| 141 | + * |
|
| 142 | + * @return string |
|
| 143 | + **/ |
|
| 144 | + protected function http_build_query($data) |
|
| 145 | + { |
|
| 146 | + return preg_replace('/%5B\d+%5D/simU', '[]', http_build_query($data)); |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * Make a GET call to the API |
|
| 151 | - * |
|
| 152 | - * For queries to individually identified endpoints (e.g. |
|
| 153 | - * `accounts/1/users/123`), return a CanvasObject representing the API response |
|
| 154 | - * describing _that_ individually identified object affected by the query. |
|
| 155 | - * |
|
| 156 | - * For queries to generic endpoints (e.g. `accounts/1/users`), return a |
|
| 157 | - * traversable CanvasArray (of CanvasObjects) representing the API response |
|
| 158 | - * describing the list of objects affected by the query. |
|
| 159 | - * |
|
| 160 | - * @api |
|
| 161 | - * |
|
| 162 | - * @param string $path Path to the API endpoint of this call |
|
| 163 | - * @param string|string[] $data (Optional) Query parameters for this call |
|
| 164 | - * @param string|string[] $headers (Optional) Any additional HTTP headers for this call |
|
| 165 | - * |
|
| 166 | - * @return CanvasObject|CanvasArray |
|
| 167 | - **/ |
|
| 168 | - public function get($path, $data = array(), $headers = array()) |
|
| 169 | - { |
|
| 170 | - return $this->postprocessResponse( |
|
| 171 | - parent::get($path, $this->preprocessData($data), $headers) |
|
| 172 | - ); |
|
| 173 | - } |
|
| 149 | + /** |
|
| 150 | + * Make a GET call to the API |
|
| 151 | + * |
|
| 152 | + * For queries to individually identified endpoints (e.g. |
|
| 153 | + * `accounts/1/users/123`), return a CanvasObject representing the API response |
|
| 154 | + * describing _that_ individually identified object affected by the query. |
|
| 155 | + * |
|
| 156 | + * For queries to generic endpoints (e.g. `accounts/1/users`), return a |
|
| 157 | + * traversable CanvasArray (of CanvasObjects) representing the API response |
|
| 158 | + * describing the list of objects affected by the query. |
|
| 159 | + * |
|
| 160 | + * @api |
|
| 161 | + * |
|
| 162 | + * @param string $path Path to the API endpoint of this call |
|
| 163 | + * @param string|string[] $data (Optional) Query parameters for this call |
|
| 164 | + * @param string|string[] $headers (Optional) Any additional HTTP headers for this call |
|
| 165 | + * |
|
| 166 | + * @return CanvasObject|CanvasArray |
|
| 167 | + **/ |
|
| 168 | + public function get($path, $data = array(), $headers = array()) |
|
| 169 | + { |
|
| 170 | + return $this->postprocessResponse( |
|
| 171 | + parent::get($path, $this->preprocessData($data), $headers) |
|
| 172 | + ); |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * Make a POST call to the API |
|
| 177 | - * |
|
| 178 | - * For queries to individually identified endpoints (e.g. |
|
| 179 | - * `accounts/1/users/123`), return a CanvasObject representing the API response |
|
| 180 | - * describing _that_ individually identified object affected by the query. |
|
| 181 | - * |
|
| 182 | - * For queries to generic endpoints (e.g. `accounts/1/users`), return a |
|
| 183 | - * traversable CanvasArray (of CanvasObjects) representing the API response |
|
| 184 | - * describing the list of objects affected by the query. |
|
| 185 | - * |
|
| 186 | - * @api |
|
| 187 | - * |
|
| 188 | - * @param string $path Path to the API endpoint of this call |
|
| 189 | - * @param string|string[] $data (Optional) Query parameters for this call |
|
| 190 | - * @param string|string[] $headers (Optional) Any additional HTTP headers for this call |
|
| 191 | - * |
|
| 192 | - * @return CanvasObject|CanvasArray |
|
| 193 | - **/ |
|
| 194 | - public function post($path, $data = array(), $headers = array()) |
|
| 195 | - { |
|
| 196 | - return $this->postprocessResponse( |
|
| 197 | - parent::post($path, $this->preprocessData($data), $headers) |
|
| 198 | - ); |
|
| 199 | - } |
|
| 175 | + /** |
|
| 176 | + * Make a POST call to the API |
|
| 177 | + * |
|
| 178 | + * For queries to individually identified endpoints (e.g. |
|
| 179 | + * `accounts/1/users/123`), return a CanvasObject representing the API response |
|
| 180 | + * describing _that_ individually identified object affected by the query. |
|
| 181 | + * |
|
| 182 | + * For queries to generic endpoints (e.g. `accounts/1/users`), return a |
|
| 183 | + * traversable CanvasArray (of CanvasObjects) representing the API response |
|
| 184 | + * describing the list of objects affected by the query. |
|
| 185 | + * |
|
| 186 | + * @api |
|
| 187 | + * |
|
| 188 | + * @param string $path Path to the API endpoint of this call |
|
| 189 | + * @param string|string[] $data (Optional) Query parameters for this call |
|
| 190 | + * @param string|string[] $headers (Optional) Any additional HTTP headers for this call |
|
| 191 | + * |
|
| 192 | + * @return CanvasObject|CanvasArray |
|
| 193 | + **/ |
|
| 194 | + public function post($path, $data = array(), $headers = array()) |
|
| 195 | + { |
|
| 196 | + return $this->postprocessResponse( |
|
| 197 | + parent::post($path, $this->preprocessData($data), $headers) |
|
| 198 | + ); |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * Make a PUT call to the API |
|
| 203 | - * |
|
| 204 | - * For queries to individually identified endpoints (e.g. |
|
| 205 | - * `accounts/1/users/123`), return a CanvasObject representing the API response |
|
| 206 | - * describing _that_ individually identified object affected by the query. |
|
| 207 | - * |
|
| 208 | - * For queries to generic endpoints (e.g. `accounts/1/users`), return a |
|
| 209 | - * traversable CanvasArray (of CanvasObjects) representing the API response |
|
| 210 | - * describing the list of objects affected by the query. |
|
| 211 | - * |
|
| 212 | - * @api |
|
| 213 | - * |
|
| 214 | - * @param string $path Path to the API endpoint of this call |
|
| 215 | - * @param string|string[] $data (Optional) Query parameters for this call |
|
| 216 | - * @param string|string[] $headers (Optional) Any additional HTTP headers for this call |
|
| 217 | - * |
|
| 218 | - * @return CanvasObject|CanvasArray |
|
| 219 | - **/ |
|
| 220 | - public function put($path, $data = array(), $headers = array()) |
|
| 221 | - { |
|
| 222 | - return $this->postprocessResponse( |
|
| 223 | - parent::put($path, $this->preprocessData($data), $headers) |
|
| 224 | - ); |
|
| 225 | - } |
|
| 201 | + /** |
|
| 202 | + * Make a PUT call to the API |
|
| 203 | + * |
|
| 204 | + * For queries to individually identified endpoints (e.g. |
|
| 205 | + * `accounts/1/users/123`), return a CanvasObject representing the API response |
|
| 206 | + * describing _that_ individually identified object affected by the query. |
|
| 207 | + * |
|
| 208 | + * For queries to generic endpoints (e.g. `accounts/1/users`), return a |
|
| 209 | + * traversable CanvasArray (of CanvasObjects) representing the API response |
|
| 210 | + * describing the list of objects affected by the query. |
|
| 211 | + * |
|
| 212 | + * @api |
|
| 213 | + * |
|
| 214 | + * @param string $path Path to the API endpoint of this call |
|
| 215 | + * @param string|string[] $data (Optional) Query parameters for this call |
|
| 216 | + * @param string|string[] $headers (Optional) Any additional HTTP headers for this call |
|
| 217 | + * |
|
| 218 | + * @return CanvasObject|CanvasArray |
|
| 219 | + **/ |
|
| 220 | + public function put($path, $data = array(), $headers = array()) |
|
| 221 | + { |
|
| 222 | + return $this->postprocessResponse( |
|
| 223 | + parent::put($path, $this->preprocessData($data), $headers) |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - /** |
|
| 228 | - * Make a DELETE call to the API |
|
| 229 | - * |
|
| 230 | - * For queries to individually identified endpoints (e.g. |
|
| 231 | - * `accounts/1/users/123`), return a CanvasObject representing the API response |
|
| 232 | - * describing _that_ individually identified object affected by the query. |
|
| 233 | - * |
|
| 234 | - * For queries to generic endpoints (e.g. `accounts/1/users`), return a |
|
| 235 | - * traversable CanvasArray (of CanvasObjects) representing the API response |
|
| 236 | - * describing the list of objects affected by the query. |
|
| 237 | - * |
|
| 238 | - * @api |
|
| 239 | - * |
|
| 240 | - * @param string $path Path to the API endpoint of this call |
|
| 241 | - * @param string|string[] $data (Optional) Query parameters for this call |
|
| 242 | - * @param string|string[] $headers (Optional) Any additional HTTP headers for this call |
|
| 243 | - * |
|
| 244 | - * @return CanvasObject|CanvasArray |
|
| 245 | - **/ |
|
| 246 | - public function delete($path, $data = array(), $headers = array()) |
|
| 247 | - { |
|
| 248 | - if (!empty($data)) { |
|
| 249 | - $pos = strpos($path, '?'); |
|
| 250 | - if ($pos !== false) { |
|
| 251 | - $path = substr($path, 0, $pos); |
|
| 252 | - } |
|
| 253 | - $path .= '?' . $this->http_build_query($data); |
|
| 254 | - } |
|
| 255 | - return $this->postprocessResponse( |
|
| 256 | - parent::delete($path, $headers) |
|
| 257 | - ); |
|
| 258 | - } |
|
| 227 | + /** |
|
| 228 | + * Make a DELETE call to the API |
|
| 229 | + * |
|
| 230 | + * For queries to individually identified endpoints (e.g. |
|
| 231 | + * `accounts/1/users/123`), return a CanvasObject representing the API response |
|
| 232 | + * describing _that_ individually identified object affected by the query. |
|
| 233 | + * |
|
| 234 | + * For queries to generic endpoints (e.g. `accounts/1/users`), return a |
|
| 235 | + * traversable CanvasArray (of CanvasObjects) representing the API response |
|
| 236 | + * describing the list of objects affected by the query. |
|
| 237 | + * |
|
| 238 | + * @api |
|
| 239 | + * |
|
| 240 | + * @param string $path Path to the API endpoint of this call |
|
| 241 | + * @param string|string[] $data (Optional) Query parameters for this call |
|
| 242 | + * @param string|string[] $headers (Optional) Any additional HTTP headers for this call |
|
| 243 | + * |
|
| 244 | + * @return CanvasObject|CanvasArray |
|
| 245 | + **/ |
|
| 246 | + public function delete($path, $data = array(), $headers = array()) |
|
| 247 | + { |
|
| 248 | + if (!empty($data)) { |
|
| 249 | + $pos = strpos($path, '?'); |
|
| 250 | + if ($pos !== false) { |
|
| 251 | + $path = substr($path, 0, $pos); |
|
| 252 | + } |
|
| 253 | + $path .= '?' . $this->http_build_query($data); |
|
| 254 | + } |
|
| 255 | + return $this->postprocessResponse( |
|
| 256 | + parent::delete($path, $headers) |
|
| 257 | + ); |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - /** |
|
| 261 | - * Make a PATCH call to the API |
|
| 262 | - * |
|
| 263 | - * @deprecated The Canvas API does not currently support PATCH calls |
|
| 264 | - * |
|
| 265 | - * @param string $path Path to the API endpoint of this call |
|
| 266 | - * @param string|string[] $data (Optional) Query parameters for this call |
|
| 267 | - * @param string|string[] $headers (Optional) Any additional HTTP headers for this call |
|
| 268 | - * |
|
| 269 | - * @return void |
|
| 270 | - * |
|
| 271 | - * @throws CanvasPest_Exception UNSUPPORTED_METHOD All calls to this method will cause an exception |
|
| 272 | - **/ |
|
| 273 | - public function patch($path, $data = array(), $headers = array()) |
|
| 274 | - { |
|
| 275 | - throw new CanvasPest_Exception( |
|
| 276 | - 'The Canvas API does not support the PATCH method', |
|
| 277 | - CanvasPest_Exception::UNSUPPORTED_METHOD |
|
| 278 | - ); |
|
| 279 | - } |
|
| 260 | + /** |
|
| 261 | + * Make a PATCH call to the API |
|
| 262 | + * |
|
| 263 | + * @deprecated The Canvas API does not currently support PATCH calls |
|
| 264 | + * |
|
| 265 | + * @param string $path Path to the API endpoint of this call |
|
| 266 | + * @param string|string[] $data (Optional) Query parameters for this call |
|
| 267 | + * @param string|string[] $headers (Optional) Any additional HTTP headers for this call |
|
| 268 | + * |
|
| 269 | + * @return void |
|
| 270 | + * |
|
| 271 | + * @throws CanvasPest_Exception UNSUPPORTED_METHOD All calls to this method will cause an exception |
|
| 272 | + **/ |
|
| 273 | + public function patch($path, $data = array(), $headers = array()) |
|
| 274 | + { |
|
| 275 | + throw new CanvasPest_Exception( |
|
| 276 | + 'The Canvas API does not support the PATCH method', |
|
| 277 | + CanvasPest_Exception::UNSUPPORTED_METHOD |
|
| 278 | + ); |
|
| 279 | + } |
|
| 280 | 280 | } |