Created
May 5, 2015 09:31
-
-
Save lf94/8bcabec7d87886f57e41 to your computer and use it in GitHub Desktop.
runswiftlang.org command-line utility for compiling swift online
This file contains 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
{-# LANGUAGE OverloadedStrings #-} | |
import Network.HTTP.Conduit | |
import qualified Data.ByteString.Lazy as L | |
import qualified Data.ByteString as BS | |
import System.IO | |
import Data.Aeson | |
data CompilerStatus = CompilerStatus | |
{ | |
success :: Bool | |
code :: Text | |
output :: Text | |
} deriving Show | |
instance fromJSON CompilerStatus where | |
parseJSON (Object v) = CompilerStatus <$> v .: "success" <*> v .: "code" <*> v .: "output" | |
parseJSON _ = mzero | |
main = do | |
_stdin <- BS.getContents | |
initReq <- parseUrl "http://www.runswiftlang.com/api/v1/swift/run" | |
let req = (flip urlEncodedBody) initReq $ | |
[ ("api_key", "71910F1F-B1B1-4B0B-9B68-CD83910135A1"), | |
("task[code]", _stdin) | |
] | |
response <- withManager $ httpLbs req | |
cs <- (decode . responseBody response) :: Maybe CompilerStatus | |
putStrLn cs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment