smtech/canvaspest

This package is abandoned and no longer maintained. No replacement package was suggested.

An extension of Pest to make RESTful queries to the Instructure Canvas API

Maintainers

Package info

github.com/smtech/canvaspest

pkg:composer/smtech/canvaspest

Statistics

Installs: 4 993

Dependents: 3

Suggesters: 0

Stars: 2

Open Issues: 3

v1.1.9 2017-06-14 02:09 UTC

This package is auto-updated.

Last update: 2023-05-25 12:43:06 UTC


README

Latest Version Scrutinizer Code Quality Code Coverage Build Status

Object-oriented access to the Canvas API using PHP.

Install

In your composer.json, include:

"require": {
	"smtech/canvaspest": "1.*"
}

Use

CanvasPest

Create a new CanvasPest to make RESTful queries to the Canvas API:

// construct with the API URL and an API access token
$api = new CanvasPest('https://canvas.instructure.com/api/v1', 'df2bcbad95f606d6e80093f8e40c4e5ca171d8c5e4f2138e1d58273e33b262ef')

Make a RESTful query to the API:

// GET, PUT, POST, DELETE are all supported
$obj = $api->get('users/self/profile');

The response from a query is either a CanvasObject or a CanvasArray (of CanvasObjects, natch), depending on whether you requested a specific object or a list of objects (even if the list turns out to be a single object).

CanvasObjects

CanvasObject fields can be accessed either object-style or array style:

$obj = $api->get('courses/123');
echo $obj['sis_course_id']; // array-style
echo $obj->title; // object-style

CanvasArrays

CanvasArrays can be iterated conveniently using the foreach control structure.

$arr = $api->get('/accounts/1/users');
foreach($arr as $obj) {
	echo $obj->name;
}

One could also access arbitrary elements of the CanvasArray:

$arr = $api->get('accounts/1/courses');
echo $arr[1337]->title;

Note that both CanvasObjects and CanvasArrays are immutable objects -- that is, they are treated as read-only. In fact, if you attempt to alter a CanvasObject or a CanvasArray, exceptions will be thrown.

Full API documentation is available in the repository.