Created
September 30, 2013 11:54
-
-
Save qoelet/6762708 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data ConnectionTest = ConnectionTest { ctVersion :: String, ctResult :: String } | |
deriving (Show) | |
instance ToJSON ConnectionTest where | |
toJSON (ConnectionTest versionV resultV) = object [ "ctVersion" .= versionV, | |
"ctResult" .= resultV ] | |
instance FromJSON ConnectionTest where | |
parseJSON (Object v) = ConnectionTest <$> | |
v .: "version" <*> | |
v .: "result" | |
parseJSON _ = empty | |
main :: IO () | |
main = do | |
-- ( declaring consts, reading settings from config etc... ) | |
getResp <- curlGetString (testUrl) [] -- later calls include setting cURL headers etc.. | |
let resp = getResp | |
strResp = BL.pack (getHtmlRespOnly resp) | |
json = decode strResp :: Maybe ConnectionTest | |
putStrLn ("Did we get a successful connection: " ++ show( getConnectionStatus json )) -- if test fail, we should abort | |
return () -- terminate | |
getConnectionStatus :: Maybe ConnectionTest -> Bool | |
getConnectionStatus Nothing = False | |
getConnectionStatus (Just ConnectionTest {ctResult = s}) = s == "Connection successful" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment