module Twitter.Http where import Network.Curl import System.IO (hPutStrLn, stderr) -- -- http://dev.twitter.com/doc/get/statuses/user_timeline -- user_timeline_url :: String -> String user_timeline_url username = concat [ "http://api.twitter.com/1/statuses/user_timeline.xml", "?screen_name=" ++ username, "&include_rts=true", "&count=10" ] user_new_statuses_url :: String -> Integer -> String user_new_statuses_url username last_status_id = concat [ user_timeline_url username, "&since_id=" ++ (show last_status_id) ] get_user_timeline :: String -> IO (Maybe String) get_user_timeline username = do let uri = (user_timeline_url username) timeline <- (http_get uri) return timeline get_user_new_statuses :: String -> Integer -> IO (Maybe String) get_user_new_statuses username last_status_id = do let uri = (user_new_statuses_url username last_status_id) new_statuses <- (http_get uri) return new_statuses http_get :: String -> IO (Maybe String) http_get uri = withCurlDo $ do resp <- curlGetString uri [CurlTimeout 45] case resp of (CurlOK, body) -> return (Just body) (code, _) -> do hPutStrLn stderr ("HTTP Error: " ++ (show code)) return Nothing