code examples

This commit is contained in:
Christian Landgren 2020-12-06 23:04:52 +01:00
parent d29a2b7d73
commit ee7c336356
4 changed files with 67 additions and 11 deletions

View File

@ -49,4 +49,4 @@ spec:
paths:
- backend:
serviceName: skolplattformen-api
servicePort: 8000
servicePort: 9000

View File

@ -36,28 +36,53 @@ api.register({
const token = await backend.login(c.request.query.socialSecurityNumber)
return res.status(200).json(token)
},
waitForToken: async (c, req, res) => {
const order = c.request.params.order
const cookie = await backend.waitForToken({order})
const jwtToken = jwt.sign(cookie, process.env.JWT_SECRET || 'secret')
return res.status(200).json(jwtToken)
},
getChildren: async (c, req, res) => {
const cookie = c.security.bearerAuth
const children = await backend.getChildren(cookie)
return res.status(200).json(children)
},
getChildById: async (c, req, res) => {
const cookie = c.security.bearerAuth
const childId = c.request.params.order
const child = await backend.getChildById(childId, cookie)
return res.status(200).json(child)
},
getNews: async (c, req, res) => {
const cookie = c.security.bearerAuth
const childId = c.request.params.order
const news = await backend.getNews(childId, cookie)
return res.status(200).json(news)
},
getCalendar: async (c, req, res) => {
const cookie = c.security.bearerAuth
const childId = c.request.params.order
const calendar = await backend.getCalendar(childId, cookie)
return res.status(200).json(calendar)
},
getNotifications: async (c, req, res) => {
const cookie = c.security.bearerAuth
const childId = c.request.params.order
const notifications = await backend.getNotifications(childId, cookie)
return res.status(200).json(notifications)
},
getMenu: async (c, req, res) => {
const cookie = c.security.bearerAuth
const childId = c.request.params.order
const menu = await backend.getMenu(childId, cookie)
return res.status(200).json(menu)
},
getSchedule: async (c, req, res) => {
const cookie = c.security.bearerAuth
const childId = c.request.params.order
const schedule = await backend.getSchedule(childId, cookie)
return res.status(200).json(schedule)
}
})

View File

@ -62,10 +62,10 @@ module.exports = {
login,
waitForToken,
getChildren,
getChildById,
getNews,
getCalendar,
getNotifications,
getMenu,
getSchedule,
getChildById
getSchedule
}

View File

@ -11,15 +11,38 @@ info:
# Introduction
This API is a wrapper on top of the SOA layer behind **Skolplattformen** which is the mandatory platform for schools in Stockholm Stad.
# Get Started
Generate code examples from the OpenAPI yaml (press Download above) or use this as a start:
```
const socialSecurityNumber = '121212121212'
const baseUrl = 'https://skolplattformen-api.snowflake.cash'
const token = await fetch(`${baseUrl}/login?socialSecurityNumber=${socialSecurityNumber}`, {method: 'POST'}).then(res => res.json())
// Now start BankID and authorize, when you do - your jwt token will be ready
const jwt = await fetch(`${baseUrl}/login/${token.order}/jwt`).then(res => res.json())
const headers = {authorization: 'Bearer ' + jwt}
// Use the jwt token as bearer token in your requests
const children = await fetch(`${baseUrl}/children`, {headers}).then(res => res.json())
// Get some details
const childId = children[0].id
const child = await fetch(`${baseUrl}/children/${childId}`, {headers}).then(res => res.json())
const news = await fetch(`${baseUrl}/children/${childId}/news`, {headers}).then(res => res.json())
const calendar = await fetch(`${baseUrl}/children/${childId}/calendar`, {headers}).then(res => res.json())
```
# Disclaimers
I have no affiliate with the Stockholm Stad organisation or any part of any development team for the city. Therefore things may change and suddenly stop working and I have no way of knowing or even a way of contacting you. My motivation for creating this API is purely for personal reasons. I want to develop apps for my own use and have no interest to go deep in the underlying SDK every day so I'm using this API as a way of creating a little bit of sanity and conform the sometimes swinglish structure into something a little bit more consistant.
**Please let me know if you find anything useful and I'll add it**. /Hopefully I can find a reasonable way to release this sourcecode as open source soon./
contact:
name: Christian Landgren
email: christian@landgren.nu
email: christian.landgren@iteam.se
url: https://github.com/irony
x-logo:
url: '/logo.png'
@ -118,6 +141,8 @@ paths:
/children/{childId}/news:
get:
summary: News
operationId: getNews
description: Get list of news items for this child
tags:
- Children
@ -139,6 +164,8 @@ paths:
/children/{childId}/calendar:
get:
summary: Calendar
operationId: getCalendar
description: Get list of calendar events
security:
- bearerAuth: []
@ -161,6 +188,8 @@ paths:
/children/{childId}/notifications:
get:
summary: Notifications
operationId: getNotifications
description: Get list of notifications for this child
security:
- bearerAuth: []
@ -179,6 +208,8 @@ paths:
/children/{childId}/menu:
get:
summary: Lunch Menu
operationId: getMenu
description: Get list of news items for this child
security:
- bearerAuth: []
@ -197,6 +228,8 @@ paths:
/children/{childId}/schedule:
get:
summary: Schedule
operationId: getSchedule
description: Get list of news items for this child
security:
- bearerAuth: []
@ -212,8 +245,6 @@ paths:
responses:
'200':
description: OK
components:
schemas: