chalkpe / node-dimigo

Dimigo REST API wrapper for Node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

node-dimigo

npm v npm dt node v npm l

Dimigo REST API wrapper for Node.js

Installation

$ npm install dimigo

Usage example

import Dimigo from 'dimigo'

const api = new Dimigo({
  host: 'https://api.dimigo.hs.kr/v1',
  username: 'dimigoin', password: 'yay'
})

async function auth (username, password) {
  const me = await api.identifyUser(username, password))

  console.log(me.id, me.nick, me.email) // e.g. 907 Chalk amato17@naver.com
  console.log(`You can update your profile at http://student.dimigo.hs.kr/user/sso?token=${me.ssoToken}&url=/user/profile`)

  switch (me.userType) {
    case 'S':
      const student = await api.getStudent(me.username) // e.g. ChalkPE
      console.log(student.serial, student.name, student.dormitory) // e.g. 2409 박준영 학봉관
      break

    case 'T':
      const teacher = await api.getTeacher(me.username) // e.g. sspark
      console.log(teacher.role, teacher.position, teacher.name) // e.g. 비담임 교사 박성수
      break
  }
}

auth('ChalkPE', 'P@ssw0rd')
  .then(() => console.log('Success!'))
  .catch(err => console.error(err.statusCode, err.message)) // 401 incorrect password.

API Reference

Dimigo

new Dimigo(opts)

Create a new API wrapper.

Param Type Description
opts Object
opts.host String URL of Dimigo REST API server
opts.username String Username for HTTP Basic Authorization
opts.password String Password for HTTP Basic Authorization

Dimigo.createHash(password)

Calculate the Dimigo hash value of a password.

Param Type Description
password String Password to be hashed
Return value ⇒ String

the Dimigo hash of the password

Dimigo hashing algorithm
'@' + sha256(password + sprintf('%010u', crc32(password)))

api.identifyUser(username, password, [hash])

Authenticate and get a data of the user.

Param Type Description
username String Username of Dimigo account
password String Password of Dimigo account
hash Function? Hash function (default: Dimigo.createHash)
Return value ⇒ Object

The user data from Dimigo REST API.

Key Type Description
id int Primary key
username String Unique
email String
name String Korean name
nick String? User-specific name
gender String M: male, F: female, NULL: unknown
userType char S: students, T: teachers, D: dormitory teachers, P: parents, O: others
birthday String? YYYY-MM-DD
status int 10 for active, 0 for deactivated
facePhoto String? Image URL for face image
userPhoto String? Image URL for user-specific image
createdAt String YYYY-MM-DD HH:mm:ss
updatedAt String YYYY-MM-DD HH:mm:ss
passwordHash String? Not available
ssoToken String? SSO token for student.dimigo.hs.kr

api.getStudent(username)

Get a data of enrolled student.

Param Type Description
username String Username of Dimigo student account
Return value ⇒ Object

The student data from Dimigo REST API.

Key Type Description
id int Primary key
username String Unique
name String Korean name
gender String M: male, F: female, NULL: unknown
grade int Current grade (1 to 3)
clazz int Current class (1 to 6)
number int Current number in class
serial String Serial code (e.g. 2409)
rfcardUid String RFID UID of student ID card
facePhoto String? Image URL for face image
userPhoto String? Image URL for user-specific image
dormitory String? Current dormitory (학봉관, 본관 or null)
roomNum String? Current dormitory room number (~3 digits)

api.getTeacher(username)

Get a data of the teacher.

Param Type Description
username String Username of Dimigo teacher account
Return value ⇒ Object

The teacher data from Dimigo REST API.

Key Type Description
id int Primary key
username String Unique
name String Korean name
gender String M: male, F: female, NULL: unknown
position String? e.g. 부장교사, 교사, 교감, 교장
role String? e.g. 담임, 비담임, 1학년부장, IT특성화부장
grade int? Current grade (1 to 3, if role is 담임 or 부담임)
clazz int? Current class (1 to 6, if role is 담임 or 부담임)

About

Dimigo REST API wrapper for Node.js

License:MIT License


Languages

Language:JavaScript 100.0%