hzulip-1.1.1.0: A haskell wrapper for the Zulip API.

CopyrightPedro Tacla Yamada
LicenseMIT (see LICENSE)
MaintainerPedro Tacla Yamada <tacla.yamada@gmail.com>
Stabilityunstable
Portabilityunportable
Safe HaskellNone
LanguageHaskell2010

Web.HZulip

Description

A Wrapper library for the Zulip API. Works on top of a ReaderT monad transformer, holding a ZulipOptions object, which should hold the state and configuration for the API client.

Using the library is made easier through a set of helper functions. This design is more concise and than passing around configuration variables; one could easily bypass it with the use of runZulip, though that isn't recommended.

Examples are available at the github repository for this project at: https://github.com/yamadapc/hzulip

Synopsis

Documentation

data Event Source

Represents zulip events

Constructors

Event 

data Queue Source

Represents some event queue

Constructors

Queue 

Fields

queueId :: String
 
lastEventId :: Int
 

Instances

data User Source

Represents a zulip user account - for both display_recipient and message_sender representations

data ZulipOptions Source

Represents a Zulip API client

Instances

type ZulipM = ReaderT ZulipOptions IO Source

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 EventCallback = Event -> ZulipM () Source

The root type for Event callbacks

type MessageCallback = Message -> ZulipM () Source

Type for message callbacks

addSubscriptions :: [String] -> ZulipM () Source

Add new Stream subscriptions to the client.

addAllSubscriptions :: ZulipM [String] Source

Subscribes the client to all available streams and returns all the stream names

defaultBaseUrl :: String Source

The default zulip API URL

eventTypes :: [String] Source

The list of all avaiable event types

getEvents :: Queue -> Bool -> ZulipM (Queue, [Event]) Source

Fetches new set of events from a Queue.

getStreams :: ZulipM [String] Source

Get a list of all the public streams

getStreamSubscribers :: String -> ZulipM [String] Source

Get all the user emails subscribed to a stream

getSubscriptions :: ZulipM [String] Source

Get a list of the streams the client is currently subscribed to.

onNewEvent :: [String] -> EventCallback -> ZulipM () Source

Registers an event callback for specified events and keeps executing it over events as they come in

onNewMessage :: MessageCallback -> ZulipM () Source

Registers a callback to be executed whenever a message comes in. Will loop forever

registerQueue :: [String] -> Bool -> ZulipM Queue Source

This registers a new event queue with the zulip API. It's a lower level function, which shouldn't be used unless you know what you're doing. It takes a list of names of the events you want to listen for and whether you'd like for the content to be rendered in HTML format (if you set the last parameter to False it will be kept as typed, in markdown format)

removeSubscriptions :: [String] -> ZulipM () Source

Remove one or more Stream subscriptions from the client

runZulip :: ZulipM a -> ZulipOptions -> IO a Source

Helper to run Actions in the Zulip Monad

sendMessage :: String -> [String] -> String -> String -> ZulipM Int Source

This wraps `POST https://api.zulip.com/v1/messages` with a nicer root API. Simpler helpers for each specific case of this somewhat overloaded endpoint will also be provided in the future.

It takes the message mtype, mrecipients, msubject and mcontent and returns the created message's id in the ZulipM monad.

sendPrivateMessage :: [String] -> String -> ZulipM Int Source

Helper for sending private messages. Takes the list of recipients and the message's content.

sendStreamMessage :: String -> String -> String -> ZulipM Int Source

Helper for sending stream messages. Takes the stream name, the subject and the message.

sinkZulipMessages :: Sink (String, [String], String, String) ZulipM () Source

A sink representation of the zulip messaging API, takes a tuple with the arguments for sendMessage and sends it

sourceZulipEvents Source

Arguments

:: Int

The size of the event buffer

-> [String]

A list of event types to subscribe to

-> Source ZulipM Event 

Creates a conduit Source of zulip events

sourceZulipMessages Source

Arguments

:: Int

The size of the event buffer

-> Source ZulipM Message 

Creates a conduit Source of zulip messages

withZulip :: ZulipOptions -> ZulipM a -> IO a Source

Flipped version of runZulip

withZulipCreds :: String -> String -> ZulipM a -> IO a Source

Helper for creating a minimal ZulipOptions object and running an action in the ZulipM monad

zulipOptions :: String -> String -> IO ZulipOptions Source

Helper for creating a ZulipOptions object with the baseUrl set to defaultBaseUrl

lift :: MonadTrans t => forall m a. Monad m => m a -> t m a

Lift a computation from the argument monad to the constructed monad.

ask :: Monad m => ReaderT r m r

Fetch the value of the environment.