instructure / pandarus

A Ruby library for the Canvas API (and code generator for other languages, eventually)
34 stars 25 forks source link

What is Pandarus?

Pandarus is a Ruby gem client library for the Canvas LMS API. It is auto-generated from the Canvas api documentation.

Included in this repo is also the code generator that has the potential to generate Canvas API support for other programming languages.

Pandarus uses the Swagger 1.2 spec. It depends on the canvas-lms API documentation to be accurate. If the documentation is accurate, the generated code should work. However, there are several known cases where the api documentation cannot conform to the spec, and these cases are broken. We'll try to document known broken cases below.

Warning

Please think carefully about whether or not Pandarus makes sense for your use case. It might make sense to write a smaller wrapper around just the api endpoints that you need.

Potential Risks:

Potential Benefits:

Pandarus was created internally as an experiment, and is only used sporadically internally. As such, it's only updated sporadically as well. It's provided as a way to experiment with the Canvas API, but please understand the risks before using it in a production application.

Installation

gem install pandarus

Example Usage

require 'pandarus'

client = Pandarus::Client.new(
  prefix: "https://pandamonium.instructure.com/api",
  token: "[YOUR API TOKEN HERE]")

client.get_single_course_courses(1)

# => <Pandarus::Course :id=>1 ...>

Documentation

See the Canvas API documentation that Pandarus is built from:

http://api.instructure.com/

Pandarus method names are very similar to the descriptions in the documentation. If you follow three rules, you will be able to access the full API:

  1. All descriptions get lower-cased and spaces become underscores
  2. If there is an 'a', 'an' or 'the' in the description, ignore it
  3. If there are two ways to access an API call (such as via /courses and /sections) then add a _courses or _sections suffix

Examples:

Code Generation

To generate the Ruby gem from Canvas's api-docs.json file:

  1. Install Java 1.8 SDK
  2. Install maven (e.g. brew install maven)
  3. Set the environment variable CANVAS_DIR if your canvas checkout is not located at the relative path ../canvas-lms.
  4. Run ./build-all

Directory Structure

Known Issues

TODO