Copyright | (c) Will Sewell, 2015 |
---|---|
License | MIT |
Maintainer | [email protected] |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Network.Pusher
Description
Exposes the functions necessary for interacting with the Pusher HTTP API, as well as functions for generating auth signatures for private and presence channels.
The idea is that you must create a Pusher data structure with your credentials, then your write your block of code that calls functions from this library, and finally "run" this code with the Pusher data structure you created.
The types of the functions are general enough to allow you to use the provided PusherM as the return type, or PusherT if you wish to use other monads in your applications monad transformer stack.
The functions return a MonadError type which means any can fail, and you must handle these failures in your client application. In the simplist case you can instantiate the type to an Either and case split on it.
An example of how you would use these functions:
let credentials = Credentials { credentialsAppID = 123 , credentialsAppKey = wrd12344rcd234 , credentialsAppSecret = 124df34d545v } pusher <- getPusher credentials result <- runPusherT (trigger [Channel Public "my-channel"] "my-event" "my-data" Nothing) pusher case result of Right resp -> print resp Left e -> error e
There is a simple working example in the example/ directory.
See https://pusher.com/docs/rest_api for more detail on the HTTP requests.
- trigger :: MonadPusher m => [Channel] -> Text -> Text -> Maybe Text -> m ()
- channels :: MonadPusher m => Maybe ChannelType -> Text -> ChannelsInfoQuery -> m ChannelsInfo
- channel :: MonadPusher m => Channel -> ChannelInfoQuery -> m FullChannelInfo
- users :: MonadPusher m => Channel -> m Users
- authenticatePresence :: ToJSON a => Credentials -> ByteString -> ByteString -> a -> ByteString
- authenticatePrivate :: Credentials -> ByteString -> ByteString -> ByteString
Events
Arguments
:: MonadPusher m | |
=> [Channel] | The list of channels to trigger to |
-> Text | The event |
-> Text | The data to send (often encoded JSON) |
-> Maybe Text | An optional socket ID of a connection you wish to exclude |
-> m () |
Trigger an event to one or more channels.
Channel queries
Arguments
:: MonadPusher m | |
=> Maybe ChannelType | Filter by the type of channel |
-> Text | A channel prefix you wish to filter on |
-> ChannelsInfoQuery | Data you wish to query for, currently just the user count |
-> m ChannelsInfo | The returned data |
Query a list of channels for information.
Arguments
:: MonadPusher m | |
=> Channel | |
-> ChannelInfoQuery | Can query user count and also subscription count (if enabled) |
-> m FullChannelInfo |
Query for information on a single channel.
users :: MonadPusher m => Channel -> m Users Source
Get a list of users in a presence channel.
Authentication
authenticatePresence :: ToJSON a => Credentials -> ByteString -> ByteString -> a -> ByteString Source
Generate an auth signature of the form "app_key:auth_sig" for a user of a presence channel.
authenticatePrivate :: Credentials -> ByteString -> ByteString -> ByteString Source
Generate an auth signature of the form "app_key:auth_sig" for a user of a private channel.