module Web.Tweet
(
basicTweet
, thread
, reply
, module Web.Tweet.Types
, module Web.Tweet.API
, module Web.Tweet.API.Internal
, signRequest
, oAuthMem
, credentialMem
, urlString
, bird
) where
import Control.Lens
import Control.Monad
import Data.Default
import Data.List.Split (chunksOf)
import Data.Maybe
import Web.Tweet.API
import Web.Tweet.API.Internal
import Web.Tweet.Sign
import Web.Tweet.Types
import Web.Tweet.Utils
import Web.Tweet.Utils.API
basicTweet :: String -> FilePath -> IO Int
basicTweet contents = tweetData (mkTweet contents)
thread :: String -> [String] -> Maybe Int -> Int -> FilePath -> IO ()
thread contents hs idNum num filepath = do
let handleStr = concatMap (((++) " ") . ((++) "@")) hs
let content = (take num) . (chunksOf (140(length handleStr))) $ contents
case idNum of
(Just _) -> thread' content hs idNum filepath
Nothing -> case content of
[] -> pure ()
[x] -> void $ basicTweet x filepath
y@(_:_) -> thread' y hs (Just 0) filepath
thread' :: [String] -> [String] -> Maybe Int -> FilePath -> IO ()
thread' content hs idNum filepath = do
let f = \str i -> tweetData (Tweet { _status = str, _handles = hs, _replyID = if i == 0 then Nothing else Just i }) filepath
let initial = f (head content)
lastTweet <- foldr ((>=>) . f) initial (content) $ fromMaybe 0 idNum
deleteTweet (fromIntegral lastTweet) filepath
reply :: String -> [String] -> Maybe Int -> FilePath -> IO ()
reply contents hs idNum = thread contents hs idNum 1
mkTweet :: String -> Tweet
mkTweet contents = over (status) (const (contents)) def