git.iko.soy/typeable/mandrill
on master help sign in
add inbound calls to mandrill
22f751aMark Wotton
mandrill.cabal+1
@@ -25,6 +25,7 @@ library
25 Network.API.Mandrill.Users.Types
25 Network.API.Mandrill.Users.Types
26 Network.API.Mandrill.Messages
26 Network.API.Mandrill.Messages
27 Network.API.Mandrill.Messages.Types
27 Network.API.Mandrill.Messages.Types
28+ Network.API.Mandrill.Inbound
28 other-modules:
29 other-modules:
29 Network.API.Mandrill.Utils
30 Network.API.Mandrill.Utils
30 Network.API.Mandrill.HTTP
31 Network.API.Mandrill.HTTP
src/Network/API/Mandrill.hs+14−14
@@ -20,19 +20,19 @@ module Network.API.Mandrill (
20 -- $exampleusage
20 -- $exampleusage
21 ) where
21 ) where
22
22
23+import Control.Lens
23−import Control.Monad.Reader
24+import Control.Monad.Reader
24−import Control.Lens
25+import qualified Data.Aeson as JSON
26+import qualified Data.HashMap.Strict as H
27+import Data.Monoid
28+import qualified Data.Text as T
25−import Data.Time
29+import Data.Time
30+import Network.API.Mandrill.Messages as M
31+import Network.API.Mandrill.Messages.Types as M
32+import Network.API.Mandrill.Trans as M
33+import Network.API.Mandrill.Types as M
26−import Text.Blaze.Html
34+import Text.Blaze.Html
27−import Network.API.Mandrill.Types as M
28−import Network.API.Mandrill.Messages as M
29−import Network.API.Mandrill.Messages.Types as M
30−import Network.API.Mandrill.Trans as M
31−import Data.Monoid
32−import Text.Email.Validate
35+import Text.Email.Validate
33−import qualified Data.Text as T
34−import qualified Data.Aeson as JSON
35−import qualified Data.HashMap.Strict as H
36
36
37{- $exampleusage
37{- $exampleusage
38
38
@@ -144,7 +144,7 @@ newTextMessage f t subj txt = let body = unsafeMkMandrillHtml txt in
144-- 'MandrillMessage' and this function will send an email inside a
144-- 'MandrillMessage' and this function will send an email inside a
145-- 'MandrillT' transformer. You are not forced to use the 'MandrillT' context
145-- 'MandrillT' transformer. You are not forced to use the 'MandrillT' context
146-- though. Have a look at "Network.API.Mandrill.Messages" for an IO-based,
146-- though. Have a look at "Network.API.Mandrill.Messages" for an IO-based,
147−-- low lever function for sending email.
147+-- low level function for sending email.
148sendEmail :: MonadIO m
148sendEmail :: MonadIO m
149 => MandrillMessage
149 => MandrillMessage
150 -> MandrillT m (MandrillResponse [MessagesResponse])
150 -> MandrillT m (MandrillResponse [MessagesResponse])
src/Network/API/Mandrill/HTTP.hs+9−9
@@ -1,15 +1,15 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2module Network.API.Mandrill.HTTP where
2module Network.API.Mandrill.HTTP where
3
3
4−import Network.API.Mandrill.Settings
4+import Control.Applicative
5−import Network.API.Mandrill.Types
5+import Data.Aeson
6+import Data.Monoid
6−import qualified Data.Text as T
7+import qualified Data.Text as T
7−import Data.Monoid
8+import Network.API.Mandrill.Settings
8−import Data.Aeson
9−import Control.Applicative
10−import Network.HTTP.Types
9+import Network.API.Mandrill.Types
11−import Network.HTTP.Client
10+import Network.HTTP.Client
12−import Network.HTTP.Client.TLS
11+import Network.HTTP.Client.TLS
12+import Network.HTTP.Types
13
13
14toMandrillResponse :: (MandrillEndpoint ep, FromJSON a, ToJSON rq)
14toMandrillResponse :: (MandrillEndpoint ep, FromJSON a, ToJSON rq)
15 => ep
15 => ep
src/Network/API/Mandrill/Inbound.hsnew file+82
@@ -0,0 +1,82 @@
1+{-# LANGUAGE TemplateHaskell #-}
2+module Network.API.Mandrill.Inbound where
3+import Control.Lens
4+import Data.Aeson (FromJSON, ToJSON, parseJSON,
5+ toJSON)
6+import Data.Aeson.TH (defaultOptions, deriveJSON)
7+import Data.Aeson.Types (fieldLabelModifier)
8+import Data.Text (Text)
9+import Network.API.Mandrill.HTTP (toMandrillResponse)
10+import Network.API.Mandrill.Settings
11+import Network.API.Mandrill.Types
12+import Network.HTTP.Client (Manager)
13+
14+data DomainAddRq =
15+ DomainAddRq
16+ { _darq_key :: MandrillKey
17+ , _darq_domain :: Text
18+ } deriving Show
19+
20+makeLenses ''DomainAddRq
21+deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''DomainAddRq
22+
23+data DomainAddResponse =
24+ DomainAddResponse
25+ { _dares_domain :: Text
26+ , _dares_created_at :: MandrillDate
27+ , _dares_valid_mx :: Bool
28+ } deriving Show
29+
30+
31+
32+makeLenses ''DomainAddResponse
33+deriveJSON defaultOptions { fieldLabelModifier = drop 7 } ''DomainAddResponse
34+
35+data RouteAddResponse =
36+ RouteAddResponse
37+ { _rares_id :: Text
38+ , _rares_pattern :: Text
39+ , _rares_url :: Text
40+ } deriving Show
41+
42+
43+
44+makeLenses ''RouteAddResponse
45+deriveJSON defaultOptions { fieldLabelModifier = drop 7 } ''RouteAddResponse
46+
47+data RouteAddRq =
48+ RouteAddRq
49+ { _rarq_key :: Text
50+ , _rarq_domain :: Text
51+ , _rarq_pattern :: Text
52+ , _rarq_url :: Text
53+ } deriving Show
54+
55+makeLenses ''RouteAddRq
56+deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''RouteAddRq
57+
58+
59+
60+
61+
62+addDomain :: MandrillKey
63+ -- ^ The API key
64+ -> Text
65+ -- ^ The domain to add
66+ -> Maybe Manager
67+ -> IO (MandrillResponse DomainAddResponse)
68+addDomain k dom = toMandrillResponse DomainsAdd (DomainAddRq k dom)
69+
70+
71+
72+addRoute :: MandrillKey
73+ -- ^ The API key
74+ -> Text
75+ -- ^ The domain to add
76+ -> Text
77+ -- ^ the pattern including wildcards
78+ -> Text
79+ -- ^ URL to forward to
80+ -> Maybe Manager
81+ -> IO (MandrillResponse RouteAddResponse)
82+addRoute k dom pattern forward = toMandrillResponse RoutesAdd (RouteAddRq k dom pattern forward)
src/Network/API/Mandrill/Messages.hs+4−4
@@ -1,13 +1,13 @@
1
1
2module Network.API.Mandrill.Messages where
2module Network.API.Mandrill.Messages where
3
3
4+import qualified Data.Text as T
5+import Data.Time
4−import Network.API.Mandrill.Types
6+import Network.API.Mandrill.HTTP
5import Network.API.Mandrill.Messages.Types
7import Network.API.Mandrill.Messages.Types
6import Network.API.Mandrill.Settings
8import Network.API.Mandrill.Settings
7−import Network.API.Mandrill.HTTP
9+import Network.API.Mandrill.Types
8import Network.HTTP.Client
10import Network.HTTP.Client
9−import Data.Time
10−import qualified Data.Text as T
11
11
12--------------------------------------------------------------------------------
12--------------------------------------------------------------------------------
13-- | Send a new transactional message through Mandrill
13-- | Send a new transactional message through Mandrill
src/Network/API/Mandrill/Settings.hs+14−7
@@ -15,16 +15,23 @@ data MandrillCalls =
15 -- Messages API
15 -- Messages API
16 | MessagesSend
16 | MessagesSend
17 | MessagesSendTemplate
17 | MessagesSendTemplate
18− | MessagesSearch deriving Show
18+ | MessagesSearch
19+ -- Inbound API
20+ | RoutesAdd
21+ | DomainsAdd
22+
23+ deriving Show
19
24
20class MandrillEndpoint ep where
25class MandrillEndpoint ep where
21 toUrl :: ep -> T.Text
26 toUrl :: ep -> T.Text
22
27
23instance MandrillEndpoint MandrillCalls where
28instance MandrillEndpoint MandrillCalls where
24− toUrl UsersInfo = "users/info.json"
29+ toUrl UsersInfo = "users/info.json"
25− toUrl UsersPing = "users/ping.json"
30+ toUrl UsersPing = "users/ping.json"
26− toUrl UsersPing2 = "users/ping2.json"
31+ toUrl UsersPing2 = "users/ping2.json"
27− toUrl UsersSenders = "users/senders.json"
32+ toUrl UsersSenders = "users/senders.json"
28− toUrl MessagesSend = "messages/send.json"
33+ toUrl MessagesSend = "messages/send.json"
29 toUrl MessagesSendTemplate = "messages/send-template.json"
34 toUrl MessagesSendTemplate = "messages/send-template.json"
30− toUrl MessagesSearch = "messages/search.json"
35+ toUrl MessagesSearch = "messages/search.json"
36+ toUrl DomainsAdd = "inbound/add-domain.json"
37+ toUrl RoutesAdd = "inbound/add-route.json"
src/Network/API/Mandrill/Types.hs+57−57
@@ -1,34 +1,34 @@
1−{-# LANGUAGE TemplateHaskell #-}
1+{-# LANGUAGE CPP #-}
2−{-# LANGUAGE CPP #-}
2+{-# LANGUAGE OverloadedStrings #-}
3−{-# LANGUAGE RankNTypes #-}
3+{-# LANGUAGE RankNTypes #-}
4{-# LANGUAGE ScopedTypeVariables #-}
4{-# LANGUAGE ScopedTypeVariables #-}
5−{-# LANGUAGE OverloadedStrings #-}
5+{-# LANGUAGE TemplateHaskell #-}
6module Network.API.Mandrill.Types where
6module Network.API.Mandrill.Types where
7
7
8−import Network.API.Mandrill.Utils
8+import Control.Applicative
9−import Test.QuickCheck
10−import Text.Email.Validate
11import Data.Char
9import Data.Char
12import Data.Maybe
10import Data.Maybe
13import Data.Time
11import Data.Time
14−import Control.Applicative
12+import Network.API.Mandrill.Utils
13+import Test.QuickCheck
14+import Text.Email.Validate
15#if MIN_VERSION_time(1,5,0)
15#if MIN_VERSION_time(1,5,0)
16−import Data.Time.Format (TimeLocale, defaultTimeLocale)
16+import Data.Time.Format (TimeLocale, defaultTimeLocale)
17#else
17#else
18−import System.Locale (TimeLocale, defaultTimeLocale)
18+import System.Locale (TimeLocale, defaultTimeLocale)
19#endif
19#endif
20−import qualified Data.ByteString as B
21−import qualified Data.ByteString.Base64 as Base64
22−import qualified Data.HashMap.Strict as H
23−import qualified Data.Text as T
24−import qualified Data.Text.Encoding as TL
25−import qualified Data.Text.Lazy as TL
26import Control.Lens
20import Control.Lens
27−import Data.Monoid
28import Data.Aeson
21import Data.Aeson
29−import Data.Aeson.Types
30import Data.Aeson.TH
22import Data.Aeson.TH
23+import Data.Aeson.Types
24+import qualified Data.ByteString as B
25+import qualified Data.ByteString.Base64 as Base64
26+import qualified Data.HashMap.Strict as H
27+import Data.Monoid
28+import qualified Data.Text as T
29+import qualified Data.Text.Encoding as TL
30+import qualified Data.Text.Lazy as TL
31−import qualified Text.Blaze.Html as Blaze
31+import qualified Text.Blaze.Html as Blaze
32import qualified Text.Blaze.Html.Renderer.Text as Blaze
32import qualified Text.Blaze.Html.Renderer.Text as Blaze
33
33
34
34
@@ -41,9 +41,9 @@ timeParse = parseTime
41
41
42--------------------------------------------------------------------------------
42--------------------------------------------------------------------------------
43data MandrillError = MandrillError {
43data MandrillError = MandrillError {
44− _merr_status :: !T.Text
44+ _merr_status :: !T.Text
45− , _merr_code :: !Int
45+ , _merr_code :: !Int
46− , _merr_name :: !T.Text
46+ , _merr_name :: !T.Text
47 , _merr_message :: !T.Text
47 , _merr_message :: !T.Text
48 } deriving Show
48 } deriving Show
49
49
@@ -119,9 +119,9 @@ instance FromJSON MandrillEmail where
119data MandrillRecipient = MandrillRecipient {
119data MandrillRecipient = MandrillRecipient {
120 _mrec_email :: MandrillEmail
120 _mrec_email :: MandrillEmail
121 -- ^ The email address of the recipient
121 -- ^ The email address of the recipient
122− , _mrec_name :: Maybe T.Text
122+ , _mrec_name :: Maybe T.Text
123 -- ^ The optional display name to use for the recipient
123 -- ^ The optional display name to use for the recipient
124− , _mrec_type :: Maybe MandrillRecipientTag
124+ , _mrec_type :: Maybe MandrillRecipientTag
125 -- ^ The header type to use for the recipient.
125 -- ^ The header type to use for the recipient.
126 -- defaults to "to" if not provided
126 -- defaults to "to" if not provided
127 } deriving Show
127 } deriving Show
@@ -196,7 +196,7 @@ deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMergeVars
196
196
197--------------------------------------------------------------------------------
197--------------------------------------------------------------------------------
198data MandrillMetadata = MandrillMetadata {
198data MandrillMetadata = MandrillMetadata {
199− _mmdt_rcpt :: !T.Text
199+ _mmdt_rcpt :: !T.Text
200 , _mmdt_values :: Object
200 , _mmdt_values :: Object
201 } deriving Show
201 } deriving Show
202
202
@@ -221,8 +221,8 @@ instance FromJSON Base64ByteString where
221
221
222--------------------------------------------------------------------------------
222--------------------------------------------------------------------------------
223data MandrillWebContent = MandrillWebContent {
223data MandrillWebContent = MandrillWebContent {
224− _mwct_type :: !T.Text
224+ _mwct_type :: !T.Text
225− , _mwct_name :: !T.Text
225+ , _mwct_name :: !T.Text
226 -- ^ [for images] the Content ID of the image
226 -- ^ [for images] the Content ID of the image
227 -- - use <img src="cid:THIS_VALUE"> to reference the image
227 -- - use <img src="cid:THIS_VALUE"> to reference the image
228 -- in your HTML content
228 -- in your HTML content
@@ -235,67 +235,67 @@ deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillWebContent
235--------------------------------------------------------------------------------
235--------------------------------------------------------------------------------
236-- | The information on the message to send
236-- | The information on the message to send
237data MandrillMessage = MandrillMessage {
237data MandrillMessage = MandrillMessage {
238− _mmsg_html :: MandrillHtml
238+ _mmsg_html :: MandrillHtml
239 -- ^ The full HTML content to be sent
239 -- ^ The full HTML content to be sent
240− , _mmsg_text :: Maybe T.Text
240+ , _mmsg_text :: Maybe T.Text
241 -- ^ Optional full text content to be sent
241 -- ^ Optional full text content to be sent
242− , _mmsg_subject :: !T.Text
242+ , _mmsg_subject :: !T.Text
243 -- ^ The message subject
243 -- ^ The message subject
244− , _mmsg_from_email :: MandrillEmail
244+ , _mmsg_from_email :: MandrillEmail
245 -- ^ The sender email address
245 -- ^ The sender email address
246− , _mmsg_from_name :: Maybe T.Text
246+ , _mmsg_from_name :: Maybe T.Text
247 -- ^ Optional from name to be used
247 -- ^ Optional from name to be used
248− , _mmsg_to :: [MandrillRecipient]
248+ , _mmsg_to :: [MandrillRecipient]
249 -- ^ A list of recipient information
249 -- ^ A list of recipient information
250− , _mmsg_headers :: MandrillHeaders
250+ , _mmsg_headers :: MandrillHeaders
251 -- ^ optional extra headers to add to the message (most headers are allowed)
251 -- ^ optional extra headers to add to the message (most headers are allowed)
252− , _mmsg_important :: Maybe Bool
252+ , _mmsg_important :: Maybe Bool
253 -- ^ whether or not this message is important, and should be delivered ahead
253 -- ^ whether or not this message is important, and should be delivered ahead
254 -- of non-important messages
254 -- of non-important messages
255− , _mmsg_track_opens :: Maybe Bool
255+ , _mmsg_track_opens :: Maybe Bool
256 -- ^ whether or not to turn on open tracking for the message
256 -- ^ whether or not to turn on open tracking for the message
257− , _mmsg_track_clicks :: Maybe Bool
257+ , _mmsg_track_clicks :: Maybe Bool
258 -- ^ whether or not to turn on click tracking for the message
258 -- ^ whether or not to turn on click tracking for the message
259− , _mmsg_auto_text :: Maybe Bool
259+ , _mmsg_auto_text :: Maybe Bool
260 -- ^ whether or not to automatically generate a text part for messages that are not given text
260 -- ^ whether or not to automatically generate a text part for messages that are not given text
261− , _mmsg_auto_html :: Maybe Bool
261+ , _mmsg_auto_html :: Maybe Bool
262 -- ^ whether or not to automatically generate an HTML part for messages that are not given HTML
262 -- ^ whether or not to automatically generate an HTML part for messages that are not given HTML
263− , _mmsg_inline_css :: Maybe Bool
263+ , _mmsg_inline_css :: Maybe Bool
264 -- ^ whether or not to automatically inline all CSS styles provided in the message HTML
264 -- ^ whether or not to automatically inline all CSS styles provided in the message HTML
265 -- - only for HTML documents less than 256KB in size
265 -- - only for HTML documents less than 256KB in size
266− , _mmsg_url_strip_qs :: Maybe Bool
266+ , _mmsg_url_strip_qs :: Maybe Bool
267 -- ^ whether or not to strip the query string from URLs when aggregating tracked URL data
267 -- ^ whether or not to strip the query string from URLs when aggregating tracked URL data
268− , _mmsg_preserve_recipients :: Maybe Bool
268+ , _mmsg_preserve_recipients :: Maybe Bool
269 -- ^ whether or not to expose all recipients in to "To" header for each email
269 -- ^ whether or not to expose all recipients in to "To" header for each email
270− , _mmsg_view_content_link :: Maybe Bool
270+ , _mmsg_view_content_link :: Maybe Bool
271 -- ^ set to false to remove content logging for sensitive emails
271 -- ^ set to false to remove content logging for sensitive emails
272− , _mmsg_bcc_address :: Maybe T.Text
272+ , _mmsg_bcc_address :: Maybe T.Text
273 -- ^ an optional address to receive an exact copy of each recipient's email
273 -- ^ an optional address to receive an exact copy of each recipient's email
274− , _mmsg_tracking_domain :: Maybe T.Text
274+ , _mmsg_tracking_domain :: Maybe T.Text
275 -- ^ a custom domain to use for tracking opens and clicks instead of mandrillapp.com
275 -- ^ a custom domain to use for tracking opens and clicks instead of mandrillapp.com
276− , _mmsg_signing_domain :: Maybe Bool
276+ , _mmsg_signing_domain :: Maybe Bool
277 -- ^ a custom domain to use for SPF/DKIM signing instead of mandrill
277 -- ^ a custom domain to use for SPF/DKIM signing instead of mandrill
278 -- (for "via" or "on behalf of" in email clients)
278 -- (for "via" or "on behalf of" in email clients)
279− , _mmsg_return_path_domain :: Maybe Bool
279+ , _mmsg_return_path_domain :: Maybe Bool
280 -- ^ a custom domain to use for the messages's return-path
280 -- ^ a custom domain to use for the messages's return-path
281− , _mmsg_merge :: Maybe Bool
281+ , _mmsg_merge :: Maybe Bool
282 -- ^ whether to evaluate merge tags in the message.
282 -- ^ whether to evaluate merge tags in the message.
283 -- Will automatically be set to true if either merge_vars
283 -- Will automatically be set to true if either merge_vars
284 -- or global_merge_vars are provided.
284 -- or global_merge_vars are provided.
285− , _mmsg_global_merge_vars :: [MergeVar]
285+ , _mmsg_global_merge_vars :: [MergeVar]
286 -- ^ global merge variables to use for all recipients. You can override these per recipient.
286 -- ^ global merge variables to use for all recipients. You can override these per recipient.
287− , _mmsg_merge_vars :: [MandrillMergeVars]
287+ , _mmsg_merge_vars :: [MandrillMergeVars]
288 -- ^ per-recipient merge variables, which override global merge variables with the same name.
288 -- ^ per-recipient merge variables, which override global merge variables with the same name.
289− , _mmsg_tags :: [MandrillTags]
289+ , _mmsg_tags :: [MandrillTags]
290 -- ^ an array of string to tag the message with. Stats are accumulated using tags,
290 -- ^ an array of string to tag the message with. Stats are accumulated using tags,
291 -- though we only store the first 100 we see, so this should not be unique
291 -- though we only store the first 100 we see, so this should not be unique
292 -- or change frequently. Tags should be 50 characters or less.
292 -- or change frequently. Tags should be 50 characters or less.
293 -- Any tags starting with an underscore are reserved for internal use
293 -- Any tags starting with an underscore are reserved for internal use
294 -- and will cause errors.
294 -- and will cause errors.
295− , _mmsg_subaccount :: Maybe T.Text
295+ , _mmsg_subaccount :: Maybe T.Text
296 -- ^ the unique id of a subaccount for this message
296 -- ^ the unique id of a subaccount for this message
297 -- - must already exist or will fail with an error
297 -- - must already exist or will fail with an error
298− , _mmsg_google_analytics_domains :: [T.Text]
298+ , _mmsg_google_analytics_domains :: [T.Text]
299 -- ^ an array of strings indicating for which any matching URLs
299 -- ^ an array of strings indicating for which any matching URLs
300 -- will automatically have Google Analytics parameters appended
300 -- will automatically have Google Analytics parameters appended
301 -- to their query string automatically.
301 -- to their query string automatically.
@@ -303,17 +303,17 @@ data MandrillMessage = MandrillMessage {
303 -- ^ optional string indicating the value to set for the utm_campaign
303 -- ^ optional string indicating the value to set for the utm_campaign
304 -- tracking parameter. If this isn't provided the email's from address
304 -- tracking parameter. If this isn't provided the email's from address
305 -- will be used instead.
305 -- will be used instead.
306− , _mmsg_metadata :: Object
306+ , _mmsg_metadata :: Object
307 -- ^ metadata an associative array of user metadata. Mandrill will store
307 -- ^ metadata an associative array of user metadata. Mandrill will store
308 -- this metadata and make it available for retrieval.
308 -- this metadata and make it available for retrieval.
309 -- In addition, you can select up to 10 metadata fields to index
309 -- In addition, you can select up to 10 metadata fields to index
310 -- and make searchable using the Mandrill search api.
310 -- and make searchable using the Mandrill search api.
311− , _mmsg_recipient_metadata :: [MandrillMetadata]
311+ , _mmsg_recipient_metadata :: [MandrillMetadata]
312 -- ^ Per-recipient metadata that will override the global values
312 -- ^ Per-recipient metadata that will override the global values
313 -- specified in the metadata parameter.
313 -- specified in the metadata parameter.
314− , _mmsg_attachments :: [MandrillWebContent]
314+ , _mmsg_attachments :: [MandrillWebContent]
315 -- ^ an array of supported attachments to add to the message
315 -- ^ an array of supported attachments to add to the message
316− , _mmsg_images :: [MandrillWebContent]
316+ , _mmsg_images :: [MandrillWebContent]
317 -- ^ an array of embedded images to add to the message
317 -- ^ an array of embedded images to add to the message
318 } deriving Show
318 } deriving Show
319
319
test/Main.hs+11−7
@@ -1,14 +1,14 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2module Main where
2module Main where
3
3
4−import System.Environment
5import Data.Monoid
4import Data.Monoid
6−import Tests
5+import qualified Data.Text as T
7import Online
6import Online
7+import System.Environment
8import Test.Tasty
8import Test.Tasty
9import Test.Tasty.HUnit
9import Test.Tasty.HUnit
10import Test.Tasty.QuickCheck
10import Test.Tasty.QuickCheck
11−import qualified Data.Text as T
11+import Tests
12
12
13----------------------------------------------------------------------
13----------------------------------------------------------------------
14withQuickCheckDepth :: TestName -> Int -> [TestTree] -> TestTree
14withQuickCheckDepth :: TestName -> Int -> [TestTree] -> TestTree
@@ -23,10 +23,12 @@ onlineTestsIfEnabled = do
23 Nothing -> return []
23 Nothing -> return []
24 Just k -> return [
24 Just k -> return [
25 testGroup "Mandrill online tests" [
25 testGroup "Mandrill online tests" [
26− testCase "users/info.json" (testOnlineUsersInfo k)
26+ testCase "users/info.json" (testOnlineUsersInfo k)
27− , testCase "users/ping2.json" (testOnlineUsersPing2 k)
27+ , testCase "users/ping2.json" (testOnlineUsersPing2 k)
28− , testCase "users/senders.json" (testOnlineUsersSenders k)
28+ , testCase "users/senders.json" (testOnlineUsersSenders k)
29− , testCase "messages/send.json" (testOnlineMessagesSend k)
29+ , testCase "messages/send.json" (testOnlineMessagesSend k)
30+ , testCase "inbound/addDomain.json" (testOnlineDomainAdd k)
31+ , testCase "inbound/addRoute.json" (testOnlineRouteAdd k)
30 ]]
32 ]]
31
33
32----------------------------------------------------------------------
34----------------------------------------------------------------------
@@ -40,5 +42,7 @@ main = do
40 , testCase "users/senders.json API parsing" testUsersSenders
42 , testCase "users/senders.json API parsing" testUsersSenders
41 , testCase "messages/send.json API parsing" testMessagesSend
43 , testCase "messages/send.json API parsing" testMessagesSend
42 , testCase "messages/send.json API response parsing" testMessagesResponseRejected
44 , testCase "messages/send.json API response parsing" testMessagesResponseRejected
45+ , testCase "inbound/add-route.json API response parsing" testRouteAdd
46+ , testCase "inbound/add-domain.json API response parsing" testDomainAdd
43 ]
47 ]
44 ]
48 ]
test/Online.hs+25−7
@@ -1,19 +1,20 @@
1{-# LANGUAGE OverloadedStrings #-}
1{-# LANGUAGE OverloadedStrings #-}
2module Online where
2module Online where
3
3
4−import Test.QuickCheck
5−import Test.Tasty.HUnit
6−import Text.RawString.QQ
7−import Data.Either
8import Data.Aeson
4import Data.Aeson
5+import qualified Data.ByteString.Char8 as C8
6+import Data.Either
9import Network.API.Mandrill.Messages.Types
7import Network.API.Mandrill.Messages.Types
10import Network.API.Mandrill.Users.Types
8import Network.API.Mandrill.Users.Types
11−import qualified Data.ByteString.Char8 as C8
12import RawData
9import RawData
10+import Test.QuickCheck
11+import Test.Tasty.HUnit
12+import Text.RawString.QQ
13
13
14+import qualified Network.API.Mandrill.Inbound as API
15+import qualified Network.API.Mandrill.Messages as API
14import Network.API.Mandrill.Types
16import Network.API.Mandrill.Types
15−import qualified Network.API.Mandrill.Messages as API
17+import qualified Network.API.Mandrill.Users as API
16−import qualified Network.API.Mandrill.Users as API
17
18
18--
19--
19-- Users calls
20-- Users calls
@@ -50,3 +51,20 @@ testOnlineMessagesSend k = do
50 case res of
51 case res of
51 MandrillSuccess _ -> return ()
52 MandrillSuccess _ -> return ()
52 MandrillFailure e -> fail $ "messages/send.json " ++ show e
53 MandrillFailure e -> fail $ "messages/send.json " ++ show e
54+
55+--
56+-- Inbound calls
57+--
58+
59+testOnlineDomainAdd k = do
60+ res <- API.addDomain k "foobar.com" Nothing
61+ case res of
62+ MandrillSuccess a -> print a
63+ MandrillFailure e -> fail $ "inbound/add-domain.json " ++ show e
64+
65+
66+testOnlineRouteAdd k = do
67+ res <- API.addRoute k "foobar.com" "mail-*" "http://requestb.in/19a4frw1" Nothing
68+ case res of
69+ MandrillSuccess a -> print a
70+ MandrillFailure e -> fail $ "inbound/add-domain.json " ++ show e
test/RawData.hs+22−4
@@ -1,10 +1,10 @@
1{-# LANGUAGE QuasiQuotes #-}
1{-# LANGUAGE QuasiQuotes #-}
2module RawData where
2module RawData where
3
3
4+import Data.Either
4−import Test.QuickCheck
5+import Test.QuickCheck
5−import Test.Tasty.HUnit
6+import Test.Tasty.HUnit
6−import Text.RawString.QQ
7+import Text.RawString.QQ
7−import Data.Either
8
8
9usersInfoData :: String
9usersInfoData :: String
10usersInfoData = [r|
10usersInfoData = [r|
@@ -210,3 +210,21 @@ messagesResponseRejected = [r|
210 }
210 }
211]
211]
212|]
212|]
213+
214+
215+domainAdd = [r|
216+{
217+ "domain": "inbound.example.com",
218+ "created_at": "2013-01-01 15:30:27",
219+ "valid_mx": true
220+}
221+|]
222+
223+
224+routeAdd= [r|
225+{
226+ "id": "7.23",
227+ "pattern": "mailbox-*",
228+ "url": "http://example.com/webhook-url"
229+}
230+|]
test/Tests.hs+20−2
@@ -4,9 +4,10 @@ module Tests where
4import Data.Aeson
4import Data.Aeson
5import qualified Data.ByteString.Char8 as C8
5import qualified Data.ByteString.Char8 as C8
6import Data.Either
6import Data.Either
7+import Network.API.Mandrill.Inbound
7import Network.API.Mandrill.Messages.Types
8import Network.API.Mandrill.Messages.Types
8−import Network.API.Mandrill.Users.Types
9import Network.API.Mandrill.Types
9import Network.API.Mandrill.Types
10+import Network.API.Mandrill.Users.Types
10import RawData
11import RawData
11import Test.Tasty.HUnit
12import Test.Tasty.HUnit
12
13
@@ -17,7 +18,7 @@ isRight _ = True
17#endif
18#endif
18
19
19testMessagesSend :: Assertion
20testMessagesSend :: Assertion
20−testMessagesSend =
21+testMessagesSend =
21 assertBool ("send.json: Parsing failed! " ++ show parsePayload)
22 assertBool ("send.json: Parsing failed! " ++ show parsePayload)
22 (isRight parsePayload)
23 (isRight parsePayload)
23 where
24 where
@@ -49,3 +50,20 @@ testMessagesResponseRejected = do
49 where
50 where
50 parsePayload :: Either String (MandrillResponse [MessagesResponse])
51 parsePayload :: Either String (MandrillResponse [MessagesResponse])
51 parsePayload = eitherDecodeStrict . C8.pack $ messagesResponseRejected
52 parsePayload = eitherDecodeStrict . C8.pack $ messagesResponseRejected
53+
54+testDomainAdd :: Assertion
55+testDomainAdd =
56+ assertBool ("inbound/add-domain.json (response): parsing failed" ++ show parsePayload)
57+ (isRight parsePayload)
58+ where
59+ parsePayload :: Either String DomainAddResponse
60+ parsePayload = eitherDecodeStrict . C8.pack $ domainAdd
61+
62+
63+testRouteAdd :: Assertion
64+testRouteAdd =
65+ assertBool ("inbound/add-route.json (response): parsing failed" ++ show parsePayload)
66+ (isRight parsePayload)
67+ where
68+ parsePayload :: Either String RouteAddResponse
69+ parsePayload = eitherDecodeStrict . C8.pack $ routeAdd