git.iko.soy/typeable/mandrill
on master help sign in
Support for messages
7bd053eAlfredo Di Napoli
mandrill.cabal+1−1
@@ -30,7 +30,7 @@ library
30 base >=4.6 && < 5
30 base >=4.6 && < 5
31 , containers >= 0.5.0.0
31 , containers >= 0.5.0.0
32 , bytestring >= 0.9.0
32 , bytestring >= 0.9.0
33− , bytestring-base64 > 1.0.0.1
33+ , base64-bytestring >= 1.0.0.1
34 , text >= 1.0.0.0 && < 1.2
34 , text >= 1.0.0.0 && < 1.2
35 , wreq >= 0.1.0.1
35 , wreq >= 0.1.0.1
36 , aeson >= 0.7.0.3 && < 0.8
36 , aeson >= 0.7.0.3 && < 0.8
src/Network/API/Mandrill/Types.hs+13−13
@@ -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
20−import Control.Monad
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
132
132
133
133
134--------------------------------------------------------------------------------
134--------------------------------------------------------------------------------
135−type MandrillHeader = Map T.Text T.Text
135+type MandrillHeaders = Value
136
136
137
137
138--------------------------------------------------------------------------------
138--------------------------------------------------------------------------------
139−type MandrillVars = Map T.Text T.Text
139+type MandrillVars = Value
140
140
141
141
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
156
156
157makeLenses ''MandrillMetadata
157makeLenses ''MandrillMetadata
158deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMetadata
158deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMetadata
159
159
160
160
161−newtype Base64ByteString = B64BS !B.ByteString
161+newtype Base64ByteString = B64BS B.ByteString deriving Show
162
162
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
165
165
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
171
171
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 []
test/Tests.hs+3−1
@@ -18,7 +18,9 @@ isRight _ = True
18#endif
18#endif
19
19
20testMessagesSend :: Assertion
20testMessagesSend :: Assertion
21+testMessagesSend =
21−testMessagesSend = assertBool "send.json: Parsing failed!" (isRight parsePayload)
22+ assertBool ("send.json: Parsing failed! " ++ show parsePayload)
23+ (isRight parsePayload)
22 where
24 where
23 parsePayload :: Either String MessagesSendRq
25 parsePayload :: Either String MessagesSendRq
24 parsePayload = eitherDecodeStrict . C8.pack $ sendData
26 parsePayload = eitherDecodeStrict . C8.pack $ sendData