institute-courses-api

1.0.2 • Public • Published

Institute courses API for Node JS

A fully async API written in ES6 for fetching courses from various sources


npm badge

Setting up

Installing
npm install institute-courses-api
Quickstart
CLI
# Install
> npm install -g institute-courses-api
# Use
> institute-courses-api --help
 
Fetch courses
 
Options:
  --help                  Show help                                    [boolean]
  --version               Show version number                          [boolean]
  --parallel-sources      The number of sources to process simultaneously
                                                                    [default: 1]
  --parallel-requests     The number of requests to send simultaneously
                                                                    [default: 3]
  --minimum-delay         The minimum number of milliseconds to wait between
                          requests                                [default: 100]
  --maximum-delay         The maximum number of milliseconds to wait between
                          requests                               [default: 1000]
  --courses-to-fetch, -n  The amount of courses to fetch from each source (0
                          means all). Rounds up to nearest batch    [default: 0]
  --output, -o            Path to the output file
  -d, --debug             Run in debugging mode                        [boolean]
 
Library
const {BTH, fetchCourses} = require('institute-courses-api');
 
// Fetch courses from all institutes
const bth = new BTH();
fetchCourses(bth).then(courses => {
  console.log(courses[0]);
});
{
  "other": {
    "appliable": false,
    "applicationCode": "S5531",
    "start": "SOM18",
    "points": 15,
    "topic": "Medieteknik"
  },
  "name": "Idé- och konceptutveckling för entreprenörskap",
  "url": "url-to-course-page",
  "code": "ME1595",
  "books": [],
  "source": "bth"
}

Documentation

The documentation is currently a bit sparse. For more information, refer to the source and issues on GitHub.

Methods

The module exposes the following

const {
  BTH, // Source
  sources, // Enumerable array of the sources above
  fetchCourses // Convenience method for fetching courses from a source
} = require('institute-courses-api');

Convenience methods

/**
* Fetch courses from all sources asynchronously.
* @param {Source} source - The source (institute) to fetch courses from.
* @param {Object} options - Optional options
* @param {Number} options.parallelRequests - The number of requests to send simultaneously.
* @param {Number} options.minimumDelay - The minimum number of milliseconds to wait between requests.
* @param {Number} options.maximumDelay - The maximum number of milliseconds to wait between requests.
* @param {Number} options.coursesToFetch - The amount of courses to fetch from each source (0 means all). Rounds up to nearest batch.
* @returns {Array} Array of courses.
*/
async function fetchCourses(source, options) {
  ...
}

Course schema

Each courses generated by this API follows the format as explained in src/course.js as shown below.

class Course {
  constructor() {
    // Information that's not expected to always be available from all sources
    this.other = {};
 
    // Whether or not the course can be applied to
    this.other.appliable = null;
 
    // The course code to apply to on antagning.se
    this.other.applicationCode = null;
 
    // The semester the course starts (such as 'VT-19')
    this.other.start = null;
 
    // The amount of "Högskolepoäng (HP)" the course consists of
    this.other.points = null;
 
    // The topic of the course, such as 'Mathematics'
    this.other.topic = null;
 
    // Name of the course
    this.name = null;
 
    // URL to the course page
    this.url = null;
 
    // The course code, such as 'MA1445'
    this.code = null;
 
    // Book ISBNs included in the course
    this.books = [];
 
    // The source institute (such as BTH)
    this.source = null;
  }
}

Contributing

Any contribution is welcome. If you're not able to code it yourself, perhaps someone else is - so post an issue if there's anything on your mind.

Development

Clone the repository:

git clone https://github.com/AlexGustafsson/institute-courses-api.git && cd institute-courses-api

Set up for development:

npm install

Follow the conventions enforced:

npm run lint
npm run test
npm run coverage
npm run check-duplicate-code

Disclaimer

Although the project is very capable, it is not built with production in mind. Therefore there might be complications when trying to use the API for large-scale projects meant for the public. The API was created to easily fetch information about books programmatically and as such it might not promote best practices nor be performant. This project is not in any way affiliated with BTH.

Readme

Keywords

none

Package Sidebar

Install

npm i institute-courses-api

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

19.9 kB

Total Files

18

Last publish

Collaborators

  • alexgustafsson