diff options
| author | ckonstanski <carlos.konstanski@olo.com> | 2021-11-28 16:55:46 -0700 |
|---|---|---|
| committer | ckonstanski <carlos.konstanski@olo.com> | 2021-11-28 16:55:46 -0700 |
| commit | 8be7c5d959951dfafaf3fcaebe860a64ee3d8f7f (patch) | |
| tree | 57e0dc941d54685629630528ae34d892e5138102 /lisp/service/rest-service.lisp | |
initail commit
Diffstat (limited to 'lisp/service/rest-service.lisp')
| -rw-r--r-- | lisp/service/rest-service.lisp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lisp/service/rest-service.lisp b/lisp/service/rest-service.lisp new file mode 100644 index 0000000..ea374b8 --- /dev/null +++ b/lisp/service/rest-service.lisp @@ -0,0 +1,37 @@ +;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*- +(declaim (optimize (speed 0) (safety 3) (debug 3))) + +(in-package #:dns-admin) + +(defclass rest-service (base-service) + ((location :initarg :location + :initform nil + :accessor location) + (location-p :initarg :location-p + :initform t + :accessor location-p) + (authmsg :initarg :authmsg + :initform nil + :accessor authmsg) + (errormsg :initarg :errormsg + :initform nil + :accessor errormsg) + (message :initarg :message + :initform nil + :accessor message)) + (:documentation "")) + +(defmethod initialize-instance :after ((rest-service rest-service) &key) + (when (and (location-p rest-service) (null (location rest-service))) + (setf (location rest-service) (type-to-path rest-service)))) + +(defun handle-location (&optional (location "/home")) + (format nil "{\"location\":\"~a\"}" location)) + +(defun type-to-path (rest-type) + (concatenate 'string "/" (ppcre:regex-replace-all "-" (ppcre:regex-replace "-service$" (string-downcase (type-of rest-type)) "") "/"))) + +(defmacro with-service ((instance rest-service) &body body) + `(let ((,instance (make-instance ',rest-service))) + ,@body + (objects-to-json `(,,instance)))) |
