hzulip 1.1.0.5 → 1.1.1.0
raw patch · 3 files changed
+56/−6 lines, 3 filesdep +conduitdep +stmdep +stm-conduitPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: conduit, stm, stm-conduit
API changes (from Hackage documentation)
+ Web.HZulip: sinkZulipMessages :: Sink (String, [String], String, String) ZulipM ()
+ Web.HZulip: sourceZulipEvents :: Int -> [String] -> Source ZulipM Event
+ Web.HZulip: sourceZulipMessages :: Int -> Source ZulipM Message
+ Web.HZulip: type ZulipM = ReaderT ZulipOptions IO
- Web.HZulip: addAllSubscriptions :: ZulipM ()
+ Web.HZulip: addAllSubscriptions :: ZulipM [String]
- Web.HZulip.Types: type ZulipM a = ReaderT ZulipOptions IO a
+ Web.HZulip.Types: type ZulipM = ReaderT ZulipOptions IO
Files
- hzulip.cabal +7/−1
- src/Web/HZulip.hs +48/−4
- src/Web/HZulip/Types.hs +1/−1
hzulip.cabal view
@@ -1,5 +1,5 @@ name: hzulip-version: 1.1.0.5+version: 1.1.1.0 synopsis: A haskell wrapper for the Zulip API. description: This a Zulip API wrapper for Haskell. homepage: https://github.com/yamadapc/hzulip@@ -20,6 +20,9 @@ exposed-modules: Web.HZulip , Web.HZulip.Types build-depends: base >=4 && <5+ , conduit >=1.2 && <1.3+ , stm >=2.4 && <2.5+ , stm-conduit >=2.5 && <3 , http-client >=0.2 && <1 , http-client-tls , http-types@@ -41,6 +44,9 @@ , test build-depends: base >=4 && <5 , async+ , conduit >=1.2 && <1.3+ , stm >=2.4 && <2.5+ , stm-conduit >=2.5 && <3 , http-client >=0.2 && <1 , http-client-tls , http-types
src/Web/HZulip.hs view
@@ -25,6 +25,7 @@ , Queue(..) , User(..) , ZulipOptions(..)+ , ZulipM , EventCallback , MessageCallback , addSubscriptions@@ -43,6 +44,9 @@ , sendMessage , sendPrivateMessage , sendStreamMessage+ , sinkZulipMessages+ , sourceZulipEvents+ , sourceZulipMessages , withZulip , withZulipCreds , zulipOptions@@ -53,17 +57,20 @@ where import Control.Arrow (second)+import Control.Concurrent.STM (TBQueue, atomically, writeTBQueue) import Control.Lens ((^..)) import Control.Monad (void) import Control.Monad.Catch (catch, throwM) import Control.Monad.IO.Class (liftIO) import Control.Monad.Trans (lift) import Control.Monad.Trans.Reader (ask, runReaderT)-import Data.Aeson (Value(..), decode, encode)+import Data.Aeson (decode) import Data.Aeson.Lens (key, values, _String) import qualified Data.ByteString.Lazy as BL (ByteString) import qualified Data.ByteString.Char8 as C (pack) import qualified Data.ByteString.Lazy.Char8 as CL (unpack)+import Data.Conduit (Sink, Source, await)+import Data.Conduit.Async (gatherFrom) import Data.List (intercalate) import Data.Text as T (Text, unpack) import Data.Text.Encoding as T (encodeUtf8)@@ -188,9 +195,13 @@ . key "name" . _String -- |--- Subscribes the client to all streams-addAllSubscriptions :: ZulipM ()-addAllSubscriptions = getStreams >>= addSubscriptions+-- Subscribes the client to all available streams and returns all the+-- stream names+addAllSubscriptions :: ZulipM [String]+addAllSubscriptions = do+ ss <- getStreams+ addSubscriptions ss+ return ss -- | -- Add new Stream subscriptions to the client.@@ -249,6 +260,34 @@ -- this is more reasonable. maybe (return ()) f (eventMessage evt) +-- Higher-level conduit interface:+-------------------------------------------------------------------------------++-- |+-- A sink representation of the zulip messaging API, takes a tuple with the+-- arguments for 'sendMessage' and sends it+sinkZulipMessages :: Sink (String, [String], String, String) ZulipM ()+sinkZulipMessages = loop+ where loop = await >>= maybe (return ())+ (\(w, x, y, z) -> do+ void $ lift $ sendMessage w x y z+ loop)++-- |+-- Creates a conduit 'Source' of zulip events+sourceZulipEvents :: Int -- ^ The size of the event buffer+ -> [String] -- ^ A list of event types to subscribe to+ -> Source ZulipM Event+sourceZulipEvents bufSize evts = gatherFrom bufSize $+ onNewEvent evts . zulipWriteTBQueueIO++-- |+-- Creates a conduit 'Source' of zulip messages+sourceZulipMessages :: Int -- ^ The size of the event buffer+ -> Source ZulipM Message+sourceZulipMessages bufSize = gatherFrom bufSize $+ onNewMessage . zulipWriteTBQueueIO+ -- Private functions: ------------------------------------------------------------------------------- @@ -315,3 +354,8 @@ endpointSuffix Register = "/register" endpointSuffix Subscriptions = "/users/me/subscriptions" endpointSuffix Streams = "/streams"++-- |+-- Lifted IO version of 'writeTBQueue'+zulipWriteTBQueueIO :: TBQueue a -> a -> ZulipM ()+zulipWriteTBQueueIO q x = lift $ atomically $ writeTBQueue q x
src/Web/HZulip/Types.hs view
@@ -11,7 +11,7 @@ -- | -- The Monad in which Zulip API actions happen in. This is a 'ReaderT' -- alias, so it's also a instance of 'MonadTrans', 'MonadIO' etc.-type ZulipM a = ReaderT ZulipOptions IO a+type ZulipM = ReaderT ZulipOptions IO -- | -- Represents a Zulip API client