git.iko.soy/typeable/mandrill
on master help sign in
Merge pull request #21 from adinapoli/issue-20
27f654dAlfredo Di Napoli
README.md+8
@@ -6,6 +6,14 @@
6This module implement a low-level, 1:1 mapping API to
6This module implement a low-level, 1:1 mapping API to
7the [Mandrill](http://mandrillapp.com) transactional email service.
7the [Mandrill](http://mandrillapp.com) transactional email service.
8
8
9+# Changelog
10+
11+## Version 0.4.0.0
12+
13+* Modified the `Base64ByteString` type to accept another constructor. This
14+ allows the user to pass already-encoded Base64 strings which might be coming
15+ upstream.
16+
9# Example
17# Example
10
18
11This package was built with pragmatism and reuse in mind. This means
19This package was built with pragmatism and reuse in mind. This means
mandrill.cabal+1−1
@@ -1,5 +1,5 @@
1name: mandrill
1name: mandrill
2−version: 0.3.0.0
2+version: 0.4.0.0
3synopsis: Library for interfacing with the Mandrill JSON API
3synopsis: Library for interfacing with the Mandrill JSON API
4description: Pure Haskell client for the Mandrill JSON API
4description: Pure Haskell client for the Mandrill JSON API
5license: MIT
5license: MIT
src/Network/API/Mandrill/Types.hs+9−5
@@ -196,15 +196,19 @@ makeLenses ''MandrillMetadata
196deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMetadata
196deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMetadata
197
197
198
198
199−newtype Base64ByteString = B64BS B.ByteString deriving Show
199+data Base64ByteString =
200+ EncodedB64BS B.ByteString
201+ -- ^ An already-encoded Base64 ByteString.
202+ | PlainBS B.ByteString
203+ -- ^ A plain Base64 ByteString which requires encoding.
204+ deriving Show
200
205
201instance ToJSON Base64ByteString where
206instance ToJSON Base64ByteString where
202− toJSON (B64BS bs) = String . TL.decodeUtf8 . Base64.encode $ bs
207+ toJSON (PlainBS bs) = String . TL.decodeUtf8 . Base64.encode $ bs
208+ toJSON (EncodedB64BS bs) = String . TL.decodeUtf8 $ bs
203
209
204instance FromJSON Base64ByteString where
210instance FromJSON Base64ByteString where
205− parseJSON (String v) = case Base64.decode (TL.encodeUtf8 v) of
211+ parseJSON (String v) = pure $ EncodedB64BS (TL.encodeUtf8 v)
206− Left err -> fail err
207− Right rs -> return $ B64BS rs
208 parseJSON rest = typeMismatch "Base64ByteString must be a String." rest
212 parseJSON rest = typeMismatch "Base64ByteString must be a String." rest
209
213
210--------------------------------------------------------------------------------
214--------------------------------------------------------------------------------