amazon-emailer-client-snap (empty) → 0.1.0.0
raw patch · 4 files changed
+103/−0 lines, 4 filesdep +basedep +mtldep +snapsetup-changed
Dependencies added: base, mtl, snap, snaplet-postgresql-simple, text
Files
- LICENSE +30/−0
- Setup.hs +2/−0
- amazon-emailer-client-snap.cabal +24/−0
- src/Network/AmazonEmailer/Client/Snap.hs +47/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2014, Daniel Patterson++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Daniel Patterson nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ amazon-emailer-client-snap.cabal view
@@ -0,0 +1,24 @@+name: amazon-emailer-client-snap+version: 0.1.0.0+synopsis: Client library for amazon-emailer daemon+homepage: https://github.com/dbp/amazon-emailer-client-snap+license: BSD3+license-file: LICENSE+author: Daniel Patterson+maintainer: dbp@dbpmail.net+-- copyright:+category: Network+build-type: Simple+-- extra-source-files:+cabal-version: >=1.10++library+ exposed-modules:+ Network.AmazonEmailer.Client.Snap+ hs-source-dirs: src+ build-depends: base == 4.*,+ snap == 0.13.*,+ snaplet-postgresql-simple == 0.4.*,+ mtl == 2.*,+ text == 0.11.*+ default-language: Haskell2010
+ src/Network/AmazonEmailer/Client/Snap.hs view
@@ -0,0 +1,47 @@+{-# LANGUAGE OverloadedStrings, FlexibleContexts #-}++module Network.AmazonEmailer.Client.Snap where++import Data.Text (Text)+import Control.Monad (void)+import Control.Monad.Trans (liftIO)++import Snap.Snaplet (Handler)+import Snap.Snaplet.PostgresqlSimple (HasPostgres, execute, executeMany)+++data Email = Email { emTo :: Text+ , emFrom :: Text+ , emFromName :: Text+ , emSubject :: Text+ , emBody :: Text+ } deriving (Show, Eq)++-- | Sends a single plain text message+sendMessage :: HasPostgres (Handler b a) => Email -> Handler b a ()+sendMessage e@(Email to from fromName subj body) =+ do liftIO $ print e+ void $ execute "insert into amazon_email_queue (to_addr, from_addr, from_name, subject, body) values (?,?,?,?,?)" (to, from, fromName, subj, body)++-- | Sends a single html message+sendMessageHtml :: HasPostgres (Handler b a) => Email -> Handler b a ()+sendMessageHtml e@(Email to from fromName subj body) =+ do liftIO $ print e+ void $ execute "insert into amazon_email_queue (to_addr, from_addr, from_name, subject, body, html) values (?,?,?,?,?, true)" (to, from, fromName, subj, body)+++-- | Sends many plain text messages+sendMessages :: HasPostgres (Handler b a) => [Email] -> Handler b a ()+sendMessages es = do+ liftIO $ putStrLn $ "Sending " ++ show (length es) ++ " messages."+ executeMany "insert into amazon_email_queue (to_addr,from_addr,from_name,subject,body) values (?,?,?,?,?)"+ (map (\(Email to from fromName subj body) -> (to,from,fromName,subj,body)) es)+ return ()++-- | Sends many html messages+sendMessagesHtml :: HasPostgres (Handler b a) => [Email] -> Handler b a ()+sendMessagesHtml es = do+ liftIO $ putStrLn $ "Sending " ++ show (length es) ++ " messages."+ executeMany "insert into amazon_email_queue (to_addr,from_addr,from_name,subject,body,html) values (?,?,?,?,?,?, true)"+ (map (\(Email to from fromName subj body) -> (to,from,fromName,subj,body)) es)+ return ()