\smtech\CanvasPestCanvasPestImmutable

Treat the API as read-only.

Without excessive editorializing, the permissions structure in Canvas bites. For example, one can't create a user who has read-only access to the complete API -- if a user has complete access to the API, they have complete access to the API, including the ability to alter and delete information. This object provides a comparative level of safety, enforcing a restriction on GET-only API calls.

Summary

Methods
Properties
Constants
__construct()
setupToken()
get()
post()
put()
delete()
patch()
No public properties found
PARAM_PER_PAGE
prepHeaders()
postprocessResponse()
http_build_query()
$headers
N/A
preprocessData()
No private properties found
N/A

Constants

PARAM_PER_PAGE

PARAM_PER_PAGE

Name of the parameter controlling the number of responses per page

Properties

$headers

$headers : array<mixed,string>

Type

array<mixed,string> — Additional headers to be passed to the API with each call

Methods

__construct()

__construct(string  $apiInstanceUrl, string  $apiAuthorizationToken = null) 

Construct a new CanvasPest

Parameters

string $apiInstanceUrl

URL of the API instance (e.g. 'https://canvas.instructure.com/api/v1')

string $apiAuthorizationToken

(Optional) API access token for the API instance (if not provided now, it will need to be provided later)

setupToken()

setupToken(string  $token) : boolean

Set up a new API access token to access this instance

Parameters

string $token

API access token

Throws

\smtech\CanvasPest\CanvasPest_Exception

INVALID_TOKEN on an empty or non-string token value

Returns

boolean

get()

get(string  $path, string|array<mixed,string>  $data = array(), string|array<mixed,string>  $headers = array()) : \smtech\CanvasPest\CanvasObject|\smtech\CanvasPest\CanvasArray|false

Make a GET call to the API

For queries to individually identified endpoints (e.g. accounts/1/users/123), return a CanvasObject representing the API response describing that individually identified object affected by the query.

For queries to generic endpoints (e.g. accounts/1/users), return a traversable CanvasArray (of CanvasObjects) representing the API response describing the list of objects affected by the query.

Parameters

string $path

Path to the API endpoint of this call

string|array<mixed,string> $data

(Optional) Query parameters for this call

string|array<mixed,string> $headers

(Optional) Any additional HTTP headers for this call

Returns

\smtech\CanvasPest\CanvasObject|\smtech\CanvasPest\CanvasArray|false

post()

post(string  $path, string|array<mixed,string>  $data = array(), string|array<mixed,string>  $headers = array()) : void

Make a POST call to the API

For queries to individually identified endpoints (e.g. accounts/1/users/123), return a CanvasObject representing the API response describing that individually identified object affected by the query.

Parameters

string $path

Path to the API endpoint of this call

string|array<mixed,string> $data

(Optional) Query parameters for this call

string|array<mixed,string> $headers

(Optional) Any additional HTTP headers for this call

Throws

\smtech\CanvasPest\CanvasPestImmutable_Exception

IMMUTABLE All calls to this method will cause an exception

put()

put(string  $path, string|array<mixed,string>  $data = array(), string|array<mixed,string>  $headers = array()) : void

Make a PUT call to the API

For queries to individually identified endpoints (e.g. accounts/1/users/123), return a CanvasObject representing the API response describing that individually identified object affected by the query.

Parameters

string $path

Path to the API endpoint of this call

string|array<mixed,string> $data

(Optional) Query parameters for this call

string|array<mixed,string> $headers

(Optional) Any additional HTTP headers for this call

Throws

\smtech\CanvasPest\CanvasPestImmutable_Exception

IMMUTABLE All calls to this method will cause an exception

delete()

delete(string  $path, string|array<mixed,string>  $data = array(), string|array<mixed,string>  $headers = array()) : void

Make a DELETE call to the API

For queries to individually identified endpoints (e.g. accounts/1/users/123), return a CanvasObject representing the API response describing that individually identified object affected by the query.

Parameters

string $path

Path to the API endpoint of this call

string|array<mixed,string> $data

(Optional) Query parameters for this call

string|array<mixed,string> $headers

(Optional) Any additional HTTP headers for this call

Throws

\smtech\CanvasPest\CanvasPestImmutable_Exception

IMMUTABLE All calls to this method will cause an exception

patch()

patch(string  $path, string|array<mixed,string>  $data = array(), string|array<mixed,string>  $headers = array()) : false

Make a PATCH call to the API

Parameters

string $path

Path to the API endpoint of this call

string|array<mixed,string> $data

(Optional) Query parameters for this call

string|array<mixed,string> $headers

(Optional) Any additional HTTP headers for this call

Throws

\smtech\CanvasPest\CanvasPest_Exception

UNSUPPORTED_METHOD All calls to this method will cause an exception

Returns

false

prepHeaders()

prepHeaders(array<mixed,string>  $headers) : array<mixed,string>

Prepare API request headers

Flatten headers from an associative array to a numerically indexed array of "Name: Value" style entries like CURLOPT_HTTPHEADER expects. Numerically indexed arrays are not modified.

Extended by CanvasPest to include the API access token in the Authorization header.

Parameters

array<mixed,string> $headers

Returns

array<mixed,string>

postprocessResponse()

postprocessResponse(string  $response) : \smtech\CanvasPest\CanvasObject|\smtech\CanvasPest\CanvasArray|false

Parse the API response into an object (or collection of objects).

For queries to individually identified endpoints (e.g. accounts/1/users/123), return a CanvasObject representing the API response describing that individually identified object affected by the query.

For queries to generic endpoints (e.g. accounts/1/users), return a traversable CanvasArray (of CanvasObjects) representing the API response describing the list of objects affected by the query.

Parameters

string $response

JSON-encoded response from the API

Throws

\smtech\CanvasPest\CanvasPest_Exception

INVALID_JSON_RESPONSE if an non-JSON-formatted response is received (and $this->throw_exceptions is true -- otherwise it returns false)

Returns

\smtech\CanvasPest\CanvasObject|\smtech\CanvasPest\CanvasArray|false

http_build_query()

http_build_query(mixed  $data) : string

Reformat query parameters for Canvas

Specifically, Canvas expects no numeric indices for base array parameters.

Parameters

mixed $data

Returns

string

preprocessData()

preprocessData(array<mixed,string>  $data) : array<mixed,string>

Preprocess API call parameters before use

Force maximum response page size, if not already defined.

Parameters

array<mixed,string> $data

Array of parameters for the next API call

Returns

array<mixed,string> —

Updated array of parameters