]> gitweb.michael.orlitzky.com - dead/halcyon.git/blob - src/Twitter/Http.hs
2fe24bdd7c9579738b0d7a05eaa7a94d03b4eaa2
[dead/halcyon.git] / src / Twitter / Http.hs
1 module Twitter.Http
2 where
3
4 import Network.Curl
5 import System.IO (hPutStrLn, stderr)
6
7 --
8 -- http://dev.twitter.com/doc/get/statuses/user_timeline
9 --
10 user_timeline_url :: String -> String
11 user_timeline_url username =
12 concat [ "http://api.twitter.com/1/statuses/user_timeline.xml",
13 "?screen_name=" ++ username,
14 "&include_rts=true",
15 "&count=10" ]
16
17 user_new_statuses_url :: String -> Integer -> String
18 user_new_statuses_url username last_status_id =
19 concat [ user_timeline_url username,
20 "&since_id=" ++ (show last_status_id) ]
21
22
23 get_user_timeline :: String -> IO (Maybe String)
24 get_user_timeline username = do
25 let uri = (user_timeline_url username)
26 timeline <- (http_get uri)
27 return timeline
28
29
30 get_user_new_statuses :: String -> Integer -> IO (Maybe String)
31 get_user_new_statuses username last_status_id = do
32 let uri = (user_new_statuses_url username last_status_id)
33 new_statuses <- (http_get uri)
34 return new_statuses
35
36
37 http_get :: String -> IO (Maybe String)
38 http_get uri = withCurlDo $ do
39 resp <- curlGetString uri [CurlTimeout 45]
40
41 case resp of
42 (CurlOK, body) -> return (Just body)
43 (code, _) -> do
44 hPutStrLn stderr ("HTTP Error: " ++ (show code))
45 return Nothing