module Control.Shell.Download (
URI,
fetch, fetchBytes,
fetchFile,
fetchTags, fetchXML, fetchFeed
) where
import Data.ByteString as BS (ByteString, writeFile)
import Network.Curl.Download as C
import Text.HTML.TagSoup (Tag)
import Text.XML.Light.Types (Content)
import Text.Feed.Types (Feed)
import Control.Shell
type URI = String
liftE :: IO (Either String a) -> Shell a
liftE m = do
res <- liftIO m
case res of
Left e -> fail e
Right x -> return x
fetchBytes :: URI -> Shell ByteString
fetchBytes = liftE . C.openURI
fetch :: URI -> Shell String
fetch = liftE . C.openURIString
fetchFile :: FilePath -> URI -> Shell ()
fetchFile file = fetchBytes >=> liftIO . BS.writeFile file
fetchTags :: URI -> Shell [Tag String]
fetchTags = liftE . C.openAsTags
fetchXML :: URI -> Shell [Content]
fetchXML = liftE . C.openAsXML
fetchFeed :: URI -> Shell Feed
fetchFeed = liftE . C.openAsFeed