packages feed

mandrill 0.5.2.3 → 0.5.3.0

raw patch · 5 files changed

+102/−1 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Network.API.Mandrill.Webhooks: EventClicked :: EventHook
+ Network.API.Mandrill.Webhooks: EventDeferred :: EventHook
+ Network.API.Mandrill.Webhooks: EventHardBounced :: EventHook
+ Network.API.Mandrill.Webhooks: EventMarkedAsSpam :: EventHook
+ Network.API.Mandrill.Webhooks: EventOpened :: EventHook
+ Network.API.Mandrill.Webhooks: EventRejected :: EventHook
+ Network.API.Mandrill.Webhooks: EventSent :: EventHook
+ Network.API.Mandrill.Webhooks: EventSoftBounced :: EventHook
+ Network.API.Mandrill.Webhooks: EventUnsubscribed :: EventHook
+ Network.API.Mandrill.Webhooks: WebhookAddRq :: MandrillKey -> Text -> Text -> Set EventHook -> WebhookAddRq
+ Network.API.Mandrill.Webhooks: [_warq_description] :: WebhookAddRq -> Text
+ Network.API.Mandrill.Webhooks: [_warq_events] :: WebhookAddRq -> Set EventHook
+ Network.API.Mandrill.Webhooks: [_warq_key] :: WebhookAddRq -> MandrillKey
+ Network.API.Mandrill.Webhooks: [_warq_url] :: WebhookAddRq -> Text
+ Network.API.Mandrill.Webhooks: data EventHook
+ Network.API.Mandrill.Webhooks: data WebhookAddRq
+ Network.API.Mandrill.Webhooks: instance Data.Aeson.Types.FromJSON.FromJSON Network.API.Mandrill.Webhooks.EventHook
+ Network.API.Mandrill.Webhooks: instance Data.Aeson.Types.FromJSON.FromJSON Network.API.Mandrill.Webhooks.WebhookAddRq
+ Network.API.Mandrill.Webhooks: instance Data.Aeson.Types.ToJSON.ToJSON Network.API.Mandrill.Webhooks.EventHook
+ Network.API.Mandrill.Webhooks: instance Data.Aeson.Types.ToJSON.ToJSON Network.API.Mandrill.Webhooks.WebhookAddRq
+ Network.API.Mandrill.Webhooks: instance GHC.Classes.Eq Network.API.Mandrill.Webhooks.EventHook
+ Network.API.Mandrill.Webhooks: instance GHC.Classes.Ord Network.API.Mandrill.Webhooks.EventHook
+ Network.API.Mandrill.Webhooks: instance GHC.Show.Show Network.API.Mandrill.Webhooks.EventHook
+ Network.API.Mandrill.Webhooks: instance GHC.Show.Show Network.API.Mandrill.Webhooks.WebhookAddRq
+ Network.API.Mandrill.Webhooks: warq_description :: Lens' WebhookAddRq Text
+ Network.API.Mandrill.Webhooks: warq_events :: Lens' WebhookAddRq (Set EventHook)
+ Network.API.Mandrill.Webhooks: warq_key :: Lens' WebhookAddRq MandrillKey
+ Network.API.Mandrill.Webhooks: warq_url :: Lens' WebhookAddRq Text

Files

mandrill.cabal view
@@ -1,5 +1,5 @@ name:                mandrill-version:             0.5.2.3+version:             0.5.3.0 synopsis:            Library for interfacing with the Mandrill JSON API description:         Pure Haskell client for the Mandrill JSON API license:             MIT@@ -26,6 +26,7 @@     Network.API.Mandrill.Messages     Network.API.Mandrill.Messages.Types     Network.API.Mandrill.Inbound+    Network.API.Mandrill.Webhooks     Network.API.Mandrill.Senders   other-modules:     Network.API.Mandrill.Utils
+ src/Network/API/Mandrill/Webhooks.hs view
@@ -0,0 +1,70 @@+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TemplateHaskell   #-}+module Network.API.Mandrill.Webhooks where+import           Control.Applicative           (pure)+import           Control.Lens+import           Control.Monad                 (mzero)+import           Data.Aeson                    (FromJSON, ToJSON, parseJSON,+                                                toJSON)+import           Data.Aeson                    (Value (String))+import           Data.Aeson.TH                 (defaultOptions, deriveJSON)+import           Data.Aeson.Types              (fieldLabelModifier)+import           Data.Set                      (Set)+import           Data.Text                     (Text)+import qualified Data.Text                     as T+import           Network.API.Mandrill.HTTP     (toMandrillResponse)+import           Network.API.Mandrill.Settings+import           Network.API.Mandrill.Types+import           Network.HTTP.Client           (Manager)++data EventHook+  = EventSent+  | EventDeferred+  | EventHardBounced+  | EventSoftBounced+  | EventOpened+  | EventClicked+  | EventMarkedAsSpam+  | EventUnsubscribed+  | EventRejected+  deriving (Ord,Eq)++instance Show EventHook where+  show e = case e of+    EventSent         -> "send"+    EventDeferred     -> "deferral"+    EventSoftBounced  -> "soft_bounce"+    EventHardBounced  -> "hard_bounce"+    EventOpened       -> "open"+    EventClicked      -> "click"+    EventMarkedAsSpam -> "spam"+    EventUnsubscribed -> "unsub"+    EventRejected     -> "reject"+instance FromJSON EventHook where+  parseJSON (String s) =+    case s of+      "send"           -> pure EventSent+      "deferral"       -> pure EventDeferred+      "soft_bounce"    -> pure EventSoftBounced+      "hard_bounce"    -> pure EventHardBounced+      "open"           -> pure EventOpened+      "click"          -> pure EventClicked+      "spam"           -> pure EventMarkedAsSpam+      "reject"         -> pure EventRejected+      "unsub"          -> pure EventUnsubscribed+      x                -> fail ("can't parse " ++  show x)+++instance ToJSON EventHook where+  toJSON e = String (T.pack $ show e)++data WebhookAddRq =+  WebhookAddRq+  { _warq_key         :: MandrillKey+  , _warq_url         :: Text+  , _warq_description :: Text+  , _warq_events      :: Set EventHook+  } deriving Show++makeLenses ''WebhookAddRq+deriveJSON defaultOptions { fieldLabelModifier = drop 6 } ''WebhookAddRq
test/Main.hs view
@@ -45,5 +45,6 @@          , testCase "inbound/add-route.json API response parsing" testRouteAdd          , testCase "inbound/add-domain.json API response parsing" testDomainAdd          , testCase "senders/verify-domain.json API response parsing" testVerifyDomain+         , testCase "webhooks/add.json API response parsing" testWebhookAdd          ]      ]
test/RawData.hs view
@@ -236,3 +236,22 @@     "email": "email@domain.com" } |]++webhookAdd = [r|+{+    "key": "example key",+    "url": "http://example/webhook-url",+    "description": "My Example Webhook",+    "events": [+         "send",+         "deferral",+         "hard_bounce",+         "soft_bounce",+         "open",+         "click",+         "spam",+         "unsub",+         "reject"+    ]+}+|]
test/Tests.hs view
@@ -9,6 +9,7 @@ import           Network.API.Mandrill.Senders import           Network.API.Mandrill.Types import           Network.API.Mandrill.Users.Types+import           Network.API.Mandrill.Webhooks import           RawData import           Test.Tasty.HUnit @@ -76,3 +77,12 @@   where     parsePayload ::  Either String VerifyDomainResponse     parsePayload = eitherDecodeStrict . C8.pack $ domainVerify+++testWebhookAdd :: Assertion+testWebhookAdd =+  assertBool ("webhooks/add.json (request): parsing failed" ++ show parsePayload)+             (isRight parsePayload)+  where+    parsePayload :: Either String WebhookAddRq+    parsePayload = eitherDecodeStrict . C8.pack $ webhookAdd