git.iko.soy/typeable/mandrill
on master help sign in
Introduce the `MandrillEmail` to prevent orphans.
444f7e2Alfredo Di Napoli
.gitignore+1
@@ -2,3 +2,4 @@ dist
2.cabal-sandbox
2.cabal-sandbox
3cabal.sandbox.config
3cabal.sandbox.config
4shell.nix
4shell.nix
5+.stack-work
.travis.yml+1
@@ -10,6 +10,7 @@ env:
10 - GHCVER=7.8.2 CABALVER=1.18
10 - GHCVER=7.8.2 CABALVER=1.18
11 - GHCVER=7.8.3 CABALVER=1.18
11 - GHCVER=7.8.3 CABALVER=1.18
12 - GHCVER=7.10.1 CABALVER=1.22
12 - GHCVER=7.10.1 CABALVER=1.22
13+ - GHCVER=7.10.2 CABALVER=1.22
13 - GHCVER=head CABALVER=1.20
14 - GHCVER=head CABALVER=1.20
14
15
15matrix:
16matrix:
mandrill.cabal+8−2
@@ -1,5 +1,5 @@
1name: mandrill
1name: mandrill
2−version: 0.2.2.1
2+version: 0.3.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
@@ -15,6 +15,9 @@ source-repository head
15 type: git
15 type: git
16 location: https://github.com/adinapoli/mandrill
16 location: https://github.com/adinapoli/mandrill
17
17
18+flag debug-th
19+ default: False
20+
18library
21library
19 exposed-modules:
22 exposed-modules:
20 Network.API.Mandrill
23 Network.API.Mandrill
@@ -28,7 +31,6 @@ library
28 other-modules:
31 other-modules:
29 Network.API.Mandrill.Utils
32 Network.API.Mandrill.Utils
30 Network.API.Mandrill.HTTP
33 Network.API.Mandrill.HTTP
31− Network.API.Mandrill.Orphans
32 -- other-extensions:
34 -- other-extensions:
33 build-depends:
35 build-depends:
34 base >=4.6 && < 5
36 base >=4.6 && < 5
@@ -51,6 +53,10 @@ library
51 src
53 src
52 default-language:
54 default-language:
53 Haskell2010
55 Haskell2010
56+
57+ if flag(debug-th)
58+ ghc-options: -ddump-splices -dth-dec-file
59+
54 ghc-options:
60 ghc-options:
55 -funbox-strict-fields
61 -funbox-strict-fields
56
62
src/Network/API/Mandrill.hs+1−1
@@ -62,7 +62,7 @@ emptyMessage f t = MandrillMessage {
62 _mmsg_html = mempty
62 _mmsg_html = mempty
63 , _mmsg_text = Nothing
63 , _mmsg_text = Nothing
64 , _mmsg_subject = T.empty
64 , _mmsg_subject = T.empty
65− , _mmsg_from_email = f
65+ , _mmsg_from_email = (MandrillEmail f)
66 , _mmsg_from_name = Nothing
66 , _mmsg_from_name = Nothing
67 , _mmsg_to = map newRecipient t
67 , _mmsg_to = map newRecipient t
68 , _mmsg_headers = JSON.Null
68 , _mmsg_headers = JSON.Null
src/Network/API/Mandrill/Orphans.hsdeleted−17
@@ -1,17 +0,0 @@
1−
2−module Network.API.Mandrill.Orphans where
3−
4−import Data.Aeson
5−import Data.Aeson.Types
6−import Text.Email.Validate
7−import qualified Data.Text.Encoding as TE
8−
9−
10−instance ToJSON EmailAddress where
11− toJSON = String . TE.decodeUtf8 . toByteString
12−
13−instance FromJSON EmailAddress where
14− parseJSON (String s) = case validate (TE.encodeUtf8 s) of
15− Left err -> fail err
16− Right v -> return v
17− parseJSON o = typeMismatch "Expecting a String for EmailAddress." o
src/Network/API/Mandrill/Types.hs+18−6
@@ -6,7 +6,6 @@
6module Network.API.Mandrill.Types where
6module Network.API.Mandrill.Types where
7
7
8import Network.API.Mandrill.Utils
8import Network.API.Mandrill.Utils
9−import Network.API.Mandrill.Orphans()
10import Test.QuickCheck
9import Test.QuickCheck
11import Text.Email.Validate
10import Text.Email.Validate
12import Data.Char
11import Data.Char
@@ -101,10 +100,23 @@ data MandrillRecipientTag = To | Cc | Bcc deriving Show
101deriveJSON defaultOptions { constructorTagModifier = map toLower } ''MandrillRecipientTag
100deriveJSON defaultOptions { constructorTagModifier = map toLower } ''MandrillRecipientTag
102
101
103
102
103+--------------------------------------------------------------------------------
104+newtype MandrillEmail = MandrillEmail EmailAddress deriving Show
105+
106+instance ToJSON MandrillEmail where
107+ toJSON (MandrillEmail e) = String . TL.decodeUtf8 . toByteString $ e
108+
109+instance FromJSON MandrillEmail where
110+ parseJSON (String s) = case validate (TL.encodeUtf8 s) of
111+ Left err -> fail err
112+ Right v -> return . MandrillEmail $ v
113+ parseJSON o = typeMismatch "Expecting a String for MandrillEmail." o
114+
115+
104--------------------------------------------------------------------------------
116--------------------------------------------------------------------------------
105-- | An array of recipient information.
117-- | An array of recipient information.
106data MandrillRecipient = MandrillRecipient {
118data MandrillRecipient = MandrillRecipient {
107− _mrec_email :: EmailAddress
119+ _mrec_email :: MandrillEmail
108 -- ^ The email address of the recipient
120 -- ^ The email address of the recipient
109 , _mrec_name :: Maybe T.Text
121 , _mrec_name :: Maybe T.Text
110 -- ^ The optional display name to use for the recipient
122 -- ^ The optional display name to use for the recipient
@@ -117,11 +129,11 @@ makeLenses ''MandrillRecipient
117deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillRecipient
129deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillRecipient
118
130
119newRecipient :: EmailAddress -> MandrillRecipient
131newRecipient :: EmailAddress -> MandrillRecipient
120−newRecipient email = MandrillRecipient email Nothing Nothing
132+newRecipient email = MandrillRecipient (MandrillEmail email) Nothing Nothing
121
133
122instance Arbitrary MandrillRecipient where
134instance Arbitrary MandrillRecipient where
123 arbitrary = pure MandrillRecipient {
135 arbitrary = pure MandrillRecipient {
124− _mrec_email = fromJust (emailAddress "test@example.com")
136+ _mrec_email = MandrillEmail $ fromJust (emailAddress "test@example.com")
125 , _mrec_name = Nothing
137 , _mrec_name = Nothing
126 , _mrec_type = Nothing
138 , _mrec_type = Nothing
127 }
139 }
@@ -218,7 +230,7 @@ data MandrillMessage = MandrillMessage {
218 -- ^ Optional full text content to be sent
230 -- ^ Optional full text content to be sent
219 , _mmsg_subject :: !T.Text
231 , _mmsg_subject :: !T.Text
220 -- ^ The message subject
232 -- ^ The message subject
221− , _mmsg_from_email :: EmailAddress
233+ , _mmsg_from_email :: MandrillEmail
222 -- ^ The sender email address
234 -- ^ The sender email address
223 , _mmsg_from_name :: Maybe T.Text
235 , _mmsg_from_name :: Maybe T.Text
224 -- ^ Optional from name to be used
236 -- ^ Optional from name to be used
@@ -301,7 +313,7 @@ instance Arbitrary MandrillMessage where
301 arbitrary = MandrillMessage <$> arbitrary
313 arbitrary = MandrillMessage <$> arbitrary
302 <*> pure Nothing
314 <*> pure Nothing
303 <*> pure "Test Subject"
315 <*> pure "Test Subject"
304− <*> pure (fromJust $ emailAddress "sender@example.com")
316+ <*> pure (MandrillEmail . fromJust $ emailAddress "sender@example.com")
305 <*> pure Nothing
317 <*> pure Nothing
306 <*> resize 2 arbitrary
318 <*> resize 2 arbitrary
307 <*> pure emptyObject
319 <*> pure emptyObject
stack.yamlnew file+5
@@ -0,0 +1,5 @@
1+flags: {}
2+packages:
3+- '.'
4+extra-deps: []
5+resolver: lts-2.19