aboutsummaryrefslogtreecommitdiff
path: root/src/executable/haskell/Utils/HTTP.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/executable/haskell/Utils/HTTP.hs')
-rw-r--r--src/executable/haskell/Utils/HTTP.hs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/executable/haskell/Utils/HTTP.hs b/src/executable/haskell/Utils/HTTP.hs
new file mode 100644
index 0000000..c901500
--- /dev/null
+++ b/src/executable/haskell/Utils/HTTP.hs
@@ -0,0 +1,20 @@
+module Utils.HTTP
+ ( get
+ ) where
+
+import Control.Exception (SomeException, try)
+
+import Data.ByteString.Lazy as BS
+import Data.Text (Text)
+import qualified Data.Text as T
+import Data.Text.Encoding as T
+import Network.HTTP.Conduit
+
+import Model.URL
+import Utils.Either (mapLeft)
+
+get :: URL -> IO (Either Text Text)
+get url = mapLeft (T.pack . show) <$> (try (unsafeGetPage url) :: IO (Either SomeException Text))
+
+unsafeGetPage :: URL -> IO Text
+unsafeGetPage url = (T.decodeLatin1 . BS.toStrict) <$> simpleHttp (T.unpack url)