Git Product home page Git Product logo

node-canvas-lms's Introduction

canvas-lms

A simple node.js wrapper for the Canvas LMS API, with some sugar!

Quick Overview

The only required parameter is host, but in most cases, you'll also want an auth token to do anything useful.

var Canvas = require('canvas-lms');

var lms = new Canvas({
	host: 'https://canvas.instructure.com',
	token: 'YOUR-TOKEN',
	name: ' (Optional) My Awesome Canvas Site'
});

// OR
var lms = new Canvas('https://canvas.instructure.com', 'YOUR-TOKEN', options);

The Cavnas object is a very simple API wrapper based around requests, designed to allow easier access. There's two basics:

  • Options: Pass an options object when creating a Canvas instance. There are currently a few parameters, but only token is required.
    • token: an auth token to access your Canvas instance. [See these docs.][canvas-token]
    • version: This defaults to "v1", which is currently the only version of the Canvas LMS API. However, if versions change, the support is there.
    • name: is an optional name for the Canvas instance. It's useful for debugging if you have lots of different instances.
    • TODO: - headers, ID formats

Functions

A Canvas object has 4 main functions: get, post, put, delete.

  • .get(endpoint, query, callback)

  • .post(endpoint, query, form, callback)

  • .put(endpoint, query, form, callback)

  • .delete(endpoint, query, callback)

  • endpoint is a string, which is the URL you are calling. It should start from the part after "v1/" in the Canvas URL.

    • Example:
      • The full URL: https://bcourses.berkeley.edu/api/v1/courses/1371647/users
      • Should be written as: courses/1371647/users
  • query is a native object which gets encoded as a querystring by node.

    • Example:

      • The object:
       {
       	per_page: 100,
       	include: ['assignments', 'user']
       }
      • Will return: ?per_page=100&include[]=assignments&include[]=user
    • This have been designed to follow Canvas conventions for querystring formats (which are based on Rails). I highly recommend using this object format rather than writing your own strings!

  • callback: Is a request callback. It has the format:

     function (err, response, body) {
    
     }
    • Note that body will be parsed and return a native JS object, rather than a JSON string.
  • form: For put and post requests, a form parameter is usually expected. This us a URL-form-encoded parameter. TODO: reference canvas docs...

Shorthand

All functions support a shorthand format, where query and form are empty. In that case the method signatures look like this:

  • .get(endpoint, callback)
  • .post(endpoint, callback)
  • .put(endpoint, callback)
  • .delete(endpoint, callback)

Course Objects

FUTURE

Requirements

canvas-lms makes use of ES6, so please use Node.js 4.2.x or newer. To use an older version of node, please use the v0.0.7 tag. 4.2 has LTS; this hopefully isn't a terrible restriction!

Development

The master branch tracks the stable version, which is published to npm. Development occurs on the dev branch. Currently This is going through a pretty big update, so be sure to check that out.

node-canvas-lms's People

Contributors

aaronbean avatar cycomachead avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-canvas-lms's Issues

Promises support

options.usePromises should exist. We should (in theory) only need to change the _http() method to work.

Optional cute functions, I suppose would need to check what this.http is returning I suppose...

Consider a streaming API

This probably only makes sense with multiple pages of data?

Good node code can/should make use of .pipe() and it seems like it'd be really cool to be able to use this for either uploading data or pulling down lots of data.

Use a `method_missing` type tool to allow more readable API calls.

The format should be:
Course(1371647).group_categories(50724).groups(queryParams?, cb)
Which is the same as:
Course(1371647).group_categories(50724).groups.get(queryParams?, cb)

But should also exist:
Course(1371647).group_categories(50724).groups.delete(queryParams?, cb)
Course(1371647).group_categories(50724).groups.post(queryParams?, form?, cb)
Course(1371647).group_categories(50724).groups.put(queryParams?, form?, cb)

Where the default arguments format is followed.

Supper Easy fuzzy matching

A super useful tool would be a simple .find() wrapper around a request that handles pagination, and supports fuzzy string matching, perhaps with a threshold?

If using promises the code could be really clean because could do Course(12345).students().find(cb) but that wouldn't be able to handle pages... So Course(12345).allPage().students().find(cb) or Course(12345).find(term).students(cb)

cb could either be a callback or replaced with .then() potentially...

Assignment Override Due Dates Helper?

Assignment Overrides return the wrong due date when run in the context of the TA -- "wrong" being the furthest out date that's due.

  • We should make it easy to get the due time for "everyone" (canvas term)
  • We should have a function to take in a student ID and find the due date for that person.

QueryStrings are broken

Work around: append to url...which is like not the point of having a library with an abstraction, but oh well. :P

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.