about summary refs log tree commit diff
path: root/users/Profpatsch/mailbox-org/AesonQQ.hs
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2023-01-15T20·20+0100
committerProfpatsch <mail@profpatsch.de>2023-01-15T20·36+0000
commitf627ee84b3a002e8f1fe38d7859860faf7d40be9 (patch)
treed541adcae274bacaf95f690d8908a34c2e9bfa4d /users/Profpatsch/mailbox-org/AesonQQ.hs
parent1a18c25d816298775cafa970c34b7ec41cdf127a (diff)
feat(users/Profpatsch/mailbox-org): add simple request json example r/5661
Adds a simple json quasiquoter thingy.

Json can be sent to the `/mailfilter?action=update` endpoint.

Change-Id: Iba80c2ab69178e431519933c4a01cd68aaa9f637
Reviewed-on: https://cl.tvl.fyi/c/depot/+/7839
Tested-by: BuildkiteCI
Autosubmit: Profpatsch <mail@profpatsch.de>
Reviewed-by: Profpatsch <mail@profpatsch.de>
Diffstat (limited to 'users/Profpatsch/mailbox-org/AesonQQ.hs')
-rw-r--r--users/Profpatsch/mailbox-org/AesonQQ.hs23
1 files changed, 23 insertions, 0 deletions
diff --git a/users/Profpatsch/mailbox-org/AesonQQ.hs b/users/Profpatsch/mailbox-org/AesonQQ.hs
new file mode 100644
index 000000000000..02e1c2f3dff0
--- /dev/null
+++ b/users/Profpatsch/mailbox-org/AesonQQ.hs
@@ -0,0 +1,23 @@
+{-# LANGUAGE TemplateHaskellQuotes #-}
+
+module AesonQQ where
+
+import Data.Aeson qualified as Json
+import Data.Either qualified as Either
+import MyPrelude
+import PyF qualified
+import PyF.Internal.QQ qualified as PyFConf
+
+aesonQQ =
+  PyF.mkFormatter
+    "aesonQQ"
+    PyF.defaultConfig
+      { PyFConf.delimiters = Just ('|', '|'),
+        PyFConf.postProcess = \exp -> do
+          -- TODO: this does not throw an error at compilation time if the json does not parse
+          [|
+            case Json.eitherDecodeStrict' @Json.Value $ textToBytesUtf8 $ stringToText $(exp) of
+              Left err -> error err
+              Right a -> a
+            |]
+      }