-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.hs
28 lines (23 loc) · 1.02 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env stack
{-# LANGUAGE OverloadedStrings #-}
import Control.Lens ((&), (^.), (.~))
import Data.Aeson
import Network.Wreq
-- Using Identibyte in a Haskell application
--
-- This example shows how you can integrate Identibyte with a Haskell
-- application by making a simple HTTP request to the /checks endpoint
-- to see if an email is disposable.
data CheckBody = CheckBody { emailDisposable :: Bool } deriving (Show)
instance FromJSON CheckBody where
parseJSON = withObject "check" $ \o ->
CheckBody <$> ((o .: "email") >>= (.: "disposable"))
main = do
-- Define the API endpoint and request settings
let email = "[email protected]"
let opts = defaults & auth .~ Just (basicAuth "API_TOKEN" "")
-- Make the request and check if the email is disposable
r <- asJSON =<< getWith opts ("https://identibyte.com/check/" ++ email)
let result = if (emailDisposable (r ^. responseBody)) == True then "Yes" else "No"
-- Print the result
putStrLn $ "Is " ++ email ++ " disposable? " ++ result