From e2ecf0739df788d1d73db9a997b0e3ed08ab190b Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Wed, 22 Jul 2020 02:56:30 +0200 Subject: [PATCH 1/2] maybeEmpty can be replaced by Data.List.listToMaybe --- src/Hash2Pub/Utils.hs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Hash2Pub/Utils.hs b/src/Hash2Pub/Utils.hs index 660dc51..284239a 100644 --- a/src/Hash2Pub/Utils.hs +++ b/src/Hash2Pub/Utils.hs @@ -4,11 +4,6 @@ module Hash2Pub.Utils where import qualified Data.ByteString as BS import qualified Data.Set as Set --- |wraps a list into a Maybe, by replacing empty lists with Nothing -maybeEmpty :: [a] -> Maybe [a] -maybeEmpty [] = Nothing -maybeEmpty nonemptyList = Just nonemptyList - -- | Chop a list into sublists of i elements. The last sublist might contain -- less than i elements. chunksOf :: Int -> [a] -> [[a]] From 5fedd9f87cdc1c861a1dd645debd82d9698847a4 Mon Sep 17 00:00:00 2001 From: Trolli Schmittlauch Date: Thu, 23 Jul 2020 00:09:45 +0200 Subject: [PATCH 2/2] specify post relay API endpoints contributes to #41, #32 --- Hash2Pub.cabal | 4 ++-- src/Hash2Pub/PostService.hs | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 src/Hash2Pub/PostService.hs diff --git a/Hash2Pub.cabal b/Hash2Pub.cabal index d1ee4b1..dba37a4 100644 --- a/Hash2Pub.cabal +++ b/Hash2Pub.cabal @@ -46,7 +46,7 @@ category: Network extra-source-files: CHANGELOG.md common deps - build-depends: base ^>=4.12.0.0, containers ^>=0.6.0.1, bytestring, utf8-string ^>=1.0.1.1, network ^>=2.8.0.1, time ^>=1.8.0.2, cmdargs ^>= 0.10, cryptonite ^>= 0.25, memory, async, stm, asn1-encoding, asn1-types, asn1-parse, publicsuffix, network-byte-order, safe, iproute, mtl, random + build-depends: base ^>=4.12.0.0, containers ^>=0.6.0.1, bytestring, utf8-string ^>=1.0.1.1, network ^>=2.8.0.1, time ^>=1.8.0.2, cmdargs ^>= 0.10, cryptonite ^>= 0.25, memory, async, stm, asn1-encoding, asn1-types, asn1-parse, publicsuffix, network-byte-order, safe, iproute, mtl, random, servant, servant-server, servant-client, warp, text ghc-options: -Wall @@ -55,7 +55,7 @@ library import: deps -- Modules exported by the library. - exposed-modules: Hash2Pub.FediChord, Hash2Pub.FediChordTypes, Hash2Pub.DHTProtocol, Hash2Pub.ASN1Coding, Hash2Pub.ProtocolTypes + exposed-modules: Hash2Pub.FediChord, Hash2Pub.FediChordTypes, Hash2Pub.DHTProtocol, Hash2Pub.ASN1Coding, Hash2Pub.ProtocolTypes, Hash2Pub.PostService -- Modules included in this library but not exported. other-modules: Hash2Pub.Utils diff --git a/src/Hash2Pub/PostService.hs b/src/Hash2Pub/PostService.hs new file mode 100644 index 0000000..5a8fc3a --- /dev/null +++ b/src/Hash2Pub/PostService.hs @@ -0,0 +1,17 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE OverloadedStrings #-} + +module Hash2Pub.PostService where + +import Servant +import qualified Data.Text as Txt + +type ServiceAPI = "relay" :> "inbox" :> PostCreated '[PlainText] Txt.Text + -- ^ delivery endpoint of new posts to relay + :<|> "relay" :> "subscribers" :> Post '[PlainText] Txt.Text + -- ^ endpoint for delivering the subscription and outstanding queue + :<|> "post" :> Capture "postid" Txt.Text :> Get '[PlainText] Txt.Text + :<|> "tags" :> Capture "hashtag" Txt.Text :> PostCreated '[PlainText] Txt.Text + :<|> "tags" :> Capture "hashtag" Txt.Text :> "subscribe" :> Header "Origin" Txt.Text :> Get '[PlainText] Txt.Text + :<|> "tags" :> Capture "hashtag" Txt.Text :> "unsubscribe" :> Header "Origin" Txt.Text :> Get '[PlainText] Txt.Text