1
0
Fork 0
A CLI program which grabs data from the Return to Ritherdon project's REST API server.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

170 lines
5.8 KiB

Squashed commit of the following: commit d6f93b022d84d3247bbed15b94f167ffa6b537bc Author: Craig Oates <craig@craigoates.net> Date: Fri Jul 2 17:36:52 2021 +0100 add tests which validate the /status/latest call. The URL which returns the latest status for all the devices at once is validated. The tests are not extensive. They just check to make sure all the intended device are present and the last device on the list is 'device 6'. If any of the device names change or 'device 6' is not the last device, it means the API has changed. commit 75d47481503a0fba6bd6450f62e9f5eb27e9dc00 Author: Craig Oates <craig@craigoates.net> Date: Fri Jul 2 16:51:59 2021 +0100 rename light meter status tests (factory devices). Rename the tests to make it easier to read and make the naming convention align with the status tests for the gallery devices. commit 4d8a1e6f9b851faec684fd499281ef3bbcc4d325 Author: Craig Oates <craig@craigoates.net> Date: Fri Jul 2 16:43:47 2021 +0100 correct 'reading' tests to 'status' tests and add new tests. I managed to not notice I wrote tests which check the status (on/off) of the devices but labelled the test as 'reading data' checks. I've relabelled the tests to avoid the confusion. I've added additional test which validate the data produced by the devices in the gallery (part of the Return to Ritherdon project). And, I've written tests which actually validate the light reading data produced by the devices in the welding booths in Ritherdon (again, part of the Return to Ritherdon project). The new tests include code from the Ratify package. I've only used the datetime-p function for now. It checks if the timestamps produced are valid datetime strings -- and can be parsed as such. commit c9559f0a670c94bef9ff464e619997769d9c954c Author: Craig Oates <craig@craigoates.net> Date: Fri Jul 2 16:41:18 2021 +0100 add Ratify to the testing system. At the moment, this is test the timestamps returned from the API. If Ratify can parse the timestamps, it returns them. If it can't parse them, it returns NIL. commit 2ebd6d2a0f1cfddee5e7869dcfd6077b1864c692 Author: Craig Oates <craig@craigoates.net> Date: Fri Jul 2 00:45:36 2021 +0100 writing tests for validating light reading data. These tests check the shape of the data produced by the light meters in the welding in booths in Ritherdon. I've place a note with the factory3 tests explaining the reason why there is a factory3 in the system but there is not actual light meter in the third welding booth in Ritherdon. commit 77952ad2945ee6d4a8a49765d8eff80a153e051f Author: Craig Oates <craig@craigoates.net> Date: Fri Jul 2 00:40:35 2021 +0100 ASDF package definition changes. The changes here are done out of frustration and desperation. SLIME was in a right mess (caching issue I assume) so I started changing things in here to try and fix it. This was before I stumbled on the 'restart Emacs/SLIIME' solution. Becuase it's now working, I've just kept the changes in place. The relief of getting 'asdf:test-system' working after about two hours of faffing was enough for me to not touch this file again. I might come back to this at a later date -- see if/how it needs cleaning up. I might just skip it and start a new project -- this is a learning exercise after all. commit d11119bfdc6425b141f1e6d7fc3f44246b4bd14d Author: Craig Oates <craig@craigoates.net> Date: Fri Jul 2 00:37:31 2021 +0100 export additional test function (at package level). This is so you can run the tests with ASDF, I think. It was something I did whilst SLIME was a bit messes-up and I was a bit desperate with trying to fix it. So, I don't know if this additional exported function is needed. Everything seems to work with it still there -- after I restarted Emacs and SLIME -- so I'm keeping it like this for now. commit b055b97e2a5d82e8723362f37b21feebfcd9c544 Author: Craig Oates <craig@craigoates.net> Date: Fri Jul 2 00:32:52 2021 +0100 rename tests file to main.lisp. This was not needed in the end. I was having trouble with SLIME and I was getting desperate at one point and starting changing everything. It turns out I just needed to restart SLIME. At the time of writing, I didn't know this or how to do that so I only noticed when I restarted Emacs. It looks like stuff got messed-up in the cache and SLIME couldn't find files/packages because it was looking for old one which were either renames or deleted (due to me frantically changing things). commit 8c87cf5b37aa88405c6e12e4c543b9475c76145b Author: Craig Oates <craig@craigoates.net> Date: Wed Jun 30 01:44:45 2021 +0100 fix typo in .gitignore (.directory) Git is picking up my systems .directory files. They are not part of this project's code base. I accidently put /.directory in a previous commit instead of .directory. commit 09dd5f9b6e37872f9afb51e6574cf9be7fcba03f Author: Craig Oates <craig@craigoates.net> Date: Wed Jun 30 01:40:49 2021 +0100 add functions and comments for making HTTP-Requests. These are comments and functions to get me into the swing of writting Common Lisp. The code here is the main part of the system but this commit is mostly about how this file and its code fits into the bigger picture which is the system/code base. commit e912fdc73d56b2e9ee9ad3b45cb7c0e94ab69477 Author: Craig Oates <craig@craigoates.net> Date: Wed Jun 30 01:38:36 2021 +0100 add drakma and cl-json packages to project. These packages are for making an HTTP-Request (to Ritherdon REST API) and parse the JSON returned. commit 05b876bea755d3097d52695576e171b27b778f72 Author: Craig Oates <craig@craigoates.net> Date: Tue Jun 29 21:38:48 2021 +0100 add 'hello' function (for quick test after loading package). This is so I can make sure I know ritherdon-rest.lisp can/is loaded correctly -- via Quicklisp or ASDF -- and is ready to start adding the actual code. commit 8f8cd147ce179886c9b56b3f1c9025d5cbc1a511 Author: Craig Oates <craig@craigoates.net> Date: Tue Jun 29 21:34:14 2021 +0100 integrate FiveAM into test package def. and main testing file. This builds on the initial set-up in the .asd file. With the .asd file knowing the tests package needs FiveAM, the code here integrates the testing framework in to the .lisp files responsible for housing the tests. The code here is placeholder tests and should be deleted the more I get into the project. They exist just to make sure everything is set-up properly between the various definition/set-up files. commit 943a912d9658c66e86f5ca53ae9936a182ade0d3 Author: Craig Oates <craig@craigoates.net> Date: Tue Jun 29 21:32:11 2021 +0100 connect fiveAM testing package to main project in .asd file. This is so you can use asdf:test-system by just calling the ritherdon-rest project -- making it easier to work with. commit 26b025361d0838f1df50737af1e1f7ea0feec0f0 Author: Craig Oates <craig@craigoates.net> Date: Tue Jun 29 21:31:11 2021 +0100 remove doc folder. This is beyond where I'm at right now so going to leave it for a future project. commit aa1abec7fe0aec0fdc371c28c669da8ae0efe65c Author: Craig Oates <craig@craigoates.net> Date: Tue Jun 29 00:22:44 2021 +0100 add fiveAM package and create initial test. I've changed how the tests and doc systems are defined in the .asd file. The changes are based on what SLIME outputted when compiling the project. The initial test are irrelevant to the project. I wrote it to make sure fiveAM (and the test project as a whole) was connected together properly. This test will (should) not remain once the main code is up and running. commit 00ba38f3b069ef2d9104fa33de61264b33fbf851 Author: Craig Oates <craig@craigoates.net> Date: Mon Jun 28 23:11:46 2021 +0100 create project files.
3 years ago
# Ritherdon REST
3 years ago
## Note: The REST API is no longer active
The server hosting the REST API this code calls out to is no longer activer. This means the code in this repository no longer works. I have decided to archive the project so the code can still be referenced.
## About this Project
This is a Common Lisp system which grabs data from the [Return to
Ritherdon](http://ritherdon.abbether.net/) project's REST API server.
The intended way to use this code is within a Lisp REPL -- something
like SLIME in Emacs or Steel Bank Common Lisp (SBCL). If they do not
mean anything to you, this code is probably not for you (or this
repo. is a little early in your learning of Common Lisp).
The code makes HTTP Requests from the [Return to Ritherdon
API](http://ritherdon.abbether.net/api/ui/) and parses the returned
JSON data. I expect this API to close down in the later stages of 2021
when the [No Gaps in the
Line](https://www.castlefieldgallery.co.uk/event/nicola-ellis-solo-exhibition-coming-in-2021/)
exhibition ends. The code in this repository will remain as reference
material, though (I'm using this to learn Common Lisp).
The project's file structure is,
```bash
ritherdon-rest/
├── LICENSE
├── README.md
├── ritherdon-rest.asd
├── src
   ├── package.lisp
   └── ritherdon-rest.lisp
└── tests
├── main.lisp
└── package.lisp
2 directories, 7 files
```
**If you just want to jump straight into the code, head to
`/src/ritherdon-rest.lisp`.**
`/src` is the project with the code to make requests and parse the
data returned from those requests. `/tests` is the testing suite for
the code in `/src`. The `ritherdon-rest.asd` file provides code for
ASDF and summaries how the two systems/packages connect to each
other. Again, if this meaning nothing to you, this might be a little
early in your Common Lisp learning.
There are two ways to use this code:
- [Quicklisp](https://www.quicklisp.org/beta/)
- [ASDF](https://common-lisp.net/project/asdf/)
## Note on Passing URL Arguments into The System
The code already has the base-URL stored in it. So you only need to
pass in the specific part of the API call you want to make. For
example, the full URL to get the latest status logs for all the
devices is `http://ritherdon.abbether.net/api/status/latest`. But, the
part specific to this request is `/status/latest`. So, this is the
part you need to pass in. Other examples are,
- `http://ritherdon.abbether.net/api/status/latest/1` becomes
`/status/latest/1`
- `http://ritherdon.abbether.net/api/readings/latest/2` becomes
`/readings/latest/2`
- `http://ritherdon.abbether.net/api/readings/all/2` becomes
`/readings/all/2`
The full list of API calls available are at [Return to Ritherdon
API](http://ritherdon.abbether.net/api/ui/).
## Use with Quicklisp
I tend to sym-link this project into the `/local-projects` folder, so
this step might be unnecessary for you. I am keeping it here to jog
the memory of those who prefer to have their code in a place outside
`/local-projects` -- hopefully catch it early and avoid any
unnecessary error message.
```bash
# Adjust the paths accordingly.
ln -s ~/dev-folder/ritherdon-rest ~/quicklisp/local-projects
```
When the project is in there, either start SBCL (CLI) or SLIME (Emacs)
and load the system into it,
```lisp
(ql:quickload :ritherdon-rest)
;;; From there, I can start using it.
(ritherdon-rest:parse-request "/status/latest")
```
To run the tests, you need to Quickload the `ritherdon-rest/test`
package,
```lisp
(ql:quickload :ritherdon-rest/tests)
;;; You might get a naming conflict with FiveAM and Ratify. SBCL or
;;; SLIME with provide you with options to resolve the naming
;;; conflict. This is a bit inconsistent for me so I can't give exact
;;; instructions. Although, I found prioritising the FiveAM package's use
;;; of `TEST' works best.
;; To run the tests...
(ritherdon-rest-tests:test-quasi)
```
I do not tend to use Quicklisp that much so you might come across
errors I have not mentioned here.
## Use with ASDF
To load the system via ASDF, enter the following into SBCL or SLIME,
```lisp
(asdf:load-system :ritherdon-rest)
;;; To use the code,
(ritherdon-rest:parse-request "/status/latest/1")
;;; The 'ritherdon-rest.asd' file has connected the test system to the
;;; main system. So you can run the tests from the main system. In other
;;; words, to run the tests,
(asdf:test-system :ritherdon-rest) ;Instead of ':ritherdon-rest/tests'.
```
If you are making repeated calls and want to reduce the amount of
typing you are doing, you can jump into the `ritherdon-rest` package
and call its functions directly.
```lisp
;;; This removes the need to type the 'ritherdon-rest:' part all the time.
(in-package :ritherdon-rest)
(parse-request "/status/latest")
(parse-request "/reading/latest/2")
(parse-request "reading/all/1")
;;; To return to the default package,
(in-package :common-lisp-user)
```
## Notes on Repository Support
This repository is to help me learn Common Lisp. Because of this,
there is no Issue Tracker, Wiki or Requests section. I have made this
repository public on the off-chance is might help you learning about
Common Lisp by seeing something in-situ.
The [Return to Ritherdon API](http://ritherdon.abbether.net/api/ui/)
has HTTP-Push requests. I have not provided any functions to make
these types of requests because I do not want to run the risk of
breaking that system. The API is part of an active art exhibition and
I do not want to corrupt the data it stores/created in any way.
I have ran this project on Linux and nothing else. I have no idea if
this work on Windows or MacOS. I, also, have no urge to find
out. Unfortunately, you are on your own here because I have no means
to test it.
As stated near the top of this document, I am expecting to shutdown
the API near the end of 2021. When that happens, this will remain as a
reference repository.