diff options
author | Joris | 2015-08-30 21:17:27 +0200 |
---|---|---|
committer | Joris | 2015-08-30 21:17:27 +0200 |
commit | c4eb771fa09e3972106d80ada6b3c4a023b85249 (patch) | |
tree | 9214b64628e34089b73ff6b4bdcb0edbc668a51e /src/HTTP.hs |
Fetch perfumes according to multiple materials
Diffstat (limited to 'src/HTTP.hs')
-rw-r--r-- | src/HTTP.hs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/HTTP.hs b/src/HTTP.hs new file mode 100644 index 0000000..6ba153d --- /dev/null +++ b/src/HTTP.hs @@ -0,0 +1,23 @@ +module HTTP + ( getPage + ) where + +import Control.Exception (SomeException, try) +import Control.Arrow (left) + +import Data.Text (Text) +import qualified Data.Text as T +import qualified Data.Text.IO as T + +import Network.HTTP (simpleHTTP, getRequest, getResponseBody) + +import Model.URL + +import Codec.Binary.UTF8.String (decodeString) + +getPage :: URL -> IO (Either Text Text) +getPage url = + left (T.pack . show) <$> (try (unsafeGetPage url) :: IO (Either SomeException Text)) + +unsafeGetPage :: URL -> IO Text +unsafeGetPage url = simpleHTTP (getRequest (T.unpack url)) >>= (\x -> T.pack . decodeString <$> getResponseBody x) |