Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
exacs committed Feb 8, 2021
1 parent 00a6292 commit 23cda3e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 52 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ npm i @kth/canvas-api
## Usage

```js
const CanvasApi = require("@kth/canvas-api");
// or, with ES modules:
// import CanvasApi from '@kth/canvas-api/esm'
import CanvasApi from '@kth/canvas-api'
// or, with CommonJS:
// const CanvasApi = require("@kth/canvas-api");

async function start() {
const canvas = CanvasApi("https://kth.instructure.com/api/v1", "XXXX~xxxx");
const canvas = new CanvasApi("https://kth.instructure.com/api/v1", "XXXX~xxxx");
const { body } = await canvas.get("/accounts/1");
}

Expand All @@ -34,8 +34,8 @@ start();
### Create a course

```js
const CanvasApi = require("./index");
const canvas = CanvasApi("https://kth.instructure.com/api/v1", "XXXX~xxxx");
import CanvasApi from '@kth/canvas-api'
const canvas = new CanvasApi("https://kth.instructure.com/api/v1", "XXXX~xxxx");

async function start() {
const { body } = await canvas.requestUrl("/accounts/1/courses", "POST");
Expand All @@ -53,10 +53,10 @@ start();
It is easier to use an array if you want to use JavaScript array methods (map, filter, etc.), when you want to retrieve the entire collection or when you know that the collection has a small size.

```js
const CanvasApi = require("@kth/canvas-api");
import CanvasApi from '@kth/canvas-api'

const courseId = "XXXX";
const canvas = CanvasApi("https://kth.instructure.com/api/v1", "XXXX~xxxx");
const canvas = new CanvasApi("https://kth.instructure.com/api/v1", "XXXX~xxxx");

async function start() {
const sections = (
Expand All @@ -73,8 +73,8 @@ start();
It is better to use an iterable if you don't want to fetch all the resources in a collection (in this case we are interested in **5 courses that...**)

```js
const CanvasApi = require("@kth/canvas-api");
const canvas = CanvasApi("https://kth.instructure.com/api/v1", "XXXX~xxxx");
import CanvasApi from '@kth/canvas-api'
const canvas = new CanvasApi("https://kth.instructure.com/api/v1", "XXXX~xxxx");

function isSustainable(course) {
return course.name.toLowerCase().indexOf("sustain") !== -1;
Expand Down
38 changes: 3 additions & 35 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
"build": "npm test"
},
"exports": {
"require": "./src/index.js",
"import": "./esm/index.mjs"
".": {
"require": "./src/index.js",
"import": "./esm/index.mjs"
}
},
"repository": {
"type": "git",
Expand All @@ -24,14 +26,11 @@
},
"license": "MIT",
"dependencies": {
"@hapi/joi": "^15.1.0",
"debug": "^4.1.1",
"form-data": "^2.5.0",
"got": "^11.8.1",
"query-string": "^6.13.1"
},
"devDependencies": {
"ajv": "^6.12.2",
"ava": "^3.9.0",
"create-test-server": "^3.0.1",
"dotenv": "^8.2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ function getNextUrl(linkHeader) {
}

module.exports = class CanvasAPI {
constructor(apiUrl, apiKey, options = {}) {
constructor(apiUrl, apiToken, options = {}) {
this.gotClient = got.extend({
prefixUrl: apiUrl,
headers: {
Authorization: `Bearer ${apiKey}`,
Authorization: `Bearer ${apiToken}`,
},
responseType: "json",
...options,
Expand Down

0 comments on commit 23cda3e

Please sign in to comment.