module Network.Pastis (pastisURL) where import Network.HTTP import Network.URI -- | Use pastisURL to shorten a URL. pastisURL :: String -> IO String pastisURL url = do result <- simpleHTTP request `catch` (const . return $ Left undefined) case result of Left _ -> return url Right response -> return $ rspBody response where request = Request { rqURI = uri , rqMethod = GET , rqHeaders = [] , rqBody = "" } uri = URI { uriScheme = "http:" , uriAuthority = Just $ URIAuth { uriUserInfo = "", uriRegName = "past.is", uriPort = "" } , uriPath = "/api/" , uriQuery = "?format=simple&url=" ++ escapeURIString isUnreserved url , uriFragment = "" }