aboutsummaryrefslogtreecommitdiff
path: root/src/executable/haskell/Utils/HTTP.hs
blob: c9015005669a9c60df738b5da15246830423dee5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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)