diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2f707d8..694d9b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,7 +58,7 @@ jobs: - name: Configure run: | - cabal configure --enable-tests --enable-benchmarks --test-show-details=direct + cabal configure --enable-tests --enable-benchmarks --test-show-details=direct -fexamples cabal build all --dry-run # The last step generates dist-newstyle/cache/plan.json for the cache key. diff --git a/README.md b/README.md index 9dc6c92..3087423 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ testMail = from = MailAddress "jane@example.com" "Jane Smith" subject = "Email Subject" content = fromList [mailContentText "Example Content"] - in mail [to] from subject content + in mail [to] from subject $ Just content main :: IO () main = do diff --git a/examples/SendEmail.hs b/examples/SendEmail.hs new file mode 100644 index 0000000..4084837 --- /dev/null +++ b/examples/SendEmail.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE OverloadedStrings #-} + +import Data.List.NonEmpty (fromList) +import Data.Text (Text) +import Network.SendGridV3.Api +import Control.Lens ((^.)) +import Network.Wreq (responseStatus, statusCode) + +sendGridApiKey :: Text +sendGridApiKey = "SG..." + +testMail :: Mail () () +testMail = + let to = personalization $ fromList [MailAddress "john@example.com" "John Doe"] + from = MailAddress "jane@example.com" "Jane Smith" + subject = "Email Subject" + content = fromList [mailContentText "Example Content"] + in mail [to] from subject $ Just content + +main :: IO () +main = do + sendgridSettings <- mkSendGridSettings sendGridApiKey + + -- Send an email, overriding options as needed + eResponse <- sendMail sendgridSettings (testMail { _mailSendAt = Just 1516468000 }) + case eResponse of + Left httpException -> error $ show httpException + Right response -> print (response ^. responseStatus . statusCode) diff --git a/sendgrid-v3.cabal b/sendgrid-v3.cabal index 66b92f0..b07562f 100644 --- a/sendgrid-v3.cabal +++ b/sendgrid-v3.cabal @@ -11,7 +11,12 @@ maintainer: buesing.marcel@googlemail.com -- copyright: category: Network build-type: Simple -extra-source-files: ChangeLog.md +extra-doc-files: + ChangeLog.md + README.md +extra-source-files: + examples/*.hs + stack.yaml tested-with: GHC == 8.10.7 , GHC == 9.0.2 , GHC == 9.2.8 @@ -60,3 +65,26 @@ test-suite test , tasty-hunit >= 0.10 , text >= 1.2 , wreq >= 0.5 + +Flag examples + Description: Build the examples + Default: False + Manual: True + +common examples-settings + ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N + default-language: Haskell2010 + default-extensions: OverloadedStrings + build-depends: base >= 4.7 && < 5 + , lens + , sendgrid-v3 + , text + , wreq + hs-source-dirs: examples + if !flag(examples) + buildable: False + +executable SendEmail + import: examples-settings + scope: private + main-is: SendEmail.hs