packages feed

snaplet-mandrill 0.1.0.2 → 0.1.0.3

raw patch · 2 files changed

+63/−16 lines, 2 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

README.org view
@@ -1,34 +1,78 @@ * Welcome!-  =snaplet-amqp= provides a convenience interface to the Haskell AMQP-  package.+  [[https://hackage.haskell.org/package/snaplet-mandrill][https://img.shields.io/hackage/v/snaplet-mandrill.svg?style=flat]]+  [[https://travis-ci.org/ixmatus/snaplet-mandrill][https://travis-ci.org/ixmatus/snaplet-mandrill.svg?branch=master]]+  +  =snaplet-mandrill= provides a convenience interface to the Haskell+  Mandrill package.    #+BEGIN_SRC+  {-# LANGUAGE FlexibleInstances #-}+  {-# LANGUAGE OverloadedStrings #-}+  {-# LANGUAGE RecordWildCards   #-}+  {-# LANGUAGE TemplateHaskell   #-}++  module Main where++  ------------------------------------------------------------------------------+  import           Control.Applicative   import           Control.Lens+  import           Data.ByteString.Char8 as C8+  import           Data.Maybe            (fromMaybe)+  import           Network.API.Mandrill  hiding (runMandrill)   import           Snap-  import           Snap.Snaplet   import           Snap.Snaplet.Mandrill-  import           Network.API.Mandrill  hiding (runMandrill)+  import           Text.Email.Validate +  ------------------------------------------------------------------------------   data App = App-      { _mandrill :: Snaplet Mandrill }+      { _mandrill :: Snaplet MandrillState+      }    makeLenses ''App    instance HasMandrill (Handler b App) where       getMandrill = with mandrill getMandrill +  ------------------------------------------------------------------------------+  -- | The application's routes.+  routes :: [(ByteString, Handler App App ())]+  routes = [ ("/"            , writeText "hello")+           , ("mailme/:email", fooHandler)+           ]++  decodedParam :: MonadSnap m => ByteString -> m ByteString+  decodedParam p = fromMaybe "" <$> getParam p++  fooHandler :: Handler App App ()+  fooHandler = do+      email <- decodedParam "email"+      case emailAddress email of+          Nothing -> do+              modifyResponse $ setResponseCode 400+          Just e  -> do+              res <- runMandrill $ do+                  return =<< sendEmail (newTextMessage e [e] "Hello" "<p>My Html</p>")++              mandrillResponse res++      getResponse >>= finishWith++    where+      mandrillResponse (MandrillSuccess _) = modifyResponse $ setResponseCode 204+      mandrillResponse (MandrillFailure e) = do+                      modifyResponse $ setResponseCode 500+                      writeBS . C8.pack $ show e+++  ------------------------------------------------------------------------------+  -- | The application initializer.   app :: SnapletInit App App   app = makeSnaplet "app" "An snaplet example application." Nothing $ do-      a <- nestSnaplet "mandrill" mandrill initMandrill-      addRoutes appRoutes -- Your routes, I haven't defined any here-      return $ App a+      m <- nestSnaplet "mandrill" mandrill $ initMandrill+      addRoutes routes+      return $ App m -  handler = do-      runMandrill $ do-          let msg = "<p>My Html</p>"-          res <- sendEmail (newTextMessage addr [addr] "Hello" msg)-          case res of-            MandrillSuccess k -> liftIO (print k)-            MandrillFailure f -> liftIO (print f) +  main :: IO ()+  main = serveSnaplet defaultConfig app   #+END_SRC
snaplet-mandrill.cabal view
@@ -1,5 +1,5 @@ Name:                snaplet-mandrill-Version:             0.1.0.2+Version:             0.1.0.3 Synopsis:            Snap framework snaplet for the Mandrill API library. Homepage:            https://github.com/ixmatus/snaplet-mandrill License:             BSD3@@ -16,6 +16,9 @@ Cabal-version:       >=1.14.0  description:++  <<https://travis-ci.org/ixmatus/snaplet-mandrill.svg?branch=master>>+  .   `snaplet-mandrill` is a snaplet for the Snap web framework providing   convenience functions and state management for the Haskell Mandrill   package.