git.iko.soy/typeable/mandrill
on master help sign in
Merge pull request #25 from basvandijk/more-precise-types

More precise types

commit5c6584cc74f85246e0e70d499f7eaaa855e2f383 authorAlfredo Di Napoli <alfredo.dinapoli@gmail.com> dateFri 2 Oct 2015, 13:06 (11 years ago) parentceec6d157a0d2f
4 files changed+41−13
README.md+19 mandrill.cabal+2−1 src/Network/API/Mandrill.hs+4−3 src/Network/API/Mandrill/Types.hs+16−9
README.md+19
@@ -8,6 +8,25 @@ the [Mandrill](http://mandrillapp.com) transactional email service.
88
99# Changelog
1010
11+## Version 0.5.0.0
12+
13+* Changed the `MandrillHeaders` type synonym from `Value` to `Object`.
14+
15+* Changed the `mmsg_metadata` and `mmdt_values` fields from `MandrillVars` to `Object`.
16+
17+* Changed the `mmsg_global_merge_vars` and `mmvr_vars` fields from `[MandrillVars]` to `[MergeVar]`
18+
19+* Added the `MergeVar` data type:
20+
21+```haskell
22+data MergeVar = MergeVar {
23+ _mv_name :: !Text
24+ , _mv_content :: Value
25+ }
26+```
27+
28+* Removed the `MandrillVars` type synonym.
29+
1130## Version 0.4.0.0
1231
1332* Modified the `Base64ByteString` type to accept another constructor. This
mandrill.cabal+2−1
@@ -1,5 +1,5 @@
11name: mandrill
2−version: 0.4.1.0
2+version: 0.5.0.0
33synopsis: Library for interfacing with the Mandrill JSON API
44description: Pure Haskell client for the Mandrill JSON API
55license: MIT
@@ -46,6 +46,7 @@ library
4646 , time
4747 , email-validate >= 1.0.0
4848 , old-locale
49+ , unordered-containers
4950 hs-source-dirs:
5051 src
5152 default-language:
src/Network/API/Mandrill.hs+4−3
@@ -32,6 +32,7 @@ import Data.Monoid
3232import Text.Email.Validate
3333import qualified Data.Text as T
3434import qualified Data.Aeson as JSON
35+import qualified Data.HashMap.Strict as H
3536
3637{- $exampleusage
3738
@@ -40,7 +41,7 @@ The API was designed to allow to get you started as quickly as possible:
4041> {-# LANGUAGE OverloadedStrings #-}
4142> import Text.Email.Validate
4243> import Network.API.Mandrill
43−>
44+>
4445> main :: IO ()
4546> main = do
4647> case validate "foo@example.com" of
@@ -66,7 +67,7 @@ emptyMessage f t = MandrillMessage {
6667 , _mmsg_from_email = (MandrillEmail f)
6768 , _mmsg_from_name = Nothing
6869 , _mmsg_to = map newRecipient t
69− , _mmsg_headers = JSON.Null
70+ , _mmsg_headers = H.empty
7071 , _mmsg_important = Nothing
7172 , _mmsg_track_opens = Nothing
7273 , _mmsg_track_clicks = Nothing
@@ -87,7 +88,7 @@ emptyMessage f t = MandrillMessage {
8788 , _mmsg_subaccount = Nothing
8889 , _mmsg_google_analytics_domains = []
8990 , _mmsg_google_analytics_campaign = Nothing
90− , _mmsg_metadata = JSON.Null
91+ , _mmsg_metadata = H.empty
9192 , _mmsg_recipient_metadata = []
9293 , _mmsg_attachments = []
9394 , _mmsg_images = []
src/Network/API/Mandrill/Types.hs+16−9
@@ -19,6 +19,7 @@ import System.Locale (TimeLocale, defaultTimeLocale)
1919#endif
2020import qualified Data.ByteString as B
2121import qualified Data.ByteString.Base64 as Base64
22+import qualified Data.HashMap.Strict as H
2223import qualified Data.Text as T
2324import qualified Data.Text.Encoding as TL
2425import qualified Data.Text.Lazy as TL
@@ -170,17 +171,23 @@ type MandrillTags = T.Text
170171
171172
172173--------------------------------------------------------------------------------
173−type MandrillHeaders = Value
174+type MandrillHeaders = Object
174175
175176
176177--------------------------------------------------------------------------------
177−type MandrillVars = Value
178178
179+data MergeVar = MergeVar {
180+ _mv_name :: !T.Text
181+ , _mv_content :: Value
182+ } deriving Show
183+
184+makeLenses ''MergeVar
185+deriveJSON defaultOptions { fieldLabelModifier = drop 4 } ''MergeVar
179186
180187--------------------------------------------------------------------------------
181188data MandrillMergeVars = MandrillMergeVars {
182189 _mmvr_rcpt :: !T.Text
183− , _mmvr_vars :: [MandrillVars]
190+ , _mmvr_vars :: [MergeVar]
184191 } deriving Show
185192
186193makeLenses ''MandrillMergeVars
@@ -189,7 +196,7 @@ deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''MandrillMergeVars
189196--------------------------------------------------------------------------------
190197data MandrillMetadata = MandrillMetadata {
191198 _mmdt_rcpt :: !T.Text
192− , _mmdt_values :: MandrillVars
199+ , _mmdt_values :: Object
193200 } deriving Show
194201
195202makeLenses ''MandrillMetadata
@@ -266,7 +273,7 @@ data MandrillMessage = MandrillMessage {
266273 , _mmsg_tracking_domain :: Maybe T.Text
267274 -- ^ a custom domain to use for tracking opens and clicks instead of mandrillapp.com
268275 , _mmsg_signing_domain :: Maybe Bool
269− -- ^ a custom domain to use for SPF/DKIM signing instead of mandrill
276+ -- ^ a custom domain to use for SPF/DKIM signing instead of mandrill
270277 -- (for "via" or "on behalf of" in email clients)
271278 , _mmsg_return_path_domain :: Maybe Bool
272279 -- ^ a custom domain to use for the messages's return-path
@@ -274,7 +281,7 @@ data MandrillMessage = MandrillMessage {
274281 -- ^ whether to evaluate merge tags in the message.
275282 -- Will automatically be set to true if either merge_vars
276283 -- or global_merge_vars are provided.
277− , _mmsg_global_merge_vars :: [MandrillVars]
284+ , _mmsg_global_merge_vars :: [MergeVar]
278285 -- ^ global merge variables to use for all recipients. You can override these per recipient.
279286 , _mmsg_merge_vars :: [MandrillMergeVars]
280287 -- ^ per-recipient merge variables, which override global merge variables with the same name.
@@ -295,7 +302,7 @@ data MandrillMessage = MandrillMessage {
295302 -- ^ optional string indicating the value to set for the utm_campaign
296303 -- tracking parameter. If this isn't provided the email's from address
297304 -- will be used instead.
298− , _mmsg_metadata :: MandrillVars
305+ , _mmsg_metadata :: Object
299306 -- ^ metadata an associative array of user metadata. Mandrill will store
300307 -- this metadata and make it available for retrieval.
301308 -- In addition, you can select up to 10 metadata fields to index
@@ -319,7 +326,7 @@ instance Arbitrary MandrillMessage where
319326 <*> pure (MandrillEmail . fromJust $ emailAddress "sender@example.com")
320327 <*> pure Nothing
321328 <*> resize 2 arbitrary
322− <*> pure emptyObject
329+ <*> pure H.empty
323330 <*> pure Nothing
324331 <*> pure Nothing
325332 <*> pure Nothing
@@ -340,7 +347,7 @@ instance Arbitrary MandrillMessage where
340347 <*> pure Nothing
341348 <*> pure []
342349 <*> pure Nothing
343− <*> pure emptyObject
350+ <*> pure H.empty
344351 <*> pure []
345352 <*> pure []
346353 <*> pure []