Main.hs 734 B

123456789101112131415161718192021222324
  1. {-# LANGUAGE OverloadedStrings #-}
  2. module Main (main) where
  3. import Json
  4. import Control.Monad.IO.Class
  5. import Network.HTTP.Req
  6. import qualified Data.ByteString.Char8 as B
  7. import System.Exit
  8. main :: IO ()
  9. main = runReq defaultHttpConfig $ do
  10. bs <- req GET (https "loadaverage.org" /: "api" /: "statuses" /: "public_timeline.as") NoReqBody bsResponse mempty
  11. let r = responseBody bs
  12. liftIO $ case Json.runParser Json.value $ Input 0 (B.unpack r) of
  13. Right (_, json) -> do
  14. liftIO $ putStrLn ("Parsed as: " ++ show json)
  15. Left (ParserError loc msg) -> do
  16. putStrLn $
  17. "[ERROR] Parser failed at character " ++ show loc ++ ": " ++ msg
  18. liftIO $ exitFailure
  19. liftIO $ B.putStrLn r
  20. liftIO $ exitFailure