diff options
author | Joris Guyonvarch | 2015-04-11 19:20:04 +0200 |
---|---|---|
committer | Joris Guyonvarch | 2015-04-11 19:20:04 +0200 |
commit | 4ddd6d1f6df2bab75d42b6d45b816e92e7173529 (patch) | |
tree | 09ddfd62fe32e210a87eb15eb86ee07ab9f24623 /src/Page.hs | |
parent | 88b7f848da3515d67cfb989b98ad5285a037993e (diff) |
Fixing parsing errors, and use Text from now
Diffstat (limited to 'src/Page.hs')
-rw-r--r-- | src/Page.hs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Page.hs b/src/Page.hs index b70db70..b048410 100644 --- a/src/Page.hs +++ b/src/Page.hs @@ -4,11 +4,18 @@ module Page import Control.Exception (SomeException, try) +import qualified Data.Text as T + import Network.HTTP (simpleHTTP, getRequest, getResponseBody) -getPage :: String -> IO (Either String String) +import Model.URL + +getPage :: URL -> IO (Either T.Text T.Text) getPage url = - mapLeft show <$> (try (simpleHTTP (getRequest url) >>= getResponseBody) :: IO (Either SomeException String)) + mapLeft (T.pack . show) <$> (try (unsafeGetPage url) :: IO (Either SomeException T.Text)) + +unsafeGetPage :: URL -> IO T.Text +unsafeGetPage url = simpleHTTP (getRequest url) >>= (\x -> T.pack <$> getResponseBody x) mapLeft :: (a -> c) -> Either a b -> Either c b mapLeft f (Left l) = Left (f l) |