Skip to content

Commit

Permalink
remove redundant derivingVia
Browse files Browse the repository at this point in the history
  • Loading branch information
nitinprakash96 committed Oct 7, 2024
1 parent 5cafae7 commit 8d80868
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 17 deletions.
17 changes: 11 additions & 6 deletions azure-email/Azure/Email.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}

module Azure.Email (sendEmail, sendEmailEither) where
module Azure.Email
( sendEmail
, sendEmailEither
) where

import Azure.Types (AzureEmailRequest (..))
import Azure.Types (AzureEmailRequest (..), AzureEmailResponse (..))
import Crypto.Hash.SHA256 (hash, hmac)
import Data.Aeson (encode)
import Data.Proxy (Proxy (..))
Expand All @@ -23,14 +26,16 @@ import qualified Data.Text as Text
sendEmail ::
MonadIO m =>
Text ->
m ()
sendEmail apiSecret = undefined
AzureEmailRequest ->
m AzureEmailResponse
sendEmail apiSecret payload = undefined

sendEmailEither ::
MonadIO m =>
Text ->
m (Either Text ())
sendEmailEither apiSecret = undefined
AzureEmailRequest ->
m (Either Text AzureEmailResponse)
sendEmailEither apiSecret payload = undefined

type SendEmailApi =
"emails:send"
Expand Down
39 changes: 28 additions & 11 deletions azure-email/Azure/Types.hs
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}

module Azure.Types (AzureEmailRequest (..), AzureEmailResponse (..)) where
module Azure.Types
( AzureEmailRequest (..)
, AzureEmailResponse (..)

-- * Types to work with email addresses.

-- These types merely represent the address and
-- are not responsible for validating them whatsoever.
, EmailAddress (..)
, EmailRecipients (..)
, EmailContent (..)
, EmailAttachment (..)
) where

import Data.Aeson (FromJSON (..), ToJSON (..), object, withObject, withText, (.:), (.=))
import Data.Aeson.Types (parseFail)
import Data.Text (Text)
import GHC.Generics (Generic)

{- | Each email is represented as an object with @displayName@
and an associated @address@.
Source: https://learn.microsoft.com/en-us/rest/api/communication/dataplane/email/send?view=rest-communication-dataplane-2023-03-31&tabs=HTTP#emailaddress
-}
data EmailAddress = EmailAddress
{ eaEmail :: !Text
, eaDisplayName :: !Text
}
deriving stock (Eq, Show, Generic)
deriving stock (Eq, Show)

instance ToJSON EmailAddress where
toJSON EmailAddress{..} =
Expand All @@ -27,7 +43,7 @@ data EmailRecipients = EmailRecipients
, bccRecipients :: ![EmailAddress]
, toRecipients :: ![EmailAddress]
}
deriving stock (Generic)
deriving stock (Show)

instance ToJSON EmailRecipients where
toJSON EmailRecipients{..} =
Expand All @@ -46,7 +62,7 @@ data EmailContent = EmailContent
, ecSubject :: !Text
-- ^ Subject of the email message.
}
deriving stock (Eq, Show, Generic)
deriving stock (Eq, Show)

instance ToJSON EmailContent where
toJSON EmailContent{..} =
Expand All @@ -64,7 +80,7 @@ data EmailAttachment = EmailAttachment
, eaName :: !Text
-- ^ Name of the attachment
}
deriving stock (Generic)
deriving stock (Show)

instance ToJSON EmailAttachment where
toJSON EmailAttachment{..} =
Expand All @@ -74,8 +90,9 @@ instance ToJSON EmailAttachment where
, "contentInBase64" .= eaContentInBase64
]

{- | Source:
https://learn.microsoft.com/en-us/rest/api/communication/dataplane/email/send?view=rest-communication-dataplane-2023-03-31&tabs=HTTP
{- | Represents the payload for sending an email message.
Source: https://learn.microsoft.com/en-us/rest/api/communication/dataplane/email/send?view=rest-communication-dataplane-2023-03-31&tabs=HTTP#emailmessage
-}
data AzureEmailRequest = AzureEmailRequest
{ aerContent :: !EmailContent
Expand All @@ -85,7 +102,7 @@ data AzureEmailRequest = AzureEmailRequest
, aerAttachments :: ![EmailAttachment]
, aerUserEngagementTrackingDisabled :: !Bool
}
deriving stock (Generic)
deriving stock (Show)

instance ToJSON AzureEmailRequest where
toJSON AzureEmailRequest{..} =
Expand All @@ -107,7 +124,7 @@ data EmailSendStatus
| NotStarted
| Running
| Succeeded
deriving stock (Eq, Show, Generic, Enum, Bounded)
deriving stock (Eq, Show, Enum, Bounded)

instance FromJSON EmailSendStatus where
parseJSON = withText "EmailSendStatus" $ \case
Expand All @@ -122,7 +139,7 @@ data AzureEmailResponse = AzureEmailResponse
{ aerId :: !Text
, aerStatus :: !EmailSendStatus
}
deriving stock (Eq, Show, Generic)
deriving stock (Eq, Show)

instance FromJSON AzureEmailResponse where
parseJSON = withObject "AzureEmailResponse" $ \o -> do
Expand Down

0 comments on commit 8d80868

Please sign in to comment.