@@ -5,13 +5,14 @@
5module Network.API.Mandrill.Types where
5module Network.API.Mandrill.Types where
7import Network.API.Mandrill.Utils
7import Network.API.Mandrill.Utils
8+import Network.API.Mandrill.Orphans()
8import Test.QuickCheck
9import Test.QuickCheck
10+import Text.Email.Validate
9import Data.Char
11import Data.Char
10import Data.Time
13import Data.Time
11import Control.Applicative
14import Control.Applicative
12import System.Locale (defaultTimeLocale)
15import System.Locale (defaultTimeLocale)
14−import qualified Data.Map as Map
15import qualified Data.ByteString as B
16import qualified Data.ByteString as B
16import qualified Data.ByteString.Base64 as Base64
17import qualified Data.ByteString.Base64 as Base64
17import qualified Data.Text as T
18import qualified Data.Text as T
@@ -90,7 +91,7 @@ deriveJSON defaultOptions { constructorTagModifier = map toLower } ''MandrillRec
90--------------------------------------------------------------------------------
91--------------------------------------------------------------------------------
91-- | An array of recipient information.
92-- | An array of recipient information.
92data MandrillRecipient = MandrillRecipient {
93data MandrillRecipient = MandrillRecipient {
93− _mrec_email :: !T.Text
94+ _mrec_email :: EmailAddress
94 -- ^ The email address of the recipient
95 -- ^ The email address of the recipient
95 , _mrec_name :: Maybe T.Text
96 , _mrec_name :: Maybe T.Text
96 -- ^ The optional display name to use for the recipient
97 -- ^ The optional display name to use for the recipient
@@ -102,17 +103,30 @@ data MandrillRecipient = MandrillRecipient {
102makeLenses ''MandrillRecipient
103makeLenses ''MandrillRecipient
103deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillRecipient
104deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillRecipient
106+newRecipient :: EmailAddress -> MandrillRecipient
107+newRecipient email = MandrillRecipient email Nothing Nothing
105instance Arbitrary MandrillRecipient where
109instance Arbitrary MandrillRecipient where
106− arbitrary = pure $ MandrillRecipient "test@example.com" Nothing Nothing
110+ arbitrary = pure MandrillRecipient {
111+ _mrec_email = fromJust (emailAddress "test@example.com")
112+ , _mrec_name = Nothing
113+ , _mrec_type = Nothing
108--------------------------------------------------------------------------------
116--------------------------------------------------------------------------------
109newtype MandrillHtml = MandrillHtml Blaze.Html
117newtype MandrillHtml = MandrillHtml Blaze.Html
111−mkMandrillHtml :: T.Text -> MandrillHtml
119+unsafeMkMandrillHtml :: T.Text -> MandrillHtml
112−mkMandrillHtml = MandrillHtml . Blaze.toHtml
120+unsafeMkMandrillHtml = MandrillHtml . Blaze.preEscapedToHtml
122+-- This might be slightly hairy because it violates
123+-- the nice encapsulation that newtypes offer.
124+mkMandrillHtml :: Blaze.Html -> MandrillHtml
125+mkMandrillHtml = MandrillHtml
127+instance Monoid MandrillHtml where
114−mkMandrillHtml' :: Blaze.Html -> MandrillHtml
128+ mempty = MandrillHtml mempty
115−mkMandrillHtml' = MandrillHtml
129+ mappend (MandrillHtml m1) (MandrillHtml m2) = MandrillHtml (m1 <> m2)
117instance Show MandrillHtml where
131instance Show MandrillHtml where
118 show (MandrillHtml h) = show $ Blaze.renderHtml h
132 show (MandrillHtml h) = show $ Blaze.renderHtml h
@@ -191,7 +205,7 @@ data MandrillMessage = MandrillMessage {
191 -- ^ Optional full text content to be sent
205 -- ^ Optional full text content to be sent
192 , _mmsg_subject :: !T.Text
206 , _mmsg_subject :: !T.Text
193 -- ^ The message subject
207 -- ^ The message subject
194− , _mmsg_from_email :: !T.Text
208+ , _mmsg_from_email :: EmailAddress
195 -- ^ The sender email address
209 -- ^ The sender email address
196 , _mmsg_from_name :: Maybe T.Text
210 , _mmsg_from_name :: Maybe T.Text
197 -- ^ Optional from name to be used
211 -- ^ Optional from name to be used
@@ -274,7 +288,7 @@ instance Arbitrary MandrillMessage where
274 arbitrary = MandrillMessage <$> arbitrary
288 arbitrary = MandrillMessage <$> arbitrary
275 <*> pure Nothing
289 <*> pure Nothing
276 <*> pure "Test Subject"
290 <*> pure "Test Subject"
277− <*> pure "sender@example.com"
291+ <*> pure (fromJust $ emailAddress "sender@example.com")
278 <*> pure Nothing
292 <*> pure Nothing
279 <*> resize 2 arbitrary
293 <*> resize 2 arbitrary
280 <*> pure emptyObject
294 <*> pure emptyObject