packages feed

postmark 0.0.2 → 0.1.0

raw patch · 5 files changed

+158/−4 lines, 5 filesdep +postmarkdep ~basedep ~textnew-component:exe:postmark-demo

Dependencies added: postmark

Dependency ranges changed: base, text

Files

+ demo/demo.hs view
@@ -0,0 +1,10 @@+{-# LANGUAGE OverloadedStrings #-}++import System.Environment++import Network.Api.Postmark.Demo++main :: IO ()+main = do+  args <- getArgs+  dispatch args >>= print
postmark.cabal view
@@ -1,5 +1,5 @@ Name:               postmark-Version:            0.0.2+Version:            0.1.0 License:            BSD3 License-File:       LICENSE Author:             Mark Hibberd <mark@hibberd.id.au>@@ -21,6 +21,10 @@ Flag                small_base   Description:      Choose the new, split-up base package. +Flag demo+    Description:   Build the demo executable.+    Default:       False+ Library   Build-Depends:                     base                            >= 3          && < 5@@ -50,3 +54,17 @@                     Network.Api.Postmark.Request                     Network.Api.Postmark.Response                     Network.Api.Postmark.Settings+                    Network.Api.Postmark.Tutorial++executable         postmark-demo+    if flag(demo)+        Buildable: True+    else+        Buildable: False++    ghc-options:   -Wall -threaded -O2+    main-is:           ../demo/demo.hs+    hs-source-dirs:    dist demo+    build-depends:     base+                     , postmark+                     , text
src/Network/Api/Postmark.hs view
@@ -1,11 +1,23 @@ -- |--- Module:      Network.Postmark+-- Module:      Network.Api.Postmark -- Copyright:   (c) 2012 Mark Hibberd -- License:     BSD3 -- Maintainer:  Mark Hibberd <mark@hibberd.id.au> -- Portability: portable ----- Library for postmarkapp.com HTTP Api+-- Library for postmarkapp.com HTTP Api.+--+-- To get start see some examples in the 'Network.Api.Postmark.Tutorial' module at <http://hackage.haskell.org/packages/archive/postmark/0.0.2/doc/html/Network-Api-Postmark-Tutorial.html>.+--+-- Source and more information can be found at <https://github.com/apiengine/postmark>.+--+-- To experiment with a live demo try:+-- > $ git clone https://github.com/apiengine/postmark+-- > $ cd postmark+-- > $ cabal install --only-dependencies &&  cabal configure -f demo  && cabal build+-- > $ ./dist/build/postmark-demo/postmark-demo+--+-- Issues can be reported at <https://github.com/apiengine/postmark/issues>. -- module Network.Api.Postmark (module X) where 
src/Network/Api/Postmark/Settings.hs view
@@ -7,7 +7,7 @@   PostmarkSettings {       apiUrl :: Text     , apiToken :: Text-    }+    } deriving (Eq, Show)  postmarkTestToken :: Text postmarkTestToken = "POSTMARK_API_TEST"
+ src/Network/Api/Postmark/Tutorial.hs view
@@ -0,0 +1,114 @@+{-# LANGUAGE OverloadedStrings #-}+{-# OPTIONS_GHC -fno-warn-unused-imports #-}+{-| @postmark@ is a haskell toolkit for dealing with the postmarkapp.com api+    for sending and receiving email.+-}+module Network.Api.Postmark.Tutorial (+    -- * Settings+    -- $settings++    -- * Sending Mail+    -- $email++    -- * Handling Responses+    -- $response+    ) where++import Network.Api.Postmark++{- $settings++++> postmarkHttp "<your api token>"   -- Build PostmarkSettings to talk to+>                                   -- the _http_ api with you own api token.+> postmarkHttps "<your api token>"  -- Build PostmarkSettings to talk to+>                                   -- the _https_ api with you own api token.+> postmarkHttpTest                  -- Build PostmarkSettings to talk to+>                                   -- the _http_ api with the public test token.+> postmarkHttpsTest                 -- Build PostmarkSettings to talk to+>                                   -- the _https_ api with the public test token.++-}++{- $email++Sending a single email.++> import Network.Api.Postmark+>+> request postmarkHttpTest $ email defaultEmail {+>       emailFrom = "demo-from@postmark.hs"+>     , emailTo = ["demo-to@postmark.hs"]+>     , emailSubject = "demo, yes it really is a demo"+>     , emailTag = Just "demo"+>     , emailHtml = Just "Hello world!"+>     , emailReplyTo = "demo-reply-to@postmark.hs"+>     }++Sending multiple emails.++> import Network.Api.Postmark+>+> demo = request postmarkHttpTrest $ emails [+>     defaultEmail {+>       emailFrom = "demo-from@postmark.hs"+>     , emailTo = ["demo-to@postmark.hs"]+>     , emailSubject = "demo, yes it really is a demo"+>     , emailTag = Just "demo"+>     , emailHtml = Just "Hello world!"+>     , emailReplyTo = "demo-reply-to@postmark.hs"+>     }+>   , defaultEmail {+>       emailFrom = "demo-from@postmark.hs"+>     , emailTo = ["demo-to@postmark.hs"]+>     , emailSubject = "demo, yes it really is a demo"+>     , emailTag = Just "demo"+>     , emailHtml = Just "Hello world again!"+>     , emailReplyTo = "demo-reply-to@postmark.hs"+>     }+>   }+-}++{- $response++Checking if the response is a success, ignoring detail:++> import Network.Api.Postmark+>+> case result of+>   PostmarkSuccess _ -> True+++Handling specific failure cases:++> import Network.Api.Postmark+>+> case result of+>   PostmarkSuccess a ->  undefined            -- Everything ok.+>   PostmarkUnauthorized -> undefined          -- Invalid api token.+>   PostmarkFailure (PostmarkError errortype message)+>                     -> undefined             -- A standard postmark failure.+>   PostmarkUnexpected reason code body message+>                     -> undefined             -- Unexpected failure (bug or+>                                              -- api change).++Handling known postmark failures:++> import Network.Api.Postmark+>+> case errortype of+>   PostmarkBadApiToken -> undefined+>   PostmarkInvalidEmail -> undefined+>   PostmarkSenderNotFound -> undefined+>   PostmarkSenderNotConfirmed -> undefined+>   PostmarkInvalidJson -> undefined+>   PostmarkIncompatibleJson -> undefined+>   PostmarkNotAllowed -> undefined+>   PostmarkInactive -> undefined+>   PostmarkBounceNotFound -> undefined+>   PostmarkBounceQueryException -> undefined+>   PostmarkJsonRequired -> undefined+>   PostmarkTooManyMessages -> undefined+>   PostmarkUnkownError Int -> undefined+-}