2.0 KiB
Dreamspace API Demo
This repository contains some demo code to test and play with the Dreamspace API.
NOTE: Do not use these demos incautiously on the live production API. The demo flows test a variety of API endpoints, including one that deletes all the users stored by the API.
Usage
First make sure you install the packages listed in requirements.txt. The typical way of doing this is using a venv and pip.
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
Then run the demos with
python src/demo.py --url BASE_URL --token SecureToken
Replace BASE_URL with the url of the API you are using. For example https://dreams.thewisewolf.dev or http://localhost:8000
Replace SecureToken with the API token used by the target API
The basic demo will wipe all the users in the API for a clean start, then create and submit several events with documents and stamps to the API.
It will then download these event documents and save them as pngs in a folder called users.
To understand and modify the demo flow, see src/demos.py. In particular, the method run_demos is what is called to actually run the demonstration.
Structure
src/demo.pyis the entry point with nothing of note except the command line argument parser.src/client.pycontains a basic API client exposing (almost) all of the API routes as python methods. Notable exceptions include nested routes (e.g.POST /events/{event_id}/document/stampsis not supported, instead use the equivalentPOST /documents/{document_id}/stamps.), and some minor routes such asGET /users/{user_id}/walletwhich were only included for completeness in the original API.src/drawing.pycontains some really basic image creation methods to simulate card images, along with the base64 encoder and decoder for images.src/demos.pycontains the sample data, and example flows to create events and stamp the resulting documents. Therun_demosmethod should be edited to modify which demonstrations are actually run.