summaryrefslogtreecommitdiff
path: root/Network
diff options
context:
space:
mode:
authorAlpMestanogullari <>2011-08-05 16:35:09 (GMT)
committerLuite Stegeman <luite@luite.com>2011-08-05 16:35:09 (GMT)
commit592c8d50406169ad66f06d4f0462803408b0a17d (patch)
treefe9effeeee561e611ba32998c7aa8b196aca419d /Network
version 0.10.1
Diffstat (limited to 'Network')
-rw-r--r--Network/Pastis.hs21
1 files changed, 21 insertions, 0 deletions
diff --git a/Network/Pastis.hs b/Network/Pastis.hs
new file mode 100644
index 0000000..45f1aa0
--- /dev/null
+++ b/Network/Pastis.hs
@@ -0,0 +1,21 @@
+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 = "" } \ No newline at end of file