pusher-http-haskell-0.1.0.0: Haskell client library for the Pusher HTTP API

Copyright(c) Will Sewell, 2015
LicenseMIT
Maintainerme@willsewell.com
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Network.Pusher

Contents

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
    pusher = getPusher $ Credentials
      { credentials'appID = 123
      , credentials'appKey = wrd12344rcd234
      , credentials'appSecret = 124df34d545v
      }
  result <- runPusherT (Pusher.trigger ["my-channel"] "my-event" "my-data") 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.

Synopsis

Events

trigger Source

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

channels Source

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.

channel Source

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.