Skip to content

Instantly share code, notes, and snippets.

@ivanpepelko
Created December 23, 2021 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivanpepelko/f7532a0b5ea7841d3cc8e9fe08440192 to your computer and use it in GitHub Desktop.
Save ivanpepelko/f7532a0b5ea7841d3cc8e9fe08440192 to your computer and use it in GitHub Desktop.
Brain games API

CORS settings

All requests must include credentials, cookies are used to identify users ( see XMLHttpRequest.withCredentials).

GET /games

Returns game list:

[
    {
        "description": "",
        "visible": true,
        "mobileRoot": "/bloomingdale_mobile",
        "id": "bloomingdale",
        "name": "Bloomingdale",
        "category": null,
        "root": "/bloomingdale",
        "dataUrl": "/Build/uncompressed.data",
        "frameworkUrl": "/Build/uncompressed.framework.js",
        "codeUrl": "/Build/uncompressed.wasm",
        "img": "/img/bloom-play.png",
        "loadingImg": "/img/bloom_2048x1536_preload.png",
        "tips": [
            "__Train your information processing skills by remembering flowers you last saw__",
            "__Skills you will train:__\n- Cognitive flexibility\n- Flexible thinking\n- Adapting to various situations\n"
        ],
        "colors": {
            "loadingBar": "white"
        },
        "loadingImgFit": "cover",
        "mobileLoadingImg": "/img/bloom_1080x1920_mobile_preload.png"
    }
    // more results...
]

GET /statistics/:game/(last|high)/:metric/:count?

  • :game: game.id from /games
  • last: returns the most recently saved metric
  • high: returns the highest valued metric
  • :metric: statistic name, eg. score for game score, played for play counter... (be consistent!!!)
  • :count: defaults to 1, number of records to return

Response if count == 1 (or :count omitted):

{
    "date": "2021-12-14T16:11:29.000Z",
    "metric": "score",
    "value": 3195
}

Response if count > 1:

[
    {
        "date": "2021-12-14T16:11:29.000Z",
        "metric": "score",
        "value": 3195
    }
    // more results...
]

GET /statistics/:game/count/:metric/

Parameters same as above.

Response:

{
    "count": 0
}

GET /statistics/:game/aggregate/:metric/

Parameters same as above.

Returns aggregates of requested metric:

{
    "min": 0,
    "max": 0,
    "avg": 0,
    "count": 0,
    "sum": 0
}

POST /statistics/:game

Saves statistics data.

  • :game: game.id from /games

Body:

  • application/x-www-form-urlencoded:
score=5400&correct_answers=24
  • application/json
{
    "score": 5400,
    "correct_answers": 24
}

Body is parsed as typescript type Record<string, number> (a hash with string keys and numeric values).

Response is empty, with status 201 on success, or 500 on error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment