module QuicQuid.Agent.Curl(curlAgent) where import qualified Data.Map as M import QuicQuid.Agent.Util import Network.Curl t = do c "http://www.quicquid.org" c "http://docs.google.com/View?docid=dcfrgtpf_51fh7v8vdz" where c url = curl url >>= print -- |An agent that returns http-accessible resources: curlAgent = answerAgent "resource" "resource{url:?url,content:?content}" process where process qch = do (bs,replyCh) <- readAskChan qch let Just (Str u) = M.lookup "url" bs let Just (Var v) = M.lookup "content" bs (mimeType,body) <- curl u writeQueryChan replyCh $ M.fromList [(v,App (Str "mime") $ Arr [Str mimeType ,Str body ])] -- BUG: returns a void result when is not online curl url = do res <- curlGetResponse url [] IString resType <- respGetInfo res $ ContentType return (resType,respBody res)