packages feed

pushover 0.1.0.0 → 0.1.0.1

raw patch · 8 files changed

+81/−84 lines, 8 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Lib: someFunc :: IO ()
+ Network.Pushover: Failure :: [RequestError] -> ResponseStatus
+ Network.Pushover: Success :: ResponseStatus
+ Network.Pushover: data ResponseStatus

Files

pushover.cabal view
@@ -1,10 +1,10 @@ name:                pushover-version:             0.1.0.0+version:             0.1.0.1 synopsis:            A Haskell Pushover API library description:         This package provides functionality to allow Haskell                      developers to interact with the Pushover API -                     (https://pushover.net).-homepage:            https://github.com/DanMeakin/pushover#readme+                     (https:\/\/pushover.net).+homepage:            https://github.com/DanMeakin/pushover license:             BSD3 license-file:        LICENSE author:              Dan Meakin@@ -17,8 +17,7 @@  library   hs-source-dirs:      src-  exposed-modules:     Lib-                     , Network.Pushover+  exposed-modules:     Network.Pushover                      , Network.Pushover.Exceptions                      , Network.Pushover.Execute                      , Network.Pushover.Message
− src/Lib.hs
@@ -1,6 +0,0 @@-module Lib-    ( someFunc-    ) where--someFunc :: IO ()-someFunc = putStrLn "someFunc"
src/Network/Pushover.hs view
@@ -46,6 +46,7 @@   , NotificationSound (..)     -- * Response   , Response (..)+  , ResponseStatus (..)     -- * Reader   , PushoverReader (..)   , PushoverKeys (..)
src/Network/Pushover/Exceptions.hs view
@@ -1,11 +1,13 @@+{-| This module defines exceptions which can be thrown within this library.+-} module Network.Pushover.Exceptions where -import Control.Monad.Catch-import Control.Monad.Error.Class-import Control.Monad.Except-import Data.Typeable+import           Control.Monad.Catch+import           Control.Monad.Error.Class+import           Control.Monad.Except+import           Data.Typeable --- | Defines possible exceptions which can be thrown from execution commands. +-- | Defines possible exceptions which can be thrown from execution commands. data PushoverException   = ResponseDecodeException   -- ^ This exception is thrown when a response is malformed and cannot be@@ -30,7 +32,7 @@     PushoverException  --- | Display a description error message for each 'PushoverException' +-- | Display a description error message for each 'PushoverException' --   constructor. errorMessage :: PushoverException -> String errorMessage InvalidTokenLengthException =
src/Network/Pushover/Execute.hs view
@@ -8,7 +8,7 @@ for standalone use.  -}-module Network.Pushover.Execute +module Network.Pushover.Execute   ( -- * Regular functions     sendMessage   , sendRequest@@ -20,20 +20,20 @@   , PushoverException (..)   ) where -import Control.Exception (throw)-import Control.Monad.Error.Class-import Control.Monad.Except-import Control.Monad.Reader-import Data.Aeson (decode)-import Network.Pushover.Message (Message)-import Network.Pushover.Request hiding (userKey)-import Network.Pushover.Response (Response)-import Network.Pushover.Reader (PushoverReader (..))-import Network.Pushover.Exceptions-import Network.Pushover.Token+import           Control.Exception           (throw)+import           Control.Monad.Error.Class+import           Control.Monad.Except+import           Control.Monad.Reader+import           Data.Aeson                  (decode)+import           Network.Pushover.Exceptions+import           Network.Pushover.Message    (Message)+import           Network.Pushover.Reader     (PushoverReader (..))+import           Network.Pushover.Request    hiding (userKey)+import           Network.Pushover.Response   (Response)+import           Network.Pushover.Token -import qualified Network.HTTP.Client as Http-import Network.HTTP.Client.TLS (newTlsManager)+import qualified Network.HTTP.Client         as Http+import           Network.HTTP.Client.TLS     (newTlsManager)  -- | Send a request to the Pushover API. --@@ -53,7 +53,7 @@  -- | Send a request to the Pushover API. ----- This function is designed for use within an existing monad transformer +-- This function is designed for use within an existing monad transformer -- stack to make it easy to send Pushover notifications from inside existing -- software. --@@ -65,8 +65,8 @@                 , MonadIO m                 , MonadReader r m                 , PushoverReader r-                ) -             => Message +                )+             => Message              -> m Response sendMessageM message = do   pushoverRequest <- createRequestM message@@ -75,16 +75,16 @@  -- | Send a request to the Pushover API. ----- This function is designed for use within an existing monad transformer +-- 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.-sendRequestM :: ( Error e +sendRequestM :: ( Error e                 , MonadError e m                 , MonadIO m-                ) +                )              => Request              -> m Response sendRequestM pushoverRequest = do@@ -113,9 +113,9 @@ createRequestM :: ( MonadReader r m                   , PushoverReader r                   )-               => Message +               => Message                -> m Request createRequestM message = do   apiTk <- asks apiToken   usrK  <- asks userKey-  return $ defaultRequest apiTk usrK message  +  return $ defaultRequest apiTk usrK message
src/Network/Pushover/Message.hs view
@@ -14,9 +14,9 @@ other function calls. For example:-  @-  bold -    [ italic -        [ text "This is bold & italic" +  bold+    [ italic+        [ text "This is bold & italic"         ]     , text "This is bold"     , underline@@ -28,7 +28,7 @@ will create a message with the text values formatted as described.  -}-module Network.Pushover.Message +module Network.Pushover.Message   ( -- * Creating a Message     Message   , message@@ -46,24 +46,24 @@   , Url   ) where -import Data.ByteString.Char8 (ByteString)+import           Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B-import Data.Text (Text)-import qualified Data.Text as T-import qualified Data.Text.Encoding as T-import Numeric (showHex)+import           Data.Text             (Text)+import qualified Data.Text             as T+import qualified Data.Text.Encoding    as T+import           Numeric               (showHex)  -- | 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. data Message-  = Parts [Message]-  | Bold [Message]-  | Italic [Message]-  | Underline [Message]+  = Parts           [Message]+  | Bold            [Message]+  | Italic          [Message]+  | Underline       [Message]   | Color ColorCode [Message]-  | Link Url [Message]+  | Link Url        [Message]   | MessageText Text   deriving (Show, Eq) @@ -122,7 +122,7 @@ -- | Construct a 'ColorCode' value. -- -- A 'ColorCode' requires a red, a green and a blue value for construction.--- This function takes these as arguments and returns a constructed +-- This function takes these as arguments and returns a constructed -- 'ColorCode'. -- -- This function checks that each element is within the required 0-255 range.@@ -138,8 +138,8 @@    where         f =-          max 0 . min 255 -  +          max 0 . min 255+ -- | Encode a 'Message' into a bytestring. -- -- This function is intended to convert a 'Message' into a form useable within@@ -148,7 +148,7 @@ encodeMessage =   enc -  where +  where         enc msg =           case msg of                Parts msg ->@@ -202,16 +202,16 @@  -- | Encode a 'ColorCode' into a bytestring. ----- This converts a 'ColorCode' value into its corresponding hexadecimal +-- This converts a 'ColorCode' value into its corresponding hexadecimal -- representation. encodeColorCode :: ColorCode -> ByteString encodeColorCode (ColorCode r g b) =   B.pack $ '#':hexCode -  where +  where         hexCode =           padShow r . padShow g . padShow b $ ""          padShow =-          (\hex rest -> replicate (2 - length (hex "")) '0' ++ hex rest) +          (\hex rest -> replicate (2 - length (hex "")) '0' ++ hex rest)             <$> showHex
src/Network/Pushover/Response.hs view
@@ -1,16 +1,18 @@ {-# LANGUAGE OverloadedStrings #-}+{-| This module defines the 'Response' and 'ResponseSuccess' types.+-} module Network.Pushover.Response where -import Data.Aeson hiding (Success)-import Data.Text (Text)-import qualified Data.Text as T+import           Data.Aeson hiding (Success)+import           Data.Text  (Text)+import qualified Data.Text  as T  -- | 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 +-- 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@@ -31,7 +33,7 @@ -- A request is either successful or unsuccessful. This is reflected in this -- type. Success has no additional data associated with it; failure has a list -- of errors associated.-data ResponseStatus +data ResponseStatus   = Success   | Failure [RequestError]   deriving Show@@ -45,7 +47,7 @@           0 ->            Failure <$> v .: "errors"-              + type RequestError =   Text 
src/Network/Pushover/Token.hs view
@@ -2,13 +2,13 @@ {-| This module contains functionality and types concerning tokens used to authenticate and direct communications with the Pushover API. -The API requires that an API token be sent with every request for +The API requires that an API token be sent with every request for authentication purposes, and a user key be sent with every request for the purpose of identifying the recipient of the message. Both types of token/key are of the same format, and the 'makeToken' functions work for constructing both types of token/key. -}-module Network.Pushover.Token +module Network.Pushover.Token   ( -- * Token type     PushoverToken     -- ** Aliases@@ -22,17 +22,16 @@   , encodeToken   ) where -import Control.Arrow (left)-import Control.Monad (unless)-import Control.Monad.Error.Class-import Control.Monad.Except-import Data.Aeson-import Data.ByteString.Char8 (ByteString)-import Data.Char (isAlphaNum)-import Data.Text (Text)-import qualified Data.Text as T-import qualified Data.Text.Encoding as T-import Network.Pushover.Exceptions+import           Control.Monad               (unless)+import           Control.Monad.Error.Class+import           Control.Monad.Except+import           Data.Aeson+import           Data.ByteString.Char8       (ByteString)+import           Data.Char                   (isAlphaNum)+import           Data.Text                   (Text)+import qualified Data.Text                   as T+import qualified Data.Text.Encoding          as T+import           Network.Pushover.Exceptions  -- | Define a type to represent the different types of token or key Pushover --   requires.@@ -58,7 +57,7 @@            fail $ errorMessage err    -- | API token for making a Pushover request.-type APIToken +type APIToken   = PushoverToken  -- | User key for the user receiving a notification.@@ -69,7 +68,7 @@ -- -- 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. +-- the correct length and contains valid characters. -- -- A descriptive error is returned where validation fails. makeToken :: Text -> Either PushoverException PushoverToken@@ -80,8 +79,8 @@ -- -- This is similar to the 'makeToken' function, except that it is generalised -- over the 'MonadError' monad.-makeTokenM :: (Error e, MonadError e m) -           => Text +makeTokenM :: (Error e, MonadError e m)+           => Text            -> m PushoverToken makeTokenM tokenText = do   unless validateLength $@@ -90,7 +89,7 @@     throwError . strMsg $ errorMessage InvalidTokenCharactersException   return $ PushoverToken tokenText -  where +  where         validateLength =           T.length tokenText == 30