Skip to content

Instantly share code, notes, and snippets.

@qoelet
Created September 30, 2013 11:54
Show Gist options
  • Save qoelet/6762708 to your computer and use it in GitHub Desktop.
Save qoelet/6762708 to your computer and use it in GitHub Desktop.
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