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

Copyright(c) Will Sewell 2016
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.

First create a Pusher data structure with your Pusher Credentials, and then call the functions defined in this module to make the HTTP requests.

If any of the requests fail, the return values of the functions will result in a Left PusherError when run.

An example of how you would use these functions:

  let
    credentials = Credentials
      { credentialsAppID = 123
      , credentialsAppKey = wrd12344rcd234
      , credentialsAppSecret = 124df34d545v
      }
  pusher <- getPusher credentials
  result <-
    trigger pusher [Channel Public "my-channel"] "my-event" "my-data" Nothing
  case result of
    Left e -> error e
    Right resp -> print resp

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

Data types

Pusher config type

data Pusher #

All the required configuration needed to interact with the API.

data Credentials #

The credentials for the current app.

type AppID = Integer #

getPusher :: MonadIO m => Credentials -> m Pusher #

Use this to get an instance Pusher. This will fill in the host and path automatically.

getPusherWithHost :: MonadIO m => Text -> Credentials -> m Pusher #

Get a Pusher instance that uses a specific API endpoint.

getPusherWithConnManager :: Manager -> Maybe Text -> Credentials -> Pusher #

Get a Pusher instance with a given connection manager. This can be useful if you want to share a connection with your application code.

Channels

data Channel #

The channel name (not including the channel type prefix) and its type.

Instances

Eq Channel # 

Methods

(==) :: Channel -> Channel -> Bool #

(/=) :: Channel -> Channel -> Bool #

Show Channel # 
Generic Channel # 

Associated Types

type Rep Channel :: * -> * #

Methods

from :: Channel -> Rep Channel x #

to :: Rep Channel x -> Channel #

Hashable Channel # 

Methods

hashWithSalt :: Int -> Channel -> Int #

hash :: Channel -> Int #

type Rep Channel # 
type Rep Channel = D1 (MetaData "Channel" "Network.Pusher.Data" "pusher-http-haskell-1.2.0.1-Hf4awoIkHKqHo6CvS4V5XG" False) (C1 (MetaCons "Channel" PrefixI True) ((:*:) (S1 (MetaSel (Just Symbol "channelType") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 ChannelType)) (S1 (MetaSel (Just Symbol "channelName") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 ChannelName))))

data ChannelType #

The possible types of Pusher channe.

Constructors

Public 
Private 
Presence 

Instances

Eq ChannelType # 
Show ChannelType # 
Generic ChannelType # 

Associated Types

type Rep ChannelType :: * -> * #

Hashable ChannelType # 
type Rep ChannelType # 
type Rep ChannelType = D1 (MetaData "ChannelType" "Network.Pusher.Data" "pusher-http-haskell-1.2.0.1-Hf4awoIkHKqHo6CvS4V5XG" False) ((:+:) (C1 (MetaCons "Public" PrefixI False) U1) ((:+:) (C1 (MetaCons "Private" PrefixI False) U1) (C1 (MetaCons "Presence" PrefixI False) U1)))

parseChannel :: Text -> Channel #

Convert string representation, e.g. private-chan into the datatype

Events

type Event = Text #

type SocketID = Text #

HTTP Requests

Trigger events

trigger #

Arguments

:: MonadIO m 
=> Pusher 
-> [Channel]

The list of channels to trigger to

-> Event 
-> EventData

Often encoded JSON

-> Maybe SocketID

An optional socket ID of a connection you wish to exclude

-> m (Either PusherError ()) 

Trigger an event to one or more channels.

Channel queries

channels #

Arguments

:: MonadIO m 
=> Pusher 
-> 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 (Either PusherError ChannelsInfo)

The returned data

Query a list of channels for information.

channel #

Arguments

:: MonadIO m 
=> Pusher 
-> Channel 
-> ChannelInfoQuery

Can query user count and also subscription count (if enabled)

-> m (Either PusherError FullChannelInfo) 

Query for information on a single channel.

users :: MonadIO m => Pusher -> Channel -> m (Either PusherError Users) #

Get a list of users in a presence channel.

Authentication

type AuthString = ByteString #

The bytestring to sign with the app secret to create a signature from.

type AuthSignature = ByteString #

A Pusher auth signature.

authenticatePresence :: ToJSON a => Credentials -> SocketID -> Channel -> a -> AuthSignature #

Generate an auth signature of the form "app_key:auth_sig" for a user of a presence channel.

authenticatePrivate :: Credentials -> SocketID -> Channel -> AuthSignature #

Generate an auth signature of the form "app_key:auth_sig" for a user of a private channel.

Errors

data PusherError #

Constructors

PusherArgumentError Text

Data from the caller is not valid.

PusherNon200ResponseError Text

Received non 200 response code from Pusher.

PusherInvalidResponseError Text

Received unexpected data from Pusher.