8 import qualified Data.ByteString.Lazy as B
9 import qualified Data.ByteString.Char8 as BC
10 import Network.HTTP.Client (
15 import Network.HTTP.Client.TLS (
17 import Web.Authenticate.OAuth (
24 import Configuration (Cfg(..))
26 -- |The API URL of username's timeline.
30 -- <https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline>
32 user_timeline_url :: String -> String
33 user_timeline_url username =
34 concat [ "https://api.twitter.com/",
37 "user_timeline.json?",
44 -- | Given username's last status id, constructs the API URL for
45 -- username's new statuses. Essentially, 'user_timeline_url' with a
46 -- "since_id" parameter tacked on.
47 user_new_statuses_url :: String -> Integer -> String
48 user_new_statuses_url username last_status_id =
49 url ++ "&since_id=" ++ since_id
51 url = user_timeline_url username
52 since_id = show last_status_id
55 -- | Return's username's timeline.
56 get_user_timeline :: Cfg -> String -> IO B.ByteString
57 get_user_timeline cfg username = do
58 let uri = user_timeline_url username
62 -- | Returns the JSON representing all of username's statuses that are
63 -- newer than last_status_id.
64 get_user_new_statuses :: Cfg -> String -> Integer -> IO B.ByteString
65 get_user_new_statuses cfg username last_status_id = do
66 let uri = user_new_statuses_url username last_status_id
70 -- | Retrieve a URL, or crash.
71 http_get :: Cfg -> String -> IO B.ByteString
73 manager <- newManager tlsManagerSettings
74 request <- parseUrl url
75 signed_request <- signOAuth oauth credential request
76 response <- httpLbs signed_request manager
77 return $ responseBody response
80 consumer_key' = BC.pack (consumer_key cfg)
81 consumer_secret' = BC.pack (consumer_secret cfg)
82 access_token' = BC.pack (access_token cfg)
83 access_secret' = BC.pack (access_secret cfg)
87 oauthConsumerKey = consumer_key',
88 oauthConsumerSecret = consumer_secret'
91 credential :: Credential
92 credential = newCredential access_token' access_secret'