1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2025-03-20 04:46:22 +09:00

Move some JSON/AP codec utils to new Data.Aeson.Local module

This commit is contained in:
fr33domlover 2019-02-03 11:01:36 +00:00
parent e6f987817e
commit 991296faa1
4 changed files with 59 additions and 20 deletions
src/Data/Aeson

51
src/Data/Aeson/Local.hs Normal file
View file

@ -0,0 +1,51 @@
{- This file is part of Vervis.
-
- Written in 2019 by fr33domlover <fr33domlover@riseup.net>.
-
- Copying is an act of love. Please copy, reuse and share.
-
- The author(s) have dedicated all copyright and related and neighboring
- rights to this software to the public domain worldwide. This software is
- distributed without any warranty.
-
- You should have received a copy of the CC0 Public Domain Dedication along
- with this software. If not, see
- <http://creativecommons.org/publicdomain/zero/1.0/>.
-}
module Data.Aeson.Local
( frg
, parseHttpsURI
, renderURI
, (.=?)
)
where
import Prelude
import Data.Aeson
import Data.Aeson.Types (Parser)
import Data.Text (Text)
import Network.URI
import qualified Data.Text as T (unpack)
frg :: Text
frg = "https://forgefed.angeley.es/ns#"
parseHttpsURI :: Text -> Parser URI
parseHttpsURI t =
case parseURI $ T.unpack t of
Nothing -> fail "Invalid absolute URI"
Just u ->
if uriScheme u == "https:"
then return u
else fail "URI scheme isn't https"
renderURI :: URI -> String
renderURI u = uriToString id u ""
infixr 8 .=?
(.=?) :: ToJSON v => Text -> Maybe v -> Series
k .=? Nothing = mempty
k .=? (Just v) = k .= v