shellmate-extras 0.3.3 → 0.3.4
raw patch · 2 files changed
+36/−38 lines, 2 filesdep +http-conduitdep +http-typesdep +utf8-stringdep −HTTPdep −network-uridep ~shellmate
Dependencies added: http-conduit, http-types, utf8-string
Dependencies removed: HTTP, network-uri
Dependency ranges changed: shellmate
Files
- Control/Shell/Download.hs +24/−27
- shellmate-extras.cabal +12/−11
Control/Shell/Download.hs view
@@ -7,9 +7,12 @@ , fetchTags, fetchXML, fetchFeed ) where import Data.ByteString as BS (ByteString, writeFile)+import Data.ByteString.UTF8 as BS+import Data.ByteString.Lazy as LBS+import Data.ByteString.Lazy.UTF8 as LBS import Data.String-import Network.HTTP-import qualified Network.URI as U+import Network.HTTP.Simple+import Network.HTTP.Types import Text.Feed.Import (parseFeedString) import Text.Feed.Types (Feed) import Text.HTML.TagSoup (Tag, parseTags)@@ -26,39 +29,33 @@ Left e -> fail (show e) Right x -> return x -httpFail :: (Int, Int, Int) -> String -> Shell a-httpFail (a,b,c) reason =- fail $ "HTTP error " ++ concat [show a, show b, show c] ++ ": " ++ reason+httpFail :: Int -> BS.ByteString -> Shell a+httpFail code reason =+ fail $ "HTTP error " ++ show code ++ ": " ++ BS.toString reason -fetchSomething :: (IsString a, HStream a) => URI -> Shell a+fetchSomething :: URI -> Shell LBS.ByteString fetchSomething uri = do- u <- assert ("could not parse URI `" ++ uri ++ "'") (U.parseURI uri)- rsp <- liftE $ simpleHTTP (req u)- case rspCode rsp of- (2,_,_) -> return (rspBody rsp)- code -> httpFail code (rspReason rsp)- where- req u = Request {- rqURI = u,- rqMethod = GET,- rqHeaders = [],- rqBody = ""- }+ req <- assert ("could not parse URI `" ++ uri ++ "'") $ do+ try $ liftIO $ parseRequest uri+ rsp <- httpLBS req+ case getResponseStatus rsp of+ (Status 200 _) -> return (getResponseBody rsp)+ (Status code reason) -> httpFail code reason --- | Download content specified by a url using curl, returning the content+-- | Download content specified by a URL, returning the content -- as a strict 'ByteString'.-fetchBytes :: URI -> Shell ByteString-fetchBytes = fetchSomething+fetchBytes :: URI -> Shell BS.ByteString+fetchBytes = fmap LBS.toStrict . fetchSomething --- | Download content specified by a url using curl, returning the content--- as a 'String'.+-- | Download content specified by a URL, returning the content+-- as a 'String'. The content is interpreted as UTF8. fetch :: URI -> Shell String-fetch = fetchSomething+fetch = fmap LBS.toString . fetchSomething --- | Download content specified by a url using curl, writing the content to+-- | Download content specified by a URL, writing the content to -- the file specified by the given 'FilePath'. fetchFile :: FilePath -> URI -> Shell ()-fetchFile file = fetchBytes >=> liftIO . BS.writeFile file+fetchFile file = fetchSomething >=> liftIO . LBS.writeFile file -- | Download the content as for 'fetch', but return it as a list of parsed -- tags using the tagsoup html parser.@@ -74,5 +71,5 @@ -- Atom content, using the feed library parser. fetchFeed :: URI -> Shell Feed fetchFeed uri = do- str <- fetch uri+ str <- LBS.toString <$> fetchSomething uri assert ("could not parse feed from `" ++ uri ++ "'") (parseFeedString str)
shellmate-extras.cabal view
@@ -1,5 +1,5 @@ name: shellmate-extras-version: 0.3.3+version: 0.3.4 synopsis: Extra functionality for shellmate. description: HTTP downloads and parsing for various file formats. homepage: https://github.com/valderman/shellmate@@ -21,16 +21,17 @@ Control.Shell.Download Control.Shell.Extract build-depends:- base >=4.7 && <5,- bytestring >=0.10 && <0.11,- HTTP >=4000.2 && <4000.4,- network-uri >=2.6 && <2.7,- feed >=0.3 && <0.4,- tagsoup >=0.13 && <0.14,- xml >=1.3 && <1.4,- text >=1.2 && <1.3,- mime-types >=0.1 && <0.2,- shellmate >=0.3.1 && <0.4+ base >=4.7 && <5,+ bytestring >=0.10 && <0.11,+ feed >=0.3 && <0.4,+ http-conduit >=2.1 && <2.2,+ http-types >=0.9 && <0.10,+ mime-types >=0.1 && <0.2,+ shellmate >=0.3.3 && <0.4,+ tagsoup >=0.13 && <0.14,+ text >=1.2 && <1.3,+ utf8-string >=1.0 && <1.1,+ xml >=1.3 && <1.4 default-language: Haskell2010 ghc-options: