Skip to content

Instantly share code, notes, and snippets.

@lf94
Created May 5, 2015 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lf94/8bcabec7d87886f57e41 to your computer and use it in GitHub Desktop.
Save lf94/8bcabec7d87886f57e41 to your computer and use it in GitHub Desktop.
runswiftlang.org command-line utility for compiling swift online
{-# 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