pushover-0.1.0.0: A Haskell Pushover API library

Safe HaskellNone
LanguageHaskell2010

Network.Pushover

Contents

Description

This library provides functionality for interacting with the Pushover API (https://www.pushover.net) from within a Haskell codebase.

Pushover exposes a straightforward API for sending notifications to users of the Android and iOS Pushover app. Details of the API can be found at https://pushover.net/api.

Requests are defined by the Request type. The defaultRequest function is provided to allow for the easy creation of simple requests. Each request requires an API token, user token and a message to be passed. All other fields are optional and can be set as required.

Synopsis

Sending a notification

Regular functions

sendMessage :: APIToken -> UserKey -> Message -> IO Response Source #

Send a request to the Pushover API.

Requires a pair of Pushover tokens, together with a Message value. These are used to construct a defaultRequest which is then sent to the API.

sendRequest :: Request -> IO Response Source #

Send a request to the Pushover API.

This is similar to sendMessage, except that a constructed Request must be passed instead of the tokens and message.

createRequest :: APIToken -> UserKey -> Message -> Request Source #

Create a standard Pushover request.

This is an alias of the defaultRequest function.

Monadic functions

sendMessageM :: (Error e, MonadError e m, MonadIO m, MonadReader r m, PushoverReader r) => Message -> m Response Source #

Send a request to the Pushover API.

This function is designed for use within an existing monad transformer stack to make it easy to send Pushover notifications from inside existing software.

The relevant tokens are read from a PushoverReader MonadReader instance. These are then used to construct a defaultRequest containing the passed Message value.

sendRequestM :: (Error e, MonadError e m, MonadIO m) => Request -> m Response Source #

Send a request to the Pushover API.

This function is designed for use within an existing monad transformer stack to make it easy to send Pushover notifications from inside existing software.

This is similar to sendMessageM, except that a constructed Request must be passed instead of just the message.

createRequestM :: (MonadReader r m, PushoverReader r) => Message -> m Request Source #

Create a standard Pushover request.

This is similar to createRequest, except that token information is read from within the monad stack.

Requests

Constructing a request

data Request Source #

Contains the contents of a Pushover notification request. This follows the API specification at https://pushover.net/api.

defaultRequest :: APIToken -> UserKey -> Message -> Request Source #

Construct a default request value.

As a request requires, at a minimum, an API token, a user key and a message, this function requires each of these values as an argument. Other fields can then be initialised using the regular Haskell record syntax.

Constructing a request's message

data Message Source #

Represents a message sent to the Pushover API.

A Pushover message can be constructed with a very small subset of HTML. This type represents the available HTML formatting for a message.

message :: [Message] -> Message Source #

Make a message from a list of message parts.

bold :: [Message] -> Message Source #

Make a bold message.

italic :: [Message] -> Message Source #

Make an italic message.

underline :: [Message] -> Message Source #

Make an underlined message.

color :: Integer -> Integer -> Integer -> [Message] -> Message Source #

Make a message with colored text.

Accepts three integer arguments for red, green and blue color elements, respectively.

link :: Url -> [Message] -> Message Source #

Make a url message.

text :: Text -> Message Source #

Make a textual message.

Authenticating a request

type UserKey = PushoverToken Source #

User key for the user receiving a notification.

data PushoverToken Source #

Define a type to represent the different types of token or key Pushover requires.

Pushover requires API token and user keys to be send with requests. This is intended to represent these tokens. It is intended that the makeToken function is used to construct validated tokens.

makeToken :: Text -> Either PushoverException PushoverToken Source #

Construct a PushoverToken value.

A PushoverToken consists of exactly 30 alphanumeric characters (both uppercase and lowercase). The input key text is validated to ensure it is the correct length and contains valid characters.

A descriptive error is returned where validation fails.

Other request fields

data URL Source #

A URL for sending within a notification request.

A Pushover URL is optional within a request; if present, it may optionally contain a title to display instead of the URL itself.

Constructors

URL 

Fields

Instances

Eq URL Source # 

Methods

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

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

Show URL Source # 

Methods

showsPrec :: Int -> URL -> ShowS #

show :: URL -> String #

showList :: [URL] -> ShowS #

data Priority Source #

Describes the priority of a particular message.

The different priority settings affect the way in which a notification is presented to the user. See https://pushover.net/api#priority for specific details.

Constructors

Lowest 
Low 
Normal 
High 
Emergency 

Response

data Response Source #

Describes a response received to a notification request. This follows the specification at https://pushover.net/api#response.

A request will either be successful or it will be unsuccessful. Where it is successful, an appropriate status indicator is returned. Where unsuccessful, the response will contain an errors key with a list of errors within the request.

In both cases, a request parameter is returned which uniquely identifies the request leading to the response.

Constructors

Response 

Reader

class PushoverReader r where Source #

The PushoverReader class is intended to make it straightforward to incorporate the making of Pushover requests within an existing monad stack.

This class is intended to make it easy to add an API token and user key to an existing reader monad environment.

Minimal complete definition

apiToken, userKey

data PushoverKeys Source #

A basic type for use in storing the pair of keys required for making a request.

Constructors

PushoverKeys 

createKeys :: (Error e, MonadError e m) => UnvalidatedAPIToken -> UnvalidatedUserKey -> m PushoverKeys Source #

Construct a PushoverKeys value.

This attempts to create valid tokens/keys from a pair of unvalidated tokens/keys, returning the result wrapped within a MonadError.

Exceptions

errorMessage :: PushoverException -> String Source #

Display a description error message for each PushoverException constructor.