Skip to content

Commit

Permalink
Merge pull request #4 from netz39/adapt-api
Browse files Browse the repository at this point in the history
Adapt API to the existing spec
  • Loading branch information
penguineer authored Nov 2, 2024
2 parents 07e8324 + 3efa17f commit 79f2bb0
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN git describe --always --dirty > /git-version.txt
FROM python:3.12

EXPOSE 8080
HEALTHCHECK --interval=10s CMD curl --fail http://localhost:8080/v0/health || exit 1
HEALTHCHECK --interval=10s CMD curl --fail http://localhost:8080/health || exit 1

COPY src/OAS3.yml /

Expand Down
73 changes: 73 additions & 0 deletions src/OAS3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
openapi: 3.0.0
info:
title: Space Status API
version: 1.0.0
description: API for retrieving space status and related information.
servers:
- url: http://localhost:8080/
description: Local development server
- url: https://spaceapi.n39.eu/
description: Netz39 SpaceAPI server
paths:
/health:
get:
summary: Health check endpoint
responses:
'200':
description: Health check information
content:
application/json:
schema:
type: object
properties:
api_version:
type: string
git_version:
type: string
timestamp:
type: string
format: date-time
uptime:
type: string
format: duration
/oas3:
get:
summary: OpenAPI Specification
responses:
'200':
description: OpenAPI Specification
content:
text/plain:
schema:
type: string
/json:
get:
summary: Space API entry in JSON format
responses:
'200':
description: Space API entry
content:
application/json:
schema:
type: object
/text:
get:
summary: Space state in plain text
responses:
'200':
description: Space state
content:
text/plain:
schema:
type: string
/state.png:
get:
summary: Space state as an image
responses:
'200':
description: Space state image
content:
image/png:
schema:
type: string
format: binary
18 changes: 14 additions & 4 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ def get(self):
self.write(json.dumps(self.observer.get_space_api_entry(), indent=4))
self.finish()

class SpaceStateTextHandler(tornado.web.RequestHandler, ABC):
# noinspection PyAttributeOutsideInit
def initialize(self, observer):
self.observer = observer

def get(self):
self.set_header("Content-Type", "text/plain")
self.write("open" if self.observer.space_api_entry.is_open() else "closed")
self.finish()


class PictureHandler(tornado.web.RequestHandler, ABC):
# noinspection PyAttributeOutsideInit
Expand All @@ -97,11 +107,11 @@ def get(self):


def make_app(observer, picture_manager):
version_path = r"/v[0-9]"
return tornado.web.Application([
(version_path + r"/health", HealthHandler),
(version_path + r"/oas3", Oas3Handler),
(r"/", SpaceAPIHandler, dict(observer=observer)),
(r"/health", HealthHandler),
(r"/oas3", Oas3Handler),
(r"/json", SpaceAPIHandler, dict(observer=observer)),
(r"/text", SpaceStateTextHandler, dict(observer=observer)),
(r"/state.png", PictureHandler, dict(picture_manager=picture_manager)),
])

Expand Down

0 comments on commit 79f2bb0

Please sign in to comment.