From a2c113c6ac0fc7808421e61e88e7b81ea0975c60 Mon Sep 17 00:00:00 2001 From: Brian Jing Date: Mon, 22 Nov 2021 23:38:44 +1100 Subject: [PATCH 1/8] Fix outdated conduit usages in documentation --- Web/Twitter/Conduit.hs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Web/Twitter/Conduit.hs b/Web/Twitter/Conduit.hs index 2ebd06a..f242600 100644 --- a/Web/Twitter/Conduit.hs +++ b/Web/Twitter/Conduit.hs @@ -175,12 +175,16 @@ import qualified Data.Text.IO as T -- main = do -- mgr \<- 'newManager' 'tlsManagerSettings' -- 'sourceWithMaxId' twInfo mgr 'homeTimeline' --- $= CL.isolate 60 --- $$ CL.mapM_ $ \\status -> liftIO $ do --- T.putStrLn $ T.concat [ T.pack . show $ status ^. statusId --- , \": \" --- , status ^. statusUser . userScreenName --- , \": \" --- , status ^. statusText --- ] +-- .| CL.isolate 60 +-- .| CL.mapM_ $ +-- (\\status -> liftIO $ do +-- T.putStrLn $ +-- T.concat +-- [ T.pack . show $ status ^. statusId +-- , \": \" +-- , status ^. statusUser . userScreenName +-- , \": \" +-- , status ^. statusText +-- ] +-- ) -- @ From 49e22fb97d113ac86c7eb277dd00fe9d43dccf1d Mon Sep 17 00:00:00 2001 From: Brian Jing Date: Mon, 22 Nov 2021 23:53:33 +1100 Subject: [PATCH 2/8] Fix comment inconsistency and more code example --- Web/Twitter/Conduit.hs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Web/Twitter/Conduit.hs b/Web/Twitter/Conduit.hs index f242600..a6f93a2 100644 --- a/Web/Twitter/Conduit.hs +++ b/Web/Twitter/Conduit.hs @@ -163,12 +163,12 @@ import qualified Data.Text.IO as T -- or use the conduit wrapper 'sourceWithCursor' as below: -- -- @ --- friends \<- 'sourceWithCursor' twInfo mgr ('friendsList' ('ScreenNameParam' \"thimura\") '&' #count '?~' 200) '$$' 'CL.consume' +-- friends \<- 'sourceWithCursor' twInfo mgr ('friendsList' ('ScreenNameParam' \"thimura\") '&' #count '?~' 200) '.|' 'CL.consume' -- @ -- -- Statuses APIs, for instance, 'homeTimeline', are also wrapped by 'sourceWithMaxId'. -- --- For example, you can print 1000 tweets from your home timeline, as below: +-- For example, you can print 60 tweets from your home timeline, as below: -- -- @ -- main :: IO () @@ -176,15 +176,15 @@ import qualified Data.Text.IO as T -- mgr \<- 'newManager' 'tlsManagerSettings' -- 'sourceWithMaxId' twInfo mgr 'homeTimeline' -- .| CL.isolate 60 --- .| CL.mapM_ $ --- (\\status -> liftIO $ do --- T.putStrLn $ --- T.concat --- [ T.pack . show $ status ^. statusId --- , \": \" --- , status ^. statusUser . userScreenName --- , \": \" --- , status ^. statusText --- ] +-- .| CL.mapM_ +-- (\\status -> do +-- T.putStrLn $ +-- T.concat +-- [ T.pack . show $ status ^. statusId +-- , \": \" +-- , status ^. statusUser . userScreenName +-- , \": \" +-- , status ^. statusText +-- ] -- ) -- @ From 9a1399bae871730178c8e10aa3d9b7efb5ba5528 Mon Sep 17 00:00:00 2001 From: Brian Jing Date: Tue, 23 Nov 2021 17:10:39 +1100 Subject: [PATCH 3/8] Add missing runConduit function --- Web/Twitter/Conduit.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Web/Twitter/Conduit.hs b/Web/Twitter/Conduit.hs index a6f93a2..ba48ec3 100644 --- a/Web/Twitter/Conduit.hs +++ b/Web/Twitter/Conduit.hs @@ -174,7 +174,7 @@ import qualified Data.Text.IO as T -- main :: IO () -- main = do -- mgr \<- 'newManager' 'tlsManagerSettings' --- 'sourceWithMaxId' twInfo mgr 'homeTimeline' +-- runConduit $ 'sourceWithMaxId' twInfo mgr 'homeTimeline' -- .| CL.isolate 60 -- .| CL.mapM_ -- (\\status -> do From e54741d0729acd12c59165a0f91cd55202df6304 Mon Sep 17 00:00:00 2001 From: Takahiro HIMURA Date: Thu, 25 Nov 2021 00:16:16 +0900 Subject: [PATCH 4/8] fix doc: Add runConduit --- Web/Twitter/Conduit.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Web/Twitter/Conduit.hs b/Web/Twitter/Conduit.hs index ba48ec3..def82f0 100644 --- a/Web/Twitter/Conduit.hs +++ b/Web/Twitter/Conduit.hs @@ -163,7 +163,7 @@ import qualified Data.Text.IO as T -- or use the conduit wrapper 'sourceWithCursor' as below: -- -- @ --- friends \<- 'sourceWithCursor' twInfo mgr ('friendsList' ('ScreenNameParam' \"thimura\") '&' #count '?~' 200) '.|' 'CL.consume' +-- friends \<- 'runConduit' $ 'sourceWithCursor' twInfo mgr ('friendsList' ('ScreenNameParam' \"thimura\") '&' #count '?~' 200) '.|' 'CL.consume' -- @ -- -- Statuses APIs, for instance, 'homeTimeline', are also wrapped by 'sourceWithMaxId'. From ba6cfa582850739c92a2e2095342cb067e412e31 Mon Sep 17 00:00:00 2001 From: Takahiro HIMURA Date: Thu, 25 Nov 2021 01:19:05 +0900 Subject: [PATCH 5/8] doc: Add the explanation of how to specify API parameters with OverloadedLabels --- Web/Twitter/Conduit.hs | 77 ++++++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 17 deletions(-) diff --git a/Web/Twitter/Conduit.hs b/Web/Twitter/Conduit.hs index def82f0..b2070ca 100644 --- a/Web/Twitter/Conduit.hs +++ b/Web/Twitter/Conduit.hs @@ -80,16 +80,19 @@ import qualified Data.Text.IO as T -- and . -- All of following examples import modules as below: -- --- > {\-# LANGUAGE OverloadedStrings #-\} --- > --- > import Web.Twitter.Conduit --- > import Web.Twitter.Types.Lens --- > import Data.Conduit --- > import qualified Data.Conduit.List as CL --- > import qualified Data.Text as T --- > import qualified Data.Text.IO as T --- > import Control.Monad.IO.Class --- > import Control.Lens +-- @ +-- {-# LANGUAGE OverloadedLabels #-} +-- {-# LANGUAGE OverloadedStrings #-} +-- +-- import Web.Twitter.Conduit +-- import Web.Twitter.Types.Lens +-- import Data.Conduit +-- import qualified Data.Conduit.List as CL +-- import qualified Data.Text as T +-- import qualified Data.Text.IO as T +-- import Control.Monad.IO.Class +-- import Control.Lens +-- @ -- -- First, you should obtain consumer token and secret from , -- and prepare 'OAuth' variables as follows: @@ -132,7 +135,9 @@ import qualified Data.Text.IO as T -- -- Or, simply as follows: -- --- > twInfo = setCredential tokens credential def +-- @ +-- twInfo = 'setCredential' tokens credential 'def' +-- @ -- -- Twitter API requests are performed by 'call' function. -- For example, @@ -140,7 +145,7 @@ import qualified Data.Text.IO as T -- -- @ -- mgr \<- 'newManager' 'tlsManagerSettings' --- timeline \<- 'call' twInfo mgr 'homeTimeline' +-- timeline \<- 'call' twInfo mgr 'statusesHomeTimeline' -- @ -- -- The response of 'call' function is wrapped by the suitable type of @@ -153,7 +158,42 @@ import qualified Data.Text.IO as T -- includes 20 tweets, and you can change the number of tweets by the /count/ parameter. -- -- @ --- timeline \<- 'call' twInfo mgr '$' 'homeTimeline' '&' #count '?~' 200 +-- timeline \<- 'call' twInfo mgr '$' 'statusesHomeTimeline' '&' #count '?~' 200 +-- @ +-- +-- The parameters which can be specified for this API, is able to be obtained from type parameters of APIRequest. +-- For example, +-- +-- @ +-- 'statusesHomeTimeline' :: +-- 'APIRequest' 'StatusesHomeTimeline' ['Web.Twitter.Types.Status'] +-- @ +-- +-- - The 2nd type parameter of 'APIRequest' represents acceptable parameters in this API request. +-- - The 3nd type parameter of 'APIRequest' denotes a return type of this API request. +-- +-- The 2nd type parameter of 'statusesHomeTimeline' is 'StatusesHomeTimeline' defined as below: +-- +-- @ +-- type StatusesHomeTimeline = +-- '[ "count" ':= Integer +-- , "since_id" ':= Integer +-- , "max_id" ':= Integer +-- , "trim_user" ':= Bool +-- , "exclude_replies" ':= Bool +-- , "contributor_details" ':= Bool +-- , "include_entities" ':= Bool +-- , "tweet_mode" ':= TweetMode +-- ] +-- @ +-- +-- Each element of list represents the name and type of API parameters. +-- You can specify those parameter with OverloadedLabels extension. +-- In the above example, it shows that 'statusesHomeTimeline' API supports "tweet_mode" parameter with 'TweetMode' type, so +-- you can specify "tweet_mode" parameter as: +-- +-- @ +-- 'statusesHomeTimeline' & #tweet_mode ?~ 'Extended' -- @ -- -- If you need more statuses, you can obtain those with multiple API requests. @@ -163,7 +203,10 @@ import qualified Data.Text.IO as T -- or use the conduit wrapper 'sourceWithCursor' as below: -- -- @ --- friends \<- 'runConduit' $ 'sourceWithCursor' twInfo mgr ('friendsList' ('ScreenNameParam' \"thimura\") '&' #count '?~' 200) '.|' 'CL.consume' +-- friends \<- +-- 'runConduit' $ +-- 'sourceWithMaxId' twInfo mgr ('friendsList' ('ScreenNameParam' \"thimura\") '&' #count '?~' 200) +-- '.|' 'CL.consume' -- @ -- -- Statuses APIs, for instance, 'homeTimeline', are also wrapped by 'sourceWithMaxId'. @@ -174,9 +217,9 @@ import qualified Data.Text.IO as T -- main :: IO () -- main = do -- mgr \<- 'newManager' 'tlsManagerSettings' --- runConduit $ 'sourceWithMaxId' twInfo mgr 'homeTimeline' --- .| CL.isolate 60 --- .| CL.mapM_ +-- 'runConduit' $ 'sourceWithMaxId' twInfo mgr 'homeTimeline' +-- '.|' CL.isolate 60 +-- '.|' CL.mapM_ -- (\\status -> do -- T.putStrLn $ -- T.concat From 742b2e0b536bc38a6ecf9c60676e8e7b813a9f05 Mon Sep 17 00:00:00 2001 From: Takahiro HIMURA Date: Thu, 25 Nov 2021 01:34:24 +0900 Subject: [PATCH 6/8] doc: Section headings --- Web/Twitter/Conduit.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Web/Twitter/Conduit.hs b/Web/Twitter/Conduit.hs index b2070ca..d0de26f 100644 --- a/Web/Twitter/Conduit.hs +++ b/Web/Twitter/Conduit.hs @@ -13,6 +13,18 @@ module Web.Twitter.Conduit ( -- * How to use this library -- $howto + -- ** Authentication + -- $auth + + -- ** How to call API + -- $call + + -- *** How to specify API parameters + -- $parameter + + -- *** Conduit API: Recursive API call with changing cursor parameter + -- $conduit + -- * Re-exports module Web.Twitter.Conduit.Api, module Web.Twitter.Conduit.Cursor, @@ -93,6 +105,8 @@ import qualified Data.Text.IO as T -- import Control.Monad.IO.Class -- import Control.Lens -- @ + +-- $auth -- -- First, you should obtain consumer token and secret from , -- and prepare 'OAuth' variables as follows: @@ -138,6 +152,8 @@ import qualified Data.Text.IO as T -- @ -- twInfo = 'setCredential' tokens credential 'def' -- @ + +-- $call -- -- Twitter API requests are performed by 'call' function. -- For example, @@ -160,6 +176,8 @@ import qualified Data.Text.IO as T -- @ -- timeline \<- 'call' twInfo mgr '$' 'statusesHomeTimeline' '&' #count '?~' 200 -- @ + +-- $parameter -- -- The parameters which can be specified for this API, is able to be obtained from type parameters of APIRequest. -- For example, @@ -195,6 +213,8 @@ import qualified Data.Text.IO as T -- @ -- 'statusesHomeTimeline' & #tweet_mode ?~ 'Extended' -- @ + +-- $conduit -- -- If you need more statuses, you can obtain those with multiple API requests. -- This library provides the wrapper for multiple requests with conduit interfaces. From 2c75a52ca8b637c69a69b6a0c781ef595af3f4dd Mon Sep 17 00:00:00 2001 From: Takahiro HIMURA Date: Thu, 25 Nov 2021 01:49:24 +0900 Subject: [PATCH 7/8] Fix README.md - remove old cabal instructions --- README.md | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index aa5058b..132bad2 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,6 @@ This is an conduit based Twitter API library for Haskell, including Streaming AP Documentation is available in [hackage](http://hackage.haskell.org/package/twitter-conduit). -## Usage ## - - $ cabal update - $ cabal install twitter-conduit - ## Quick Start ## For a runnable example, see [sample/simple.hs](https://github.com/himura/twitter-conduit/blob/master/sample/simple.hs). @@ -24,19 +19,32 @@ You can find other various examples in [sample](https://github.com/himura/twitte ### Build ### -If you would like to use cabal sandbox, prepare sandbox as below: +#### Building with Cabal #### ~~~~ -$ cabal sandbox init +$ cabal v2-build all ~~~~ -and then, +#### Building with Stack #### -~~~~ -$ cabal install --only-dependencies -fbuild-samples -$ cabal configure -fbuild-samples -$ cabal build -~~~~ +To build with Stack, you should create top-level `stack.yaml` file first. +An example of `stack.yaml` is like below: + +```.yaml +resolver: lts-18.12 +packages: +- . +- sample +extra-deps: +- twitter-types-0.11.0 +- twitter-types-lens-0.11.0 +``` + +then, run stack. + +``` +$ stack build +``` ### Run ### From d1bf5854b044e620b1c8de4f39fa5704e8a4ea9d Mon Sep 17 00:00:00 2001 From: Takahiro HIMURA Date: Thu, 25 Nov 2021 01:54:09 +0900 Subject: [PATCH 8/8] fourmolu --- Web/Twitter/Conduit.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Web/Twitter/Conduit.hs b/Web/Twitter/Conduit.hs index d0de26f..18070b1 100644 --- a/Web/Twitter/Conduit.hs +++ b/Web/Twitter/Conduit.hs @@ -93,8 +93,8 @@ import qualified Data.Text.IO as T -- All of following examples import modules as below: -- -- @ --- {-# LANGUAGE OverloadedLabels #-} --- {-# LANGUAGE OverloadedStrings #-} +-- {\-# LANGUAGE OverloadedLabels #-\} +-- {\-# LANGUAGE OverloadedStrings #-\} -- -- import Web.Twitter.Conduit -- import Web.Twitter.Types.Lens