Source

-- A library that serves as an abstraction for dealing with the internet.{-Copyright 2012, 2013, 2014 Colin Woodbury <colingw@gmail.com>This file is part of Aura.Aura is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or(at your option) any later version.Aura is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with Aura. If not, see <http://www.gnu.org/licenses/>.-}moduleInternet(unpack,urlContents,urlEncodeVars,saveUrlContents)whereimportqualifiedData.ByteString.LazyasLimportData.ByteString.Lazy.Char8(pack,unpack)importControl.Exception(catch)importSystem.FilePath(splitFileName,(</>))importNetwork.HTTP(urlEncodeVars)importSystem.IO(hClose,openFile,IOMode(WriteMode))importNetwork.HTTP.Conduit---urlContents::String->IOL.ByteStringurlContentsurl=doreq<-parseUrlurlletreq2=req{responseTimeout=Nothing}catch(fmapresponseBody.withManager.httpLbs$req2)handleExceptionhandleException::HttpException->IOL.ByteStringhandleException_=return(pack"")saveUrlContents::FilePath->String->IOFilePathsaveUrlContentsfpathurl=dohandle<-openFilefilePathWriteModecontent<-urlContentsurlL.hPutStrhandlecontent>>hClosehandle>>returnfilePathwherefilePath=fpath</>file(_,file)=splitFileNameurl