Permalink
Browse files

-Wall cleanup

  • Loading branch information...
1 parent ad6efcc commit de7f9210fbc119a5b099ca926c2d2d605f6e1bc7 @mariusae committed Jul 23, 2010
Showing with 28 additions and 23 deletions.
  1. +14 −14 Web/TwitterStream/Iteratee.hs
  2. +7 −8 stream.hs
  3. +7 −1 twitterstream.cabal
@@ -9,27 +9,28 @@ import Control.Concurrent.MVar (newMVar, modifyMVar_)
import Control.Exception (catch, SomeException(..))
-- for the JSON instance:
-import qualified Web.Twitter.Types.Import as TwitterTypes
+import Web.Twitter.Types.Import ()
import qualified Data.Iteratee as Iter
-import Data.Iteratee.Char (line)
+import qualified Data.Iteratee.Char as IterChar
import qualified Network.Curl as Curl
import Web.Twitter.Types (Status(..))
import Text.JSON (decode, Result(..))
import Web.TwitterStream.Types
+url :: Stream -> [Char]
url Sample = "http://stream.twitter.com/1/statuses/sample.json"
url Firehose = "http://stream.twitter.com/1/statuses/firehose.json"
driver :: Auth -> Stream -> Iter.IterateeG [] Char IO a -> IO ()
-driver (BasicAuth username password) stream iter' = Curl.withCurlDo $ do
- iter <- newMVar iter'
+driver (BasicAuth username password) stream iterStart = Curl.withCurlDo $ do
+ iter <- newMVar iterStart
- let recvChunk chunk = modifyMVar_ iter $ \iter -> do
- cont <- Iter.runIter iter (Iter.Chunk $ chunk)
+ let recvChunk chunk = modifyMVar_ iter $ \iter' -> do
+ cont <- Iter.runIter iter' (Iter.Chunk $ chunk)
case cont of
-- TODO - actually handle the cases here.
- Iter.Done x _ -> return iter
+ Iter.Done x _ -> return $ Iter.IterateeG $ return . Iter.Done x
Iter.Cont next _ -> return next
h <- Curl.initialize
@@ -38,24 +39,23 @@ driver (BasicAuth username password) stream iter' = Curl.withCurlDo $ do
, Curl.CurlURL $ url stream
, Curl.CurlUserPwd $ username ++ ":" ++ password
, Curl.CurlHttpAuth [Curl.HttpAuthAny]
- , Curl.CurlWriteFunction $ Curl.callbackWriter recvChunk
- ]
+ , Curl.CurlWriteFunction $ Curl.callbackWriter recvChunk ]
Curl.perform h
return ()
status :: (Monad m, MonadIO m) => Iter.IterateeG [] Char m (Maybe Status)
status = do
- l <- line
- case l of
+ someLine <- IterChar.line
+ case someLine of
Left _ -> return Nothing
Right l ->
- return =<< liftIO $
+ liftIO $
catch (decodeStatus l)
(const $ return Nothing :: SomeException -> IO (Maybe Status))
where
decodeStatus line = do
case decode line of
- Ok status -> return $ Just status
- Error _ -> return Nothing
+ Ok status' -> return $ Just status'
+ Error _ -> return Nothing
View
@@ -1,6 +1,8 @@
module Main where
+import Data.Maybe
import Control.Monad.IO.Class
+import Control.Monad (forever, when)
import System (getArgs)
import Web.Twitter.Types (Status(..))
@@ -10,13 +12,10 @@ import qualified Data.Iteratee as Iter
main = do
u : p : _ <- getArgs
- Stream.driver (Stream.BasicAuth u p) Stream.Sample tweets
+ Stream.driver (Stream.BasicAuth u p) Stream.Sample $ forever $ do
+ s <- Stream.status
+ when (isJust s) $ do
+ liftIO $ f (fromJust s)
where
- tweets = do
- s <- Stream.status
- case s of
- Just s -> (liftIO $ f s) >> tweets
- Nothing -> tweets
-
- f tweet = putStrLn $ statusText tweet
+ f tweet = putStrLn $ statusId tweet
View
@@ -15,4 +15,10 @@ library
base == 4.*, iteratee >= 0.3.4, hs-twitter >= 0.2.8,
json >= 0.4.3, curl >= 1.3.5, transformers >= 0.2
exposed-modules:
- Web.TwitterStream
+ Web.TwitterStream, Web.TwitterStream.Types, Web.TwitterStream.Iteratee
+
+ if impl(ghc >= 6.12.0)
+ ghc-options: -threaded -Wall -fwarn-tabs -funbox-strict-fields -O2
+ -fno-warn-unused-do-bind
+ else
+ ghc-options: -threaded -Wall -fwarn-tabs -funbox-strict-fields -O2

0 comments on commit de7f921

Please sign in to comment.