4 import qualified Data.ByteString.Lazy as B
5 import qualified Data.ByteString.Char8 as BC
6 import qualified Data.Conduit as C
7 import Data.Conduit.Binary (sinkLbs)
8 import Network.HTTP.Conduit
9 import Web.Authenticate.OAuth (
16 -- |The API URL of username's timeline.
20 -- <https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline>
22 user_timeline_url :: String -> String
23 user_timeline_url username =
24 concat [ "https://api.twitter.com/",
27 "user_timeline.json?",
33 status_url :: Integer -> String
34 status_url status_id =
35 concat [ "https://api.twitter.com/",
41 -- | Given username's last status id, constructs the API URL for
42 -- username's new statuses. Essentially, 'user_timeline_url' with a
43 -- "since_id" parameter tacked on.
44 user_new_statuses_url :: String -> Integer -> String
45 user_new_statuses_url username last_status_id =
46 concat [ user_timeline_url username,
47 "&since_id=" ++ (show last_status_id) ]
50 get_status :: Integer -> IO B.ByteString
51 get_status status_id = do
52 let uri = status_url status_id
56 -- | Return's username's timeline.
57 get_user_timeline :: String -> IO B.ByteString
58 get_user_timeline username = do
59 let uri = user_timeline_url username
63 -- | Returns the JSON representing all of username's statuses that are
64 -- newer than last_status_id.
65 get_user_new_statuses :: String -> Integer -> IO B.ByteString
66 get_user_new_statuses username last_status_id = do
67 let uri = user_new_statuses_url username last_status_id
71 -- | Retrieve a URL, or crash.
72 http_get :: String -> IO B.ByteString
74 manager <- newManager def
75 request <- parseUrl url
78 signed_request <- signOAuth oauth credential request
79 response <- http signed_request manager
80 responseBody response C.$$+- sinkLbs
83 consumer_key = BC.pack ""
84 consumer_secret = BC.pack ""
85 access_token = BC.pack ""
86 access_secret = BC.pack ""
90 oauthConsumerKey = consumer_key,
91 oauthConsumerSecret = consumer_secret
94 credential :: Credential
95 credential = newCredential access_token access_secret