@@ -15,9 +15,9 @@ import qualified Data.Map as Map
1515import qualified Data.ByteString as B
1616import qualified Data.ByteString.Base64 as Base64
1717import qualified Data.Text as T
18+import qualified Data.Text.Encoding as TL
1819import qualified Data.Text.Lazy as TL
1920import Control.Lens
20−import Control.Monad
2121import Data.Monoid
2222import Data.Aeson
2323import Data.Aeson.Types
@@ -132,11 +132,11 @@ type MandrillTags = T.Text
132132
133133
134134--------------------------------------------------------------------------------
135−type MandrillHeader = Map T.Text T.Text
135+type MandrillHeaders = Value
136136
137137
138138--------------------------------------------------------------------------------
139−type MandrillVars = Map T.Text T.Text
139+type MandrillVars = Value
140140
141141
142142--------------------------------------------------------------------------------
@@ -151,22 +151,22 @@ deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMergeVars
151151--------------------------------------------------------------------------------
152152data MandrillMetadata = MandrillMetadata {
153153 _mmdt_rcpt :: !T.Text
154− , _mmdt_values :: [MandrillVars]
154+ , _mmdt_values :: MandrillVars
155155 } deriving Show
156156
157157makeLenses ''MandrillMetadata
158158deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMetadata
159159
160160
161−newtype Base64ByteString = B64BS !B.ByteString
161+newtype Base64ByteString = B64BS B.ByteString deriving Show
162162
163163instance ToJSON Base64ByteString where
164− toJSON (B64BS bs) = Base64.encode bs
164+ toJSON (B64BS bs) = String . TL.decodeUtf8 . Base64.encode $ bs
165165
166166instance FromJSON Base64ByteString where
167− parseJSON (String v) = case Base64.decode v of
168− Left err = fail err
169− Right rs = B64BS rs
167+ parseJSON (String v) = case Base64.decode (TL.encodeUtf8 v) of
168+ Left err -> fail err
169+ Right rs -> return $ B64BS rs
170170 parseJSON rest = typeMismatch "Base64ByteString must be a String." rest
171171
172172--------------------------------------------------------------------------------
@@ -197,7 +197,7 @@ data MandrillMessage = MandrillMessage {
197197 -- ^ Optional from name to be used
198198 , _mmsg_to :: [MandrillRecipient]
199199 -- ^ A list of recipient information
200− , _mmsg_headers :: [MandrillHeader]
200+ , _mmsg_headers :: MandrillHeaders
201201 -- ^ optional extra headers to add to the message (most headers are allowed)
202202 , _mmsg_important :: Maybe Bool
203203 -- ^ whether or not this message is important, and should be delivered ahead
@@ -253,7 +253,7 @@ data MandrillMessage = MandrillMessage {
253253 -- ^ optional string indicating the value to set for the utm_campaign
254254 -- tracking parameter. If this isn't provided the email's from address
255255 -- will be used instead.
256− , _mmsg_metadata :: [MandrillVars]
256+ , _mmsg_metadata :: MandrillVars
257257 -- ^ metadata an associative array of user metadata. Mandrill will store
258258 -- this metadata and make it available for retrieval.
259259 -- In addition, you can select up to 10 metadata fields to index
@@ -277,7 +277,7 @@ instance Arbitrary MandrillMessage where
277277 <*> pure "sender@example.com"
278278 <*> pure Nothing
279279 <*> resize 2 arbitrary
280− <*> pure []
280+ <*> pure emptyObject
281281 <*> pure Nothing
282282 <*> pure Nothing
283283 <*> pure Nothing
@@ -298,7 +298,7 @@ instance Arbitrary MandrillMessage where
298298 <*> pure Nothing
299299 <*> pure []
300300 <*> pure Nothing
301− <*> pure []
301+ <*> pure emptyObject
302302 <*> pure []
303303 <*> pure []
304304 <*> pure []