Safe Haskell | None |
---|---|
Language | Haskell2010 |
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.
- sendMessage :: APIToken -> UserKey -> Message -> IO Response
- sendRequest :: Request -> IO Response
- createRequest :: APIToken -> UserKey -> Message -> Request
- sendMessageM :: (Error e, MonadError e m, MonadIO m, MonadReader r m, PushoverReader r) => Message -> m Response
- sendRequestM :: (Error e, MonadError e m, MonadIO m) => Request -> m Response
- createRequestM :: (MonadReader r m, PushoverReader r) => Message -> m Request
- data Request
- defaultRequest :: APIToken -> UserKey -> Message -> Request
- data Message
- message :: [Message] -> Message
- bold :: [Message] -> Message
- italic :: [Message] -> Message
- underline :: [Message] -> Message
- color :: Integer -> Integer -> Integer -> [Message] -> Message
- link :: Url -> [Message] -> Message
- text :: Text -> Message
- type APIToken = PushoverToken
- type UserKey = PushoverToken
- data PushoverToken
- makeToken :: Text -> Either PushoverException PushoverToken
- data URL = URL {}
- data Priority
- data NotificationSound
- = Pushover
- | Bike
- | Bugle
- | CashRegister
- | Classical
- | Cosmic
- | Falling
- | Gamelan
- | Incoming
- | Intermission
- | Magic
- | Mechanical
- | PianoBar
- | Siren
- | SpaceAlarm
- | TugBoat
- | AlienAlarm
- | Climb
- | Persistent
- | Echo
- | UpDown
- | None
- data Response = Response {
- status :: ResponseStatus
- request :: Text
- class PushoverReader r where
- data PushoverKeys = PushoverKeys {}
- createKeys :: (Error e, MonadError e m) => UnvalidatedAPIToken -> UnvalidatedUserKey -> m PushoverKeys
- data PushoverException
- errorMessage :: PushoverException -> String
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
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
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.
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.
Authenticating a request
type APIToken = PushoverToken Source #
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
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.
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.
data NotificationSound Source #
Describes the notification sound for a notification.
Response
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.
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.
data PushoverKeys Source #
A basic type for use in storing the pair of keys required for making a request.
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
data PushoverException Source #
Defines possible exceptions which can be thrown from execution commands.
errorMessage :: PushoverException -> String Source #
Display a description error message for each PushoverException
constructor.