git.iko.soy/typeable/mandrill
on master help sign in
Basic support for messages/send-template
283ce9etheunis
src/Network/API/Mandrill.hs+11
@@ -12,6 +12,7 @@ module Network.API.Mandrill (
12 , emptyMessage
12 , emptyMessage
13 , newTextMessage
13 , newTextMessage
14 , newHtmlMessage
14 , newHtmlMessage
15+ , newTemplateMessage
15 , liftIO
16 , liftIO
16
17
17 -- * Appendix: Example Usage
18 -- * Appendix: Example Usage
@@ -106,6 +107,16 @@ newHtmlMessage :: EmailAddress
106newHtmlMessage f t subj html = let body = mkMandrillHtml html in
107newHtmlMessage f t subj html = let body = mkMandrillHtml html in
107 ((mmsg_html .~ body) . (mmsg_subject .~ subj)) $ (emptyMessage f t)
108 ((mmsg_html .~ body) . (mmsg_subject .~ subj)) $ (emptyMessage f t)
108
109
110+--------------------------------------------------------------------------------
111+-- | Create a new template message (no HTML).
112+newTemplateMessage :: EmailAddress
113+ -- ^ Sender email
114+ -> [EmailAddress]
115+ -- ^ Receivers email
116+ -> T.Text
117+ -- ^ Subject
118+ -> MandrillMessage
119+newTemplateMessage f t subj = (mmsg_subject .~ subj) $ (emptyMessage f t)
109
120
110--------------------------------------------------------------------------------
121--------------------------------------------------------------------------------
111-- | Create a new textual message. By default Mandrill doesn't require you
122-- | Create a new textual message. By default Mandrill doesn't require you
src/Network/API/Mandrill/Messages.hs+19
@@ -24,3 +24,22 @@ send :: MandrillKey
24 -> Maybe Manager
24 -> Maybe Manager
25 -> IO (MandrillResponse [MessagesResponse])
25 -> IO (MandrillResponse [MessagesResponse])
26send k msg async ip_pool send_at = toMandrillResponse MessagesSend (MessagesSendRq k msg async ip_pool send_at)
26send k msg async ip_pool send_at = toMandrillResponse MessagesSend (MessagesSendRq k msg async ip_pool send_at)
27+
28+-- | Send a new transactional message through Mandrill using a template
29+sendTemplate :: MandrillKey
30+ -- ^ The API key
31+ -> MandrillTemplate
32+ -- ^ The template name
33+ -> [MandrillTemplateContent]
34+ -- ^ Template content for 'editable regions'
35+ -> MandrillMessage
36+ -- ^ The email message
37+ -> Maybe Bool
38+ -- ^ Enable a background sending mode that is optimized for bulk sending
39+ -> Maybe T.Text
40+ -- ^ ip_pool
41+ -> Maybe UTCTime
42+ -- ^ send_at
43+ -> Maybe Manager
44+ -> IO (MandrillResponse [MessagesResponse])
45+sendTemplate k template content msg async ip_pool send_at = toMandrillResponse MessagesSendTemplate (MessagesSendTemplateRq k template content msg async ip_pool send_at)
src/Network/API/Mandrill/Messages/Types.hs+13
@@ -27,6 +27,19 @@ data MessagesSendRq = MessagesSendRq {
27makeLenses ''MessagesSendRq
27makeLenses ''MessagesSendRq
28deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MessagesSendRq
28deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MessagesSendRq
29
29
30+--------------------------------------------------------------------------------
31+data MessagesSendTemplateRq = MessagesSendTemplateRq {
32+ _mstrq_key :: MandrillKey
33+ , _mstrq_template_name :: T.Text
34+ , _mstrq_template_content :: [MandrillTemplateContent]
35+ , _mstrq_message :: MandrillMessage
36+ , _mstrq_async :: Maybe Bool
37+ , _mstrq_ip_pool :: Maybe T.Text
38+ , _mstrq_send_at :: Maybe UTCTime
39+ } deriving Show
40+
41+makeLenses ''MessagesSendTemplateRq
42+deriveJSON defaultOptions { fieldLabelModifier = drop 7 } ''MessagesSendTemplateRq
30
43
31--------------------------------------------------------------------------------
44--------------------------------------------------------------------------------
32data MessagesResponse = MessagesResponse {
45data MessagesResponse = MessagesResponse {
src/Network/API/Mandrill/Types.hs+11
@@ -330,8 +330,19 @@ instance Arbitrary MandrillMessage where
330 <*> pure []
330 <*> pure []
331 <*> pure []
331 <*> pure []
332
332
333+--------------------------------------------------------------------------------
334+-- | Key value pair for replacing content in templates via 'Editable Regions'
335+data MandrillTemplateContent = MandrillTemplateContent {
336+ _mtc_name :: T.Text
337+ , _mtc_content :: T.Text
338+ } deriving Show
339+
340+makeLenses ''MandrilTemplateContent
341+deriveJSON defaultOptions { fieldLabelModifier = drop 5 } ''MandrilTemplateContent
342+
333--------------------------------------------------------------------------------
343--------------------------------------------------------------------------------
334type MandrillKey = T.Text
344type MandrillKey = T.Text
345+type MandrillTemplate = T.Text
335
346
336newtype MandrillDate = MandrillDate {
347newtype MandrillDate = MandrillDate {
337 fromMandrillDate :: UTCTime
348 fromMandrillDate :: UTCTime