@@ -1,44 +1,36 @@
1−{-# LANGUAGE CPP #-}
1+{-# LANGUAGE TemplateHaskell #-}
2−{-# LANGUAGE DeriveFoldable #-}
2+{-# LANGUAGE CPP #-}
3−{-# LANGUAGE DeriveFunctor #-}
4−{-# LANGUAGE DeriveTraversable #-}
5−{-# LANGUAGE OverloadedStrings #-}
6−{-# LANGUAGE RankNTypes #-}
3+{-# LANGUAGE RankNTypes #-}
7{-# LANGUAGE ScopedTypeVariables #-}
4{-# LANGUAGE ScopedTypeVariables #-}
8−{-# LANGUAGE TemplateHaskell #-}
5+{-# LANGUAGE OverloadedStrings #-}
9module Network.API.Mandrill.Types where
6module Network.API.Mandrill.Types where
11−import Control.Applicative
12−import Control.Monad (mzero)
16−import Lens.Micro.TH (makeLenses)
17import Network.API.Mandrill.Utils
8import Network.API.Mandrill.Utils
18import Test.QuickCheck
9import Test.QuickCheck
19import Text.Email.Validate
10import Text.Email.Validate
14+import Control.Applicative
20#if MIN_VERSION_time(1,5,0)
15#if MIN_VERSION_time(1,5,0)
21−import Data.Time.Format (TimeLocale, defaultTimeLocale)
16+import Data.Time.Format (TimeLocale, defaultTimeLocale)
23−import System.Locale (TimeLocale, defaultTimeLocale)
18+import System.Locale (TimeLocale, defaultTimeLocale)
20+import qualified Data.ByteString as B
21+import qualified Data.ByteString.Base64 as Base64
22+import qualified Data.HashMap.Strict as H
23+import qualified Data.Text as T
24+import qualified Data.Text.Encoding as TL
25+import qualified Data.Text.Lazy as TL
25import Data.Aeson
28import Data.Aeson
27import Data.Aeson.Types
29import Data.Aeson.Types
28−import qualified Data.ByteString as B
30+import Data.Aeson.TH
29−import qualified Data.ByteString.Base64 as Base64
30−#if !MIN_VERSION_base(4,8,0)
32−import Data.Traversable
34−import qualified Data.HashMap.Strict as H
36−import qualified Data.Text as T
37−import qualified Data.Text.Encoding as TL
38−import qualified Data.Text.Lazy as TL
39−import qualified Text.Blaze.Html as Blaze
31+import qualified Text.Blaze.Html as Blaze
40import qualified Text.Blaze.Html.Renderer.Text as Blaze
32import qualified Text.Blaze.Html.Renderer.Text as Blaze
41−import qualified Text.Email.Validate as TEV
33+
43timeParse :: ParseTime t => TimeLocale -> String -> String -> Maybe t
35timeParse :: ParseTime t => TimeLocale -> String -> String -> Maybe t
44#if MIN_VERSION_time(1,5,0)
36#if MIN_VERSION_time(1,5,0)
@@ -49,11 +41,11 @@ timeParse = parseTime
50--------------------------------------------------------------------------------
42--------------------------------------------------------------------------------
51data MandrillError = MandrillError {
43data MandrillError = MandrillError {
52− _merr_status :: !T.Text
44+ _merr_status :: !T.Text
53− , _merr_code :: !Int
45+ , _merr_code :: !Int
54− , _merr_name :: !T.Text
46+ , _merr_name :: !T.Text
55 , _merr_message :: !T.Text
47 , _merr_message :: !T.Text
56− } deriving (Show, Eq)
48+ } deriving Show
58makeLenses ''MandrillError
50makeLenses ''MandrillError
59deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillError
51deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillError
@@ -78,7 +70,6 @@ data MandrillRejectReason = RR_HardBounce
78 | RR_InvalidSender
70 | RR_InvalidSender
79 | RR_Invalid
71 | RR_Invalid
80 | RR_TestModeLimit
72 | RR_TestModeLimit
82 | RR_Rule deriving Show
73 | RR_Rule deriving Show
84deriveJSON defaultOptions {
75deriveJSON defaultOptions {
@@ -91,7 +82,7 @@ deriveJSON defaultOptions {
91-- which can be either a success or a failure.
82-- which can be either a success or a failure.
92data MandrillResponse k =
83data MandrillResponse k =
93 MandrillSuccess k
84 MandrillSuccess k
94− | MandrillFailure MandrillError deriving (Show, Eq, Functor, Foldable, Traversable)
85+ | MandrillFailure MandrillError deriving Show
96instance FromJSON k => FromJSON (MandrillResponse k) where
87instance FromJSON k => FromJSON (MandrillResponse k) where
97 parseJSON v = case (parseMaybe parseJSON v) :: Maybe k of
88 parseJSON v = case (parseMaybe parseJSON v) :: Maybe k of
@@ -127,9 +118,9 @@ instance FromJSON MandrillEmail where
127data MandrillRecipient = MandrillRecipient {
118data MandrillRecipient = MandrillRecipient {
128 _mrec_email :: MandrillEmail
119 _mrec_email :: MandrillEmail
129 -- ^ The email address of the recipient
120 -- ^ The email address of the recipient
130− , _mrec_name :: Maybe T.Text
121+ , _mrec_name :: Maybe T.Text
131 -- ^ The optional display name to use for the recipient
122 -- ^ The optional display name to use for the recipient
132− , _mrec_type :: Maybe MandrillRecipientTag
123+ , _mrec_type :: Maybe MandrillRecipientTag
133 -- ^ The header type to use for the recipient.
124 -- ^ The header type to use for the recipient.
134 -- defaults to "to" if not provided
125 -- defaults to "to" if not provided
135 } deriving Show
126 } deriving Show
@@ -158,11 +149,6 @@ unsafeMkMandrillHtml = MandrillHtml . Blaze.preEscapedToHtml
158mkMandrillHtml :: Blaze.Html -> MandrillHtml
149mkMandrillHtml :: Blaze.Html -> MandrillHtml
159mkMandrillHtml = MandrillHtml
150mkMandrillHtml = MandrillHtml
161−#if MIN_VERSION_base(4,11,0)
162−instance Semigroup MandrillHtml where
163− MandrillHtml m1 <> MandrillHtml m2 = MandrillHtml (m1 <> m2)
166instance Monoid MandrillHtml where
152instance Monoid MandrillHtml where
167 mempty = MandrillHtml mempty
153 mempty = MandrillHtml mempty
168 mappend (MandrillHtml m1) (MandrillHtml m2) = MandrillHtml (m1 <> m2)
154 mappend (MandrillHtml m1) (MandrillHtml m2) = MandrillHtml (m1 <> m2)
@@ -209,7 +195,7 @@ deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMergeVars
210--------------------------------------------------------------------------------
196--------------------------------------------------------------------------------
211data MandrillMetadata = MandrillMetadata {
197data MandrillMetadata = MandrillMetadata {
212− _mmdt_rcpt :: !T.Text
198+ _mmdt_rcpt :: !T.Text
213 , _mmdt_values :: Object
199 , _mmdt_values :: Object
214 } deriving Show
200 } deriving Show
@@ -234,8 +220,8 @@ instance FromJSON Base64ByteString where
235--------------------------------------------------------------------------------
221--------------------------------------------------------------------------------
236data MandrillWebContent = MandrillWebContent {
222data MandrillWebContent = MandrillWebContent {
237− _mwct_type :: !T.Text
223+ _mwct_type :: !T.Text
238− , _mwct_name :: !T.Text
224+ , _mwct_name :: !T.Text
239 -- ^ [for images] the Content ID of the image
225 -- ^ [for images] the Content ID of the image
240 -- - use <img src="cid:THIS_VALUE"> to reference the image
226 -- - use <img src="cid:THIS_VALUE"> to reference the image
241 -- in your HTML content
227 -- in your HTML content
@@ -248,67 +234,67 @@ deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillWebContent
248--------------------------------------------------------------------------------
234--------------------------------------------------------------------------------
249-- | The information on the message to send
235-- | The information on the message to send
250data MandrillMessage = MandrillMessage {
236data MandrillMessage = MandrillMessage {
251− _mmsg_html :: MandrillHtml
237+ _mmsg_html :: MandrillHtml
252 -- ^ The full HTML content to be sent
238 -- ^ The full HTML content to be sent
253− , _mmsg_text :: Maybe T.Text
239+ , _mmsg_text :: Maybe T.Text
254 -- ^ Optional full text content to be sent
240 -- ^ Optional full text content to be sent
255− , _mmsg_subject :: !T.Text
241+ , _mmsg_subject :: !T.Text
256 -- ^ The message subject
242 -- ^ The message subject
257− , _mmsg_from_email :: MandrillEmail
243+ , _mmsg_from_email :: MandrillEmail
258 -- ^ The sender email address
244 -- ^ The sender email address
259− , _mmsg_from_name :: Maybe T.Text
245+ , _mmsg_from_name :: Maybe T.Text
260 -- ^ Optional from name to be used
246 -- ^ Optional from name to be used
261− , _mmsg_to :: [MandrillRecipient]
247+ , _mmsg_to :: [MandrillRecipient]
262 -- ^ A list of recipient information
248 -- ^ A list of recipient information
263− , _mmsg_headers :: MandrillHeaders
249+ , _mmsg_headers :: MandrillHeaders
264 -- ^ optional extra headers to add to the message (most headers are allowed)
250 -- ^ optional extra headers to add to the message (most headers are allowed)
265− , _mmsg_important :: Maybe Bool
251+ , _mmsg_important :: Maybe Bool
266 -- ^ whether or not this message is important, and should be delivered ahead
252 -- ^ whether or not this message is important, and should be delivered ahead
267 -- of non-important messages
253 -- of non-important messages
268− , _mmsg_track_opens :: Maybe Bool
254+ , _mmsg_track_opens :: Maybe Bool
269 -- ^ whether or not to turn on open tracking for the message
255 -- ^ whether or not to turn on open tracking for the message
270− , _mmsg_track_clicks :: Maybe Bool
256+ , _mmsg_track_clicks :: Maybe Bool
271 -- ^ whether or not to turn on click tracking for the message
257 -- ^ whether or not to turn on click tracking for the message
272− , _mmsg_auto_text :: Maybe Bool
258+ , _mmsg_auto_text :: Maybe Bool
273 -- ^ whether or not to automatically generate a text part for messages that are not given text
259 -- ^ whether or not to automatically generate a text part for messages that are not given text
274− , _mmsg_auto_html :: Maybe Bool
260+ , _mmsg_auto_html :: Maybe Bool
275 -- ^ whether or not to automatically generate an HTML part for messages that are not given HTML
261 -- ^ whether or not to automatically generate an HTML part for messages that are not given HTML
276− , _mmsg_inline_css :: Maybe Bool
262+ , _mmsg_inline_css :: Maybe Bool
277 -- ^ whether or not to automatically inline all CSS styles provided in the message HTML
263 -- ^ whether or not to automatically inline all CSS styles provided in the message HTML
278 -- - only for HTML documents less than 256KB in size
264 -- - only for HTML documents less than 256KB in size
279− , _mmsg_url_strip_qs :: Maybe Bool
265+ , _mmsg_url_strip_qs :: Maybe Bool
280 -- ^ whether or not to strip the query string from URLs when aggregating tracked URL data
266 -- ^ whether or not to strip the query string from URLs when aggregating tracked URL data
281− , _mmsg_preserve_recipients :: Maybe Bool
267+ , _mmsg_preserve_recipients :: Maybe Bool
282 -- ^ whether or not to expose all recipients in to "To" header for each email
268 -- ^ whether or not to expose all recipients in to "To" header for each email
283− , _mmsg_view_content_link :: Maybe Bool
269+ , _mmsg_view_content_link :: Maybe Bool
284 -- ^ set to false to remove content logging for sensitive emails
270 -- ^ set to false to remove content logging for sensitive emails
285− , _mmsg_bcc_address :: Maybe T.Text
271+ , _mmsg_bcc_address :: Maybe T.Text
286 -- ^ an optional address to receive an exact copy of each recipient's email
272 -- ^ an optional address to receive an exact copy of each recipient's email
287− , _mmsg_tracking_domain :: Maybe T.Text
273+ , _mmsg_tracking_domain :: Maybe T.Text
288 -- ^ a custom domain to use for tracking opens and clicks instead of mandrillapp.com
274 -- ^ a custom domain to use for tracking opens and clicks instead of mandrillapp.com
289− , _mmsg_signing_domain :: Maybe Bool
275+ , _mmsg_signing_domain :: Maybe Bool
290 -- ^ a custom domain to use for SPF/DKIM signing instead of mandrill
276 -- ^ a custom domain to use for SPF/DKIM signing instead of mandrill
291 -- (for "via" or "on behalf of" in email clients)
277 -- (for "via" or "on behalf of" in email clients)
292− , _mmsg_return_path_domain :: Maybe Bool
278+ , _mmsg_return_path_domain :: Maybe Bool
293 -- ^ a custom domain to use for the messages's return-path
279 -- ^ a custom domain to use for the messages's return-path
294− , _mmsg_merge :: Maybe Bool
280+ , _mmsg_merge :: Maybe Bool
295 -- ^ whether to evaluate merge tags in the message.
281 -- ^ whether to evaluate merge tags in the message.
296 -- Will automatically be set to true if either merge_vars
282 -- Will automatically be set to true if either merge_vars
297 -- or global_merge_vars are provided.
283 -- or global_merge_vars are provided.
298− , _mmsg_global_merge_vars :: [MergeVar]
284+ , _mmsg_global_merge_vars :: [MergeVar]
299 -- ^ global merge variables to use for all recipients. You can override these per recipient.
285 -- ^ global merge variables to use for all recipients. You can override these per recipient.
300− , _mmsg_merge_vars :: [MandrillMergeVars]
286+ , _mmsg_merge_vars :: [MandrillMergeVars]
301 -- ^ per-recipient merge variables, which override global merge variables with the same name.
287 -- ^ per-recipient merge variables, which override global merge variables with the same name.
302− , _mmsg_tags :: [MandrillTags]
288+ , _mmsg_tags :: [MandrillTags]
303 -- ^ an array of string to tag the message with. Stats are accumulated using tags,
289 -- ^ an array of string to tag the message with. Stats are accumulated using tags,
304 -- though we only store the first 100 we see, so this should not be unique
290 -- though we only store the first 100 we see, so this should not be unique
305 -- or change frequently. Tags should be 50 characters or less.
291 -- or change frequently. Tags should be 50 characters or less.
306 -- Any tags starting with an underscore are reserved for internal use
292 -- Any tags starting with an underscore are reserved for internal use
307 -- and will cause errors.
293 -- and will cause errors.
308− , _mmsg_subaccount :: Maybe T.Text
294+ , _mmsg_subaccount :: Maybe T.Text
309 -- ^ the unique id of a subaccount for this message
295 -- ^ the unique id of a subaccount for this message
310 -- - must already exist or will fail with an error
296 -- - must already exist or will fail with an error
311− , _mmsg_google_analytics_domains :: [T.Text]
297+ , _mmsg_google_analytics_domains :: [T.Text]
312 -- ^ an array of strings indicating for which any matching URLs
298 -- ^ an array of strings indicating for which any matching URLs
313 -- will automatically have Google Analytics parameters appended
299 -- will automatically have Google Analytics parameters appended
314 -- to their query string automatically.
300 -- to their query string automatically.
@@ -316,17 +302,17 @@ data MandrillMessage = MandrillMessage {
316 -- ^ optional string indicating the value to set for the utm_campaign
302 -- ^ optional string indicating the value to set for the utm_campaign
317 -- tracking parameter. If this isn't provided the email's from address
303 -- tracking parameter. If this isn't provided the email's from address
318 -- will be used instead.
304 -- will be used instead.
319− , _mmsg_metadata :: Object
305+ , _mmsg_metadata :: Object
320 -- ^ metadata an associative array of user metadata. Mandrill will store
306 -- ^ metadata an associative array of user metadata. Mandrill will store
321 -- this metadata and make it available for retrieval.
307 -- this metadata and make it available for retrieval.
322 -- In addition, you can select up to 10 metadata fields to index
308 -- In addition, you can select up to 10 metadata fields to index
323 -- and make searchable using the Mandrill search api.
309 -- and make searchable using the Mandrill search api.
324− , _mmsg_recipient_metadata :: [MandrillMetadata]
310+ , _mmsg_recipient_metadata :: [MandrillMetadata]
325 -- ^ Per-recipient metadata that will override the global values
311 -- ^ Per-recipient metadata that will override the global values
326 -- specified in the metadata parameter.
312 -- specified in the metadata parameter.
327− , _mmsg_attachments :: [MandrillWebContent]
313+ , _mmsg_attachments :: [MandrillWebContent]
328 -- ^ an array of supported attachments to add to the message
314 -- ^ an array of supported attachments to add to the message
329− , _mmsg_images :: [MandrillWebContent]
315+ , _mmsg_images :: [MandrillWebContent]
330 -- ^ an array of embedded images to add to the message
316 -- ^ an array of embedded images to add to the message
331 } deriving Show
317 } deriving Show