@@ -15,9 +15,9 @@ import qualified Data.Map as Map
15import qualified Data.ByteString as B
15import qualified Data.ByteString as B
16import qualified Data.ByteString.Base64 as Base64
16import qualified Data.ByteString.Base64 as Base64
17import qualified Data.Text as T
17import qualified Data.Text as T
18+import qualified Data.Text.Encoding as TL
18import qualified Data.Text.Lazy as TL
19import qualified Data.Text.Lazy as TL
19import Control.Lens
20import Control.Lens
21import Data.Monoid
21import Data.Monoid
22import Data.Aeson
22import Data.Aeson
23import Data.Aeson.Types
23import Data.Aeson.Types
@@ -132,11 +132,11 @@ type MandrillTags = T.Text
134--------------------------------------------------------------------------------
134--------------------------------------------------------------------------------
135−type MandrillHeader = Map T.Text T.Text
135+type MandrillHeaders = Value
138--------------------------------------------------------------------------------
138--------------------------------------------------------------------------------
139−type MandrillVars = Map T.Text T.Text
139+type MandrillVars = Value
142--------------------------------------------------------------------------------
142--------------------------------------------------------------------------------
@@ -151,22 +151,22 @@ deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMergeVars
151--------------------------------------------------------------------------------
151--------------------------------------------------------------------------------
152data MandrillMetadata = MandrillMetadata {
152data MandrillMetadata = MandrillMetadata {
153 _mmdt_rcpt :: !T.Text
153 _mmdt_rcpt :: !T.Text
154− , _mmdt_values :: [MandrillVars]
154+ , _mmdt_values :: MandrillVars
155 } deriving Show
155 } deriving Show
157makeLenses ''MandrillMetadata
157makeLenses ''MandrillMetadata
158deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMetadata
158deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMetadata
161−newtype Base64ByteString = B64BS !B.ByteString
161+newtype Base64ByteString = B64BS B.ByteString deriving Show
163instance ToJSON Base64ByteString where
163instance ToJSON Base64ByteString where
164− toJSON (B64BS bs) = Base64.encode bs
164+ toJSON (B64BS bs) = String . TL.decodeUtf8 . Base64.encode $ bs
166instance FromJSON Base64ByteString where
166instance FromJSON Base64ByteString where
167− parseJSON (String v) = case Base64.decode v of
167+ parseJSON (String v) = case Base64.decode (TL.encodeUtf8 v) of
168− Left err = fail err
168+ Left err -> fail err
169− Right rs = B64BS rs
169+ Right rs -> return $ B64BS rs
170 parseJSON rest = typeMismatch "Base64ByteString must be a String." rest
170 parseJSON rest = typeMismatch "Base64ByteString must be a String." rest
172--------------------------------------------------------------------------------
172--------------------------------------------------------------------------------
@@ -197,7 +197,7 @@ data MandrillMessage = MandrillMessage {
197 -- ^ Optional from name to be used
197 -- ^ Optional from name to be used
198 , _mmsg_to :: [MandrillRecipient]
198 , _mmsg_to :: [MandrillRecipient]
199 -- ^ A list of recipient information
199 -- ^ A list of recipient information
200− , _mmsg_headers :: [MandrillHeader]
200+ , _mmsg_headers :: MandrillHeaders
201 -- ^ optional extra headers to add to the message (most headers are allowed)
201 -- ^ optional extra headers to add to the message (most headers are allowed)
202 , _mmsg_important :: Maybe Bool
202 , _mmsg_important :: Maybe Bool
203 -- ^ whether or not this message is important, and should be delivered ahead
203 -- ^ whether or not this message is important, and should be delivered ahead
@@ -253,7 +253,7 @@ data MandrillMessage = MandrillMessage {
253 -- ^ optional string indicating the value to set for the utm_campaign
253 -- ^ optional string indicating the value to set for the utm_campaign
254 -- tracking parameter. If this isn't provided the email's from address
254 -- tracking parameter. If this isn't provided the email's from address
255 -- will be used instead.
255 -- will be used instead.
256− , _mmsg_metadata :: [MandrillVars]
256+ , _mmsg_metadata :: MandrillVars
257 -- ^ metadata an associative array of user metadata. Mandrill will store
257 -- ^ metadata an associative array of user metadata. Mandrill will store
258 -- this metadata and make it available for retrieval.
258 -- this metadata and make it available for retrieval.
259 -- In addition, you can select up to 10 metadata fields to index
259 -- In addition, you can select up to 10 metadata fields to index
@@ -277,7 +277,7 @@ instance Arbitrary MandrillMessage where
277 <*> pure "sender@example.com"
277 <*> pure "sender@example.com"
278 <*> pure Nothing
278 <*> pure Nothing
279 <*> resize 2 arbitrary
279 <*> resize 2 arbitrary
280− <*> pure []
280+ <*> pure emptyObject
281 <*> pure Nothing
281 <*> pure Nothing
282 <*> pure Nothing
282 <*> pure Nothing
283 <*> pure Nothing
283 <*> pure Nothing
@@ -298,7 +298,7 @@ instance Arbitrary MandrillMessage where
298 <*> pure Nothing
298 <*> pure Nothing
299 <*> pure []
299 <*> pure []
300 <*> pure Nothing
300 <*> pure Nothing
301− <*> pure []
301+ <*> pure emptyObject
302 <*> pure []
302 <*> pure []
303 <*> pure []
303 <*> pure []
304 <*> pure []
304 <*> pure []