    {-# LANGUAGE DataKinds #-}
    {-# LANGUAGE FlexibleContexts #-}
    {-# LANGUAGE FlexibleInstances #-}
    {-# LANGUAGE OverloadedLabels #-}
    {-# LANGUAGE OverloadedStrings #-}
    {-# LANGUAGE RecordWildCards #-}
    {-# LANGUAGE ScopedTypeVariables #-}
    {-# LANGUAGE TypeFamilies #-}
    {-# LANGUAGE UndecidableInstances #-}

    module Web.Twitter.Conduit.Base (
        ResponseBodyType (..),
        NoContent,
        getResponse,
        call,
        call',
        callWithResponse,
        callWithResponse',
        checkResponse,
        sourceWithMaxId,
        sourceWithMaxId',
        sourceWithCursor,
        sourceWithCursor',
        sourceWithSearchResult,
        sourceWithSearchResult',
        endpoint,
        makeRequest,
        sinkJSON,
        sinkFromJSON,
    ) where

    import Web.Twitter.Conduit.Cursor
    import Web.Twitter.Conduit.Request
    import Web.Twitter.Conduit.Request.Internal
    import Web.Twitter.Conduit.Response
    import Web.Twitter.Conduit.Types
    import Web.Twitter.Types.Lens

    import Control.Lens
    import Control.Monad (void)
    import Control.Monad.Catch (MonadThrow (..))
    import Control.Monad.IO.Class
    import Control.Monad.Trans.Resource (MonadResource, ResourceT, runResourceT)
    import Data.Aeson
    import Data.Aeson.Lens
    import Data.ByteString (ByteString)
    import Data.Coerce
    import qualified Data.Conduit as C
    import qualified Data.Conduit.Attoparsec as CA
    import qualified Data.Conduit.List as CL
    import qualified Data.Map as M
    import qualified Data.Text.Encoding as T
    import GHC.TypeLits (KnownSymbol)
    import Network.HTTP.Client.MultipartFormData
    import qualified Network.HTTP.Conduit as HTTP
    import qualified Network.HTTP.Types as HT
    import Web.Authenticate.OAuth (signOAuth)

    makeRequest ::
        APIRequest apiName responseType ->
        IO HTTP.Request
    makeRequest :: forall (apiName :: [Param Symbol (*)]) responseType.
    APIRequest apiName responseType -> IO Request
    makeRequest (APIRequest Method
    m String
    u APIQuery
    pa) = Method -> String -> SimpleQuery -> IO Request
    makeRequest' Method
    m String
    u (APIQuery -> SimpleQuery
    makeSimpleQuery APIQuery
    pa)
    makeRequest (APIRequestMultipart Method
    m String
    u APIQuery
    param [Part]
    prt) =
        [Part] -> Request -> IO Request
    forall (m :: * -> *). MonadIO m => [Part] -> Request -> m Request
    formDataBody [Part]
    body (Request -> IO Request) -> IO Request -> IO Request
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< Method -> String -> SimpleQuery -> IO Request
    makeRequest' Method
    m String
    u []
      where
        body :: [Part]
    body = [Part]
    prt [Part] -> [Part] -> [Part]
    forall a. [a] -> [a] -> [a]
    ++ [Part]
    partParam
        partParam :: [Part]
    partParam = (SimpleQueryItem -> Part) -> SimpleQuery -> [Part]
    forall a b. (a -> b) -> [a] -> [b]
    Prelude.map ((Text -> Method -> Part) -> (Text, Method) -> Part
    forall a b c. (a -> b -> c) -> (a, b) -> c
    uncurry Text -> Method -> Part
    forall (m :: * -> *). Applicative m => Text -> Method -> PartM m
    partBS ((Text, Method) -> Part)
    -> (SimpleQueryItem -> (Text, Method)) -> SimpleQueryItem -> Part
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ASetter SimpleQueryItem (Text, Method) Method Text
    -> (Method -> Text) -> SimpleQueryItem -> (Text, Method)
    forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
    over ASetter SimpleQueryItem (Text, Method) Method Text
    forall s t a b. Field1 s t a b => Lens s t a b
    Lens SimpleQueryItem (Text, Method) Method Text
    _1 Method -> Text
    T.decodeUtf8) (APIQuery -> SimpleQuery
    makeSimpleQuery APIQuery
    param)
    makeRequest (APIRequestJSON Method
    m String
    u APIQuery
    param Value
    body) = do
        Request
    req <- Method -> String -> SimpleQuery -> IO Request
    makeRequest' Method
    m String
    u (APIQuery -> SimpleQuery
    makeSimpleQuery APIQuery
    param)
        Request -> IO Request
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Request -> IO Request) -> Request -> IO Request
    forall a b. (a -> b) -> a -> b
    $
            Request
    req
                { HTTP.requestBody = HTTP.RequestBodyLBS $ encode body
                , HTTP.requestHeaders = ("Content-Type", "application/json") : HTTP.requestHeaders req
                }

    makeRequest' ::
        -- | HTTP request method (GET or POST)
        HT.Method ->
        -- | API Resource URL
        String ->
        -- | Query
        HT.SimpleQuery ->
        IO HTTP.Request
    makeRequest' :: Method -> String -> SimpleQuery -> IO Request
    makeRequest' Method
    m String
    url SimpleQuery
    query = do
        Request
    req <- String -> IO Request
    forall (m :: * -> *). MonadThrow m => String -> m Request
    HTTP.parseRequest String
    url
        let addParams :: Request -> Request
    addParams =
                if Method
    m Method -> Method -> Bool
    forall a. Eq a => a -> a -> Bool
    == Method
    "POST"
                    then SimpleQuery -> Request -> Request
    HTTP.urlEncodedBody SimpleQuery
    query
                    else \Request
    r -> Request
    r {HTTP.queryString = HT.renderSimpleQuery False query}
        Request -> IO Request
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Request -> IO Request) -> Request -> IO Request
    forall a b. (a -> b) -> a -> b
    $ Request -> Request
    addParams (Request -> Request) -> Request -> Request
    forall a b. (a -> b) -> a -> b
    $ Request
    req {HTTP.method = m}

    class ResponseBodyType a where
        parseResponseBody ::
            Response (C.ConduitM () ByteString (ResourceT IO) ()) ->
            ResourceT IO (Response a)

    type NoContent = ()
    instance ResponseBodyType NoContent where
        parseResponseBody :: Response (ConduitM () Method (ResourceT IO) ())
    -> ResourceT IO (Response ())
    parseResponseBody Response (ConduitM () Method (ResourceT IO) ())
    res =
            case Response (ConduitM () Method (ResourceT IO) ()) -> Status
    forall responseType. Response responseType -> Status
    responseStatus Response (ConduitM () Method (ResourceT IO) ())
    res of
                Status
    st | Status
    st Status -> Status -> Bool
    forall a. Eq a => a -> a -> Bool
    == Status
    HT.status204 -> Response () -> ResourceT IO (Response ())
    forall a. a -> ResourceT IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Response () -> ResourceT IO (Response ()))
    -> Response () -> ResourceT IO (Response ())
    forall a b. (a -> b) -> a -> b
    $ Response (ConduitM () Method (ResourceT IO) ()) -> Response ()
    forall (f :: * -> *) a. Functor f => f a -> f ()
    void Response (ConduitM () Method (ResourceT IO) ())
    res
                Status
    _ -> do
                    Value
    body <- ConduitT () Void (ResourceT IO) Value -> ResourceT IO Value
    forall (m :: * -> *) r. Monad m => ConduitT () Void m r -> m r
    C.runConduit (ConduitT () Void (ResourceT IO) Value -> ResourceT IO Value)
    -> ConduitT () Void (ResourceT IO) Value -> ResourceT IO Value
    forall a b. (a -> b) -> a -> b
    $ Response (ConduitM () Method (ResourceT IO) ())
    -> ConduitM () Method (ResourceT IO) ()
    forall responseType. Response responseType -> responseType
    responseBody Response (ConduitM () Method (ResourceT IO) ())
    res ConduitM () Method (ResourceT IO) ()
    -> ConduitT Method Void (ResourceT IO) Value
    -> ConduitT () Void (ResourceT IO) Value
    forall (m :: * -> *) a b c r.
    Monad m =>
    ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
    C..| ConduitT Method Void (ResourceT IO) Value
    forall (m :: * -> *) o. MonadThrow m => ConduitT Method o m Value
    sinkJSON
                    TwitterError -> ResourceT IO (Response ())
    forall e a. (HasCallStack, Exception e) => e -> ResourceT IO a
    forall (m :: * -> *) e a.
    (MonadThrow m, HasCallStack, Exception e) =>
    e -> m a
    throwM (TwitterError -> ResourceT IO (Response ()))
    -> TwitterError -> ResourceT IO (Response ())
    forall a b. (a -> b) -> a -> b
    $ Status -> [Header] -> Value -> TwitterError
    TwitterStatusError (Response (ConduitM () Method (ResourceT IO) ()) -> Status
    forall responseType. Response responseType -> Status
    responseStatus Response (ConduitM () Method (ResourceT IO) ())
    res) (Response (ConduitM () Method (ResourceT IO) ()) -> [Header]
    forall responseType. Response responseType -> [Header]
    responseHeaders Response (ConduitM () Method (ResourceT IO) ())
    res) Value
    body

    instance {-# OVERLAPPABLE #-} FromJSON a => ResponseBodyType a where
        parseResponseBody :: Response (ConduitM () Method (ResourceT IO) ())
    -> ResourceT IO (Response a)
    parseResponseBody = Response (ConduitM () Method (ResourceT IO) ())
    -> ResourceT IO (Response a)
    forall a.
    FromJSON a =>
    Response (ConduitM () Method (ResourceT IO) ())
    -> ResourceT IO (Response a)
    getValueOrThrow

    getResponse ::
        MonadResource m =>
        TWInfo ->
        HTTP.Manager ->
        HTTP.Request ->
        m (Response (C.ConduitM () ByteString m ()))
    getResponse :: forall (m :: * -> *).
    MonadResource m =>
    TWInfo
    -> Manager -> Request -> m (Response (ConduitM () Method m ()))
    getResponse TWInfo {Maybe Proxy
    TWToken
    twToken :: TWToken
    twProxy :: Maybe Proxy
    twToken :: TWInfo -> TWToken
    twProxy :: TWInfo -> Maybe Proxy
    ..} Manager
    mgr Request
    req = do
        Request
    signedReq <- OAuth -> Credential -> Request -> m Request
    forall (m :: * -> *).
    MonadIO m =>
    OAuth -> Credential -> Request -> m Request
    signOAuth (TWToken -> OAuth
    twOAuth TWToken
    twToken) (TWToken -> Credential
    twCredential TWToken
    twToken) (Request -> m Request) -> Request -> m Request
    forall a b. (a -> b) -> a -> b
    $ Request
    req {HTTP.proxy = twProxy}
        Response (ConduitM () Method m ())
    res <- Request -> Manager -> m (Response (ConduitM () Method m ()))
    forall (m :: * -> *) i.
    MonadResource m =>
    Request -> Manager -> m (Response (ConduitM i Method m ()))
    HTTP.http Request
    signedReq Manager
    mgr
        Response (ConduitM () Method m ())
    -> m (Response (ConduitM () Method m ()))
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return
            Response
                { responseStatus :: Status
    responseStatus = Response (ConduitM () Method m ()) -> Status
    forall body. Response body -> Status
    HTTP.responseStatus Response (ConduitM () Method m ())
    res
                , responseHeaders :: [Header]
    responseHeaders = Response (ConduitM () Method m ()) -> [Header]
    forall body. Response body -> [Header]
    HTTP.responseHeaders Response (ConduitM () Method m ())
    res
                , responseBody :: ConduitM () Method m ()
    responseBody = Response (ConduitM () Method m ()) -> ConduitM () Method m ()
    forall body. Response body -> body
    HTTP.responseBody Response (ConduitM () Method m ())
    res
                }

    endpoint :: String
    endpoint :: String
    endpoint = String
    "https://api.twitter.com/1.1/"

    getValue ::
        Response (C.ConduitM () ByteString (ResourceT IO) ()) ->
        ResourceT IO (Response Value)
    getValue :: Response (ConduitM () Method (ResourceT IO) ())
    -> ResourceT IO (Response Value)
    getValue Response (ConduitM () Method (ResourceT IO) ())
    res = do
        Value
    value <-
            ConduitT () Void (ResourceT IO) Value -> ResourceT IO Value
    forall (m :: * -> *) r. Monad m => ConduitT () Void m r -> m r
    C.runConduit (ConduitT () Void (ResourceT IO) Value -> ResourceT IO Value)
    -> ConduitT () Void (ResourceT IO) Value -> ResourceT IO Value
    forall a b. (a -> b) -> a -> b
    $ Response (ConduitM () Method (ResourceT IO) ())
    -> ConduitM () Method (ResourceT IO) ()
    forall responseType. Response responseType -> responseType
    responseBody Response (ConduitM () Method (ResourceT IO) ())
    res ConduitM () Method (ResourceT IO) ()
    -> ConduitT Method Void (ResourceT IO) Value
    -> ConduitT () Void (ResourceT IO) Value
    forall (m :: * -> *) a b c r.
    Monad m =>
    ConduitT a b m () -> ConduitT b c m r -> ConduitT a c m r
    C..| ConduitT Method Void (ResourceT IO) Value
    forall (m :: * -> *) o. MonadThrow m => ConduitT Method o m Value
    sinkJSON
        Response Value -> ResourceT IO (Response Value)
    forall a. a -> ResourceT IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Response Value -> ResourceT IO (Response Value))
    -> Response Value -> ResourceT IO (Response Value)
    forall a b. (a -> b) -> a -> b
    $ Response (ConduitM () Method (ResourceT IO) ())
    res {responseBody = value}

    checkResponse ::
        Response Value ->
        Either TwitterError Value
    checkResponse :: Response Value -> Either TwitterError Value
    checkResponse Response {[Header]
    Value
    Status
    responseStatus :: forall responseType. Response responseType -> Status
    responseBody :: forall responseType. Response responseType -> responseType
    responseHeaders :: forall responseType. Response responseType -> [Header]
    responseStatus :: Status
    responseHeaders :: [Header]
    responseBody :: Value
    ..} =
        case Value
    responseBody Value -> Getting (First Value) Value Value -> Maybe Value
    forall s a. s -> Getting (First a) s a -> Maybe a
    ^? Key -> Traversal' Value Value
    forall t. AsValue t => Key -> Traversal' t Value
    key Key
    "errors" of
            Just errs :: Value
    errs@(Array Array
    _) ->
                case Value -> Result [TwitterErrorMessage]
    forall a. FromJSON a => Value -> Result a
    fromJSON Value
    errs of
                    Success [TwitterErrorMessage]
    errList -> TwitterError -> Either TwitterError Value
    forall a b. a -> Either a b
    Left (TwitterError -> Either TwitterError Value)
    -> TwitterError -> Either TwitterError Value
    forall a b. (a -> b) -> a -> b
    $ Status -> [Header] -> [TwitterErrorMessage] -> TwitterError
    TwitterErrorResponse Status
    responseStatus [Header]
    responseHeaders [TwitterErrorMessage]
    errList
                    Error String
    msg -> TwitterError -> Either TwitterError Value
    forall a b. a -> Either a b
    Left (TwitterError -> Either TwitterError Value)
    -> TwitterError -> Either TwitterError Value
    forall a b. (a -> b) -> a -> b
    $ String -> TwitterError
    FromJSONError String
    msg
            Just Value
    err ->
                TwitterError -> Either TwitterError Value
    forall a b. a -> Either a b
    Left (TwitterError -> Either TwitterError Value)
    -> TwitterError -> Either TwitterError Value
    forall a b. (a -> b) -> a -> b
    $ Status -> [Header] -> Value -> TwitterError
    TwitterUnknownErrorResponse Status
    responseStatus [Header]
    responseHeaders Value
    err
            Maybe Value
    Nothing ->
                if Int
    sci Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    < Int
    200 Bool -> Bool -> Bool
    || Int
    sci Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > Int
    400
                    then TwitterError -> Either TwitterError Value
    forall a b. a -> Either a b
    Left (TwitterError -> Either TwitterError Value)
    -> TwitterError -> Either TwitterError Value
    forall a b. (a -> b) -> a -> b
    $ Status -> [Header] -> Value -> TwitterError
    TwitterStatusError Status
    responseStatus [Header]
    responseHeaders Value
    responseBody
                    else Value -> Either TwitterError Value
    forall a b. b -> Either a b
    Right Value
    responseBody
      where
        sci :: Int
    sci = Status -> Int
    HT.statusCode Status
    responseStatus

    getValueOrThrow ::
        FromJSON a =>
        Response (C.ConduitM () ByteString (ResourceT IO) ()) ->
        ResourceT IO (Response a)
    getValueOrThrow :: forall a.
    FromJSON a =>
    Response (ConduitM () Method (ResourceT IO) ())
    -> ResourceT IO (Response a)
    getValueOrThrow Response (ConduitM () Method (ResourceT IO) ())
    res = do
        Response Value
    res' <- Response (ConduitM () Method (ResourceT IO) ())
    -> ResourceT IO (Response Value)
    getValue Response (ConduitM () Method (ResourceT IO) ())
    res
        case Response Value -> Either TwitterError Value
    checkResponse Response Value
    res' of
            Left TwitterError
    err -> TwitterError -> ResourceT IO ()
    forall e a. (HasCallStack, Exception e) => e -> ResourceT IO a
    forall (m :: * -> *) e a.
    (MonadThrow m, HasCallStack, Exception e) =>
    e -> m a
    throwM TwitterError
    err
            Right Value
    _ -> () -> ResourceT IO ()
    forall a. a -> ResourceT IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()
        case Value -> Result a
    forall a. FromJSON a => Value -> Result a
    fromJSON (Response Value -> Value
    forall responseType. Response responseType -> responseType
    responseBody Response Value
    res') of
            Success a
    r -> Response a -> ResourceT IO (Response a)
    forall a. a -> ResourceT IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Response a -> ResourceT IO (Response a))
    -> Response a -> ResourceT IO (Response a)
    forall a b. (a -> b) -> a -> b
    $ Response Value
    res' {responseBody = r}
            Error String
    err -> TwitterError -> ResourceT IO (Response a)
    forall e a. (HasCallStack, Exception e) => e -> ResourceT IO a
    forall (m :: * -> *) e a.
    (MonadThrow m, HasCallStack, Exception e) =>
    e -> m a
    throwM (TwitterError -> ResourceT IO (Response a))
    -> TwitterError -> ResourceT IO (Response a)
    forall a b. (a -> b) -> a -> b
    $ String -> TwitterError
    FromJSONError String
    err

    -- | Perform an 'APIRequest' and then provide the response which is mapped to a suitable type of
    -- <http://hackage.haskell.org/package/twitter-types twitter-types>.
    --
    -- Example:
    --
    -- @
    -- user <- 'call' twInfo mgr $ 'accountVerifyCredentials'
    -- print user
    -- @
    --
    -- If you need raw JSON value which is parsed by <http://hackage.haskell.org/package/aeson aeson>,
    -- use 'call'' to obtain it.
    call ::
        ResponseBodyType responseType =>
        -- | Twitter Setting
        TWInfo ->
        HTTP.Manager ->
        APIRequest apiName responseType ->
        IO responseType
    call :: forall responseType (apiName :: [Param Symbol (*)]).
    ResponseBodyType responseType =>
    TWInfo
    -> Manager -> APIRequest apiName responseType -> IO responseType
    call = TWInfo
    -> Manager -> APIRequest apiName responseType -> IO responseType
    forall value (apiName :: [Param Symbol (*)]) responseType.
    ResponseBodyType value =>
    TWInfo -> Manager -> APIRequest apiName responseType -> IO value
    call'

    -- | Perform an 'APIRequest' and then provide the response.
    -- The response of this function is not restrict to @responseType@,
    -- so you can choose an arbitrarily type of FromJSON instances.
    call' ::
        ResponseBodyType value =>
        -- | Twitter Setting
        TWInfo ->
        HTTP.Manager ->
        APIRequest apiName responseType ->
        IO value
    call' :: forall value (apiName :: [Param Symbol (*)]) responseType.
    ResponseBodyType value =>
    TWInfo -> Manager -> APIRequest apiName responseType -> IO value
    call' TWInfo
    info Manager
    mgr APIRequest apiName responseType
    req = Response value -> value
    forall responseType. Response responseType -> responseType
    responseBody (Response value -> value) -> IO (Response value) -> IO value
    forall a b. (a -> b) -> IO a -> IO b
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    `fmap` TWInfo
    -> Manager
    -> APIRequest apiName responseType
    -> IO (Response value)
    forall value (apiName :: [Param Symbol (*)]) responseType.
    ResponseBodyType value =>
    TWInfo
    -> Manager
    -> APIRequest apiName responseType
    -> IO (Response value)
    callWithResponse' TWInfo
    info Manager
    mgr APIRequest apiName responseType
    req

    -- | Perform an 'APIRequest' and then provide the 'Response'.
    --
    -- Example:
    --
    -- @
    -- res \<- 'callWithResponse' twInfo mgr $ 'accountVerifyCredentials'
    -- 'print' $ 'responseStatus' res
    -- 'print' $ 'responseHeaders' res
    -- 'print' $ 'responseBody' res
    -- @
    callWithResponse ::
        ResponseBodyType responseType =>
        -- | Twitter Setting
        TWInfo ->
        HTTP.Manager ->
        APIRequest apiName responseType ->
        IO (Response responseType)
    callWithResponse :: forall responseType (apiName :: [Param Symbol (*)]).
    ResponseBodyType responseType =>
    TWInfo
    -> Manager
    -> APIRequest apiName responseType
    -> IO (Response responseType)
    callWithResponse = TWInfo
    -> Manager
    -> APIRequest apiName responseType
    -> IO (Response responseType)
    forall value (apiName :: [Param Symbol (*)]) responseType.
    ResponseBodyType value =>
    TWInfo
    -> Manager
    -> APIRequest apiName responseType
    -> IO (Response value)
    callWithResponse'

    -- | Perform an 'APIRequest' and then provide the 'Response'.
    -- The response of this function is not restrict to @responseType@,
    -- so you can choose an arbitrarily type of FromJSON instances.
    --
    -- Example:
    --
    -- @
    -- res \<- 'callWithResponse'' twInfo mgr $ 'accountVerifyCredentials'
    -- 'print' $ 'responseStatus' res
    -- 'print' $ 'responseHeaders' res
    -- 'print' $ 'responseBody' (res :: Value)
    -- @
    callWithResponse' ::
        ResponseBodyType value =>
        TWInfo ->
        HTTP.Manager ->
        APIRequest apiName responseType ->
        IO (Response value)
    callWithResponse' :: forall value (apiName :: [Param Symbol (*)]) responseType.
    ResponseBodyType value =>
    TWInfo
    -> Manager
    -> APIRequest apiName responseType
    -> IO (Response value)
    callWithResponse' TWInfo
    info Manager
    mgr APIRequest apiName responseType
    req =
        ResourceT IO (Response value) -> IO (Response value)
    forall (m :: * -> *) a. MonadUnliftIO m => ResourceT m a -> m a
    runResourceT (ResourceT IO (Response value) -> IO (Response value))
    -> ResourceT IO (Response value) -> IO (Response value)
    forall a b. (a -> b) -> a -> b
    $ do
            Response (ConduitM () Method (ResourceT IO) ())
    res <- TWInfo
    -> Manager
    -> Request
    -> ResourceT IO (Response (ConduitM () Method (ResourceT IO) ()))
    forall (m :: * -> *).
    MonadResource m =>
    TWInfo
    -> Manager -> Request -> m (Response (ConduitM () Method m ()))
    getResponse TWInfo
    info Manager
    mgr (Request
     -> ResourceT IO (Response (ConduitM () Method (ResourceT IO) ())))
    -> ResourceT IO Request
    -> ResourceT IO (Response (ConduitM () Method (ResourceT IO) ()))
    forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
    =<< IO Request -> ResourceT IO Request
    forall a. IO a -> ResourceT IO a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (APIRequest apiName responseType -> IO Request
    forall (apiName :: [Param Symbol (*)]) responseType.
    APIRequest apiName responseType -> IO Request
    makeRequest APIRequest apiName responseType
    req)
            Response (ConduitM () Method (ResourceT IO) ())
    -> ResourceT IO (Response value)
    forall a.
    ResponseBodyType a =>
    Response (ConduitM () Method (ResourceT IO) ())
    -> ResourceT IO (Response a)
    parseResponseBody Response (ConduitM () Method (ResourceT IO) ())
    res

    -- | A wrapper function to perform multiple API request with changing @max_id@ parameter.
    --
    -- This function cooperate with instances of 'HasMaxIdParam'.
    sourceWithMaxId ::
        ( MonadIO m
        , FromJSON responseType
        , AsStatus responseType
        , HasParam "max_id" Integer supports
        ) =>
        -- | Twitter Setting
        TWInfo ->
        HTTP.Manager ->
        APIRequest supports [responseType] ->
        C.ConduitT () responseType m ()
    sourceWithMaxId :: forall (m :: * -> *) responseType (supports :: [Param Symbol (*)]).
    (MonadIO m, FromJSON responseType, AsStatus responseType,
     HasParam "max_id" Integer supports) =>
    TWInfo
    -> Manager
    -> APIRequest supports [responseType]
    -> ConduitT () responseType m ()
    sourceWithMaxId TWInfo
    info Manager
    mgr = APIRequest supports [responseType] -> ConduitT () responseType m ()
    loop
      where
        loop :: APIRequest supports [responseType] -> ConduitT () responseType m ()
    loop APIRequest supports [responseType]
    req = do
            [responseType]
    res <- IO [responseType] -> ConduitT () responseType m [responseType]
    forall a. IO a -> ConduitT () responseType m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO [responseType] -> ConduitT () responseType m [responseType])
    -> IO [responseType] -> ConduitT () responseType m [responseType]
    forall a b. (a -> b) -> a -> b
    $ TWInfo
    -> Manager
    -> APIRequest supports [responseType]
    -> IO [responseType]
    forall responseType (apiName :: [Param Symbol (*)]).
    ResponseBodyType responseType =>
    TWInfo
    -> Manager -> APIRequest apiName responseType -> IO responseType
    call TWInfo
    info Manager
    mgr APIRequest supports [responseType]
    req
            case [responseType] -> Maybe Integer
    getMinId [responseType]
    res of
                Just Integer
    mid -> do
                    [responseType] -> ConduitT () responseType m ()
    forall (m :: * -> *) a i. Monad m => [a] -> ConduitT i a m ()
    CL.sourceList [responseType]
    res
                    APIRequest supports [responseType] -> ConduitT () responseType m ()
    loop (APIRequest supports [responseType]
     -> ConduitT () responseType m ())
    -> APIRequest supports [responseType]
    -> ConduitT () responseType m ()
    forall a b. (a -> b) -> a -> b
    $ APIRequest supports [responseType]
    req APIRequest supports [responseType]
    -> (APIRequest supports [responseType]
        -> APIRequest supports [responseType])
    -> APIRequest supports [responseType]
    forall a b. a -> (a -> b) -> b
    & ASetter
      (APIRequest supports [responseType])
      (APIRequest supports [responseType])
      (Maybe Integer)
      (Maybe Integer)
    #max_id ASetter
      (APIRequest supports [responseType])
      (APIRequest supports [responseType])
      (Maybe Integer)
      (Maybe Integer)
    -> Integer
    -> APIRequest supports [responseType]
    -> APIRequest supports [responseType]
    forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
    ?~ Integer
    mid Integer -> Integer -> Integer
    forall a. Num a => a -> a -> a
    - Integer
    1
                Maybe Integer
    Nothing -> [responseType] -> ConduitT () responseType m ()
    forall (m :: * -> *) a i. Monad m => [a] -> ConduitT i a m ()
    CL.sourceList [responseType]
    res
        getMinId :: [responseType] -> Maybe Integer
    getMinId = Getting (Endo (Endo (Maybe Integer))) [responseType] Integer
    -> [responseType] -> Maybe Integer
    forall a s.
    Ord a =>
    Getting (Endo (Endo (Maybe a))) s a -> s -> Maybe a
    minimumOf ((responseType -> Const (Endo (Endo (Maybe Integer))) responseType)
    -> [responseType]
    -> Const (Endo (Endo (Maybe Integer))) [responseType]
    forall (t :: * -> *) (f :: * -> *) a b.
    (Traversable t, Applicative f) =>
    (a -> f b) -> t a -> f (t b)
    forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> [a] -> f [b]
    traverse ((responseType -> Const (Endo (Endo (Maybe Integer))) responseType)
     -> [responseType]
     -> Const (Endo (Endo (Maybe Integer))) [responseType])
    -> ((Integer -> Const (Endo (Endo (Maybe Integer))) Integer)
        -> responseType
        -> Const (Endo (Endo (Maybe Integer))) responseType)
    -> Getting (Endo (Endo (Maybe Integer))) [responseType] Integer
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Integer -> Const (Endo (Endo (Maybe Integer))) Integer)
    -> responseType -> Const (Endo (Endo (Maybe Integer))) responseType
    forall s. AsStatus s => Lens' s Integer
    Lens' responseType Integer
    status_id)

    -- | A wrapper function to perform multiple API request with changing @max_id@ parameter.
    -- The response of this function is not restrict to @responseType@,
    -- so you can choose an arbitrarily type of FromJSON instances.
    --
    -- This function cooperate with instances of 'HasMaxIdParam'.
    sourceWithMaxId' ::
        ( MonadIO m
        , HasParam "max_id" Integer supports
        ) =>
        -- | Twitter Setting
        TWInfo ->
        HTTP.Manager ->
        APIRequest supports [responseType] ->
        C.ConduitT () Value m ()
    sourceWithMaxId' :: forall (m :: * -> *) (supports :: [Param Symbol (*)]) responseType.
    (MonadIO m, HasParam "max_id" Integer supports) =>
    TWInfo
    -> Manager
    -> APIRequest supports [responseType]
    -> ConduitT () Value m ()
    sourceWithMaxId' TWInfo
    info Manager
    mgr = APIRequest supports [responseType] -> ConduitT () Value m ()
    loop
      where
        loop :: APIRequest supports [responseType] -> ConduitT () Value m ()
    loop APIRequest supports [responseType]
    req = do
            ([Value]
    res :: [Value]) <- IO [Value] -> ConduitT () Value m [Value]
    forall a. IO a -> ConduitT () Value m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO [Value] -> ConduitT () Value m [Value])
    -> IO [Value] -> ConduitT () Value m [Value]
    forall a b. (a -> b) -> a -> b
    $ TWInfo
    -> Manager -> APIRequest supports [responseType] -> IO [Value]
    forall value (apiName :: [Param Symbol (*)]) responseType.
    ResponseBodyType value =>
    TWInfo -> Manager -> APIRequest apiName responseType -> IO value
    call' TWInfo
    info Manager
    mgr APIRequest supports [responseType]
    req
            case Getting (Endo (Endo (Maybe Integer))) [Value] Integer
    -> [Value] -> Maybe Integer
    forall a s.
    Ord a =>
    Getting (Endo (Endo (Maybe a))) s a -> s -> Maybe a
    minimumOf ((Value -> Const (Endo (Endo (Maybe Integer))) Value)
    -> [Value] -> Const (Endo (Endo (Maybe Integer))) [Value]
    forall (t :: * -> *) (f :: * -> *) a b.
    (Traversable t, Applicative f) =>
    (a -> f b) -> t a -> f (t b)
    forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> [a] -> f [b]
    traverse ((Value -> Const (Endo (Endo (Maybe Integer))) Value)
     -> [Value] -> Const (Endo (Endo (Maybe Integer))) [Value])
    -> ((Integer -> Const (Endo (Endo (Maybe Integer))) Integer)
        -> Value -> Const (Endo (Endo (Maybe Integer))) Value)
    -> Getting (Endo (Endo (Maybe Integer))) [Value] Integer
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Key -> Traversal' Value Value
    forall t. AsValue t => Key -> Traversal' t Value
    key Key
    "id" ((Value -> Const (Endo (Endo (Maybe Integer))) Value)
     -> Value -> Const (Endo (Endo (Maybe Integer))) Value)
    -> ((Integer -> Const (Endo (Endo (Maybe Integer))) Integer)
        -> Value -> Const (Endo (Endo (Maybe Integer))) Value)
    -> (Integer -> Const (Endo (Endo (Maybe Integer))) Integer)
    -> Value
    -> Const (Endo (Endo (Maybe Integer))) Value
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Integer -> Const (Endo (Endo (Maybe Integer))) Integer)
    -> Value -> Const (Endo (Endo (Maybe Integer))) Value
    forall t. AsNumber t => Prism' t Integer
    Prism' Value Integer
    _Integer) [Value]
    res of
                Just Integer
    mid -> do
                    [Value] -> ConduitT () Value m ()
    forall (m :: * -> *) a i. Monad m => [a] -> ConduitT i a m ()
    CL.sourceList [Value]
    res
                    APIRequest supports [responseType] -> ConduitT () Value m ()
    loop (APIRequest supports [responseType] -> ConduitT () Value m ())
    -> APIRequest supports [responseType] -> ConduitT () Value m ()
    forall a b. (a -> b) -> a -> b
    $ APIRequest supports [responseType]
    req APIRequest supports [responseType]
    -> (APIRequest supports [responseType]
        -> APIRequest supports [responseType])
    -> APIRequest supports [responseType]
    forall a b. a -> (a -> b) -> b
    & ASetter
      (APIRequest supports [responseType])
      (APIRequest supports [responseType])
      (Maybe Integer)
      (Maybe Integer)
    #max_id ASetter
      (APIRequest supports [responseType])
      (APIRequest supports [responseType])
      (Maybe Integer)
      (Maybe Integer)
    -> Integer
    -> APIRequest supports [responseType]
    -> APIRequest supports [responseType]
    forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
    ?~ Integer
    mid Integer -> Integer -> Integer
    forall a. Num a => a -> a -> a
    - Integer
    1
                Maybe Integer
    Nothing -> [Value] -> ConduitT () Value m ()
    forall (m :: * -> *) a i. Monad m => [a] -> ConduitT i a m ()
    CL.sourceList [Value]
    res

    -- | A wrapper function to perform multiple API request with changing @cursor@ parameter.
    --
    -- This function cooperate with instances of 'HasCursorParam'.
    sourceWithCursor ::
        ( MonadIO m
        , FromJSON responseType
        , KnownSymbol ck
        , HasParam "cursor" Integer supports
        ) =>
        -- | Twitter Setting
        TWInfo ->
        HTTP.Manager ->
        APIRequest supports (WithCursor Integer ck responseType) ->
        C.ConduitT () responseType m ()
    sourceWithCursor :: forall (m :: * -> *) responseType (ck :: Symbol)
           (supports :: [Param Symbol (*)]).
    (MonadIO m, FromJSON responseType, KnownSymbol ck,
     HasParam "cursor" Integer supports) =>
    TWInfo
    -> Manager
    -> APIRequest supports (WithCursor Integer ck responseType)
    -> ConduitT () responseType m ()
    sourceWithCursor TWInfo
    info Manager
    mgr APIRequest supports (WithCursor Integer ck responseType)
    req = Maybe Integer -> ConduitT () responseType m ()
    loop (Integer -> Maybe Integer
    forall a. a -> Maybe a
    Just (-Integer
    1))
      where
        loop :: Maybe Integer -> ConduitT () responseType m ()
    loop Maybe Integer
    Nothing = ConduitT () responseType m ()
    forall (m :: * -> *) i o. Monad m => ConduitT i o m ()
    CL.sourceNull
        loop (Just Integer
    0) = ConduitT () responseType m ()
    forall (m :: * -> *) i o. Monad m => ConduitT i o m ()
    CL.sourceNull
        loop (Just Integer
    cur) = do
            WithCursor Integer ck responseType
    res <- IO (WithCursor Integer ck responseType)
    -> ConduitT () responseType m (WithCursor Integer ck responseType)
    forall a. IO a -> ConduitT () responseType m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO (WithCursor Integer ck responseType)
     -> ConduitT () responseType m (WithCursor Integer ck responseType))
    -> IO (WithCursor Integer ck responseType)
    -> ConduitT () responseType m (WithCursor Integer ck responseType)
    forall a b. (a -> b) -> a -> b
    $ TWInfo
    -> Manager
    -> APIRequest supports (WithCursor Integer ck responseType)
    -> IO (WithCursor Integer ck responseType)
    forall responseType (apiName :: [Param Symbol (*)]).
    ResponseBodyType responseType =>
    TWInfo
    -> Manager -> APIRequest apiName responseType -> IO responseType
    call TWInfo
    info Manager
    mgr (APIRequest supports (WithCursor Integer ck responseType)
     -> IO (WithCursor Integer ck responseType))
    -> APIRequest supports (WithCursor Integer ck responseType)
    -> IO (WithCursor Integer ck responseType)
    forall a b. (a -> b) -> a -> b
    $ APIRequest supports (WithCursor Integer ck responseType)
    req APIRequest supports (WithCursor Integer ck responseType)
    -> (APIRequest supports (WithCursor Integer ck responseType)
        -> APIRequest supports (WithCursor Integer ck responseType))
    -> APIRequest supports (WithCursor Integer ck responseType)
    forall a b. a -> (a -> b) -> b
    & ASetter
      (APIRequest supports (WithCursor Integer ck responseType))
      (APIRequest supports (WithCursor Integer ck responseType))
      (Maybe Integer)
      (Maybe Integer)
    #cursor ASetter
      (APIRequest supports (WithCursor Integer ck responseType))
      (APIRequest supports (WithCursor Integer ck responseType))
      (Maybe Integer)
      (Maybe Integer)
    -> Integer
    -> APIRequest supports (WithCursor Integer ck responseType)
    -> APIRequest supports (WithCursor Integer ck responseType)
    forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
    ?~ Integer
    cur
            [responseType] -> ConduitT () responseType m ()
    forall (m :: * -> *) a i. Monad m => [a] -> ConduitT i a m ()
    CL.sourceList ([responseType] -> ConduitT () responseType m ())
    -> [responseType] -> ConduitT () responseType m ()
    forall a b. (a -> b) -> a -> b
    $ WithCursor Integer ck responseType -> [responseType]
    forall cursorType (cursorKey :: Symbol) wrapped.
    WithCursor cursorType cursorKey wrapped -> [wrapped]
    contents WithCursor Integer ck responseType
    res
            Maybe Integer -> ConduitT () responseType m ()
    loop (Maybe Integer -> ConduitT () responseType m ())
    -> Maybe Integer -> ConduitT () responseType m ()
    forall a b. (a -> b) -> a -> b
    $ WithCursor Integer ck responseType -> Maybe Integer
    forall cursorType (cursorKey :: Symbol) wrapped.
    WithCursor cursorType cursorKey wrapped -> Maybe cursorType
    nextCursor WithCursor Integer ck responseType
    res

    -- | A wrapper function to perform multiple API request with changing @cursor@ parameter.
    -- The response of this function is not restrict to @responseType@,
    -- so you can choose an arbitrarily type of FromJSON instances.
    --
    -- This function cooperate with instances of 'HasCursorParam'.
    sourceWithCursor' ::
        ( MonadIO m
        , KnownSymbol ck
        , HasParam "cursor" Integer supports
        ) =>
        -- | Twitter Setting
        TWInfo ->
        HTTP.Manager ->
        APIRequest supports (WithCursor Integer ck responseType) ->
        C.ConduitT () Value m ()
    sourceWithCursor' :: forall (m :: * -> *) (ck :: Symbol)
           (supports :: [Param Symbol (*)]) responseType.
    (MonadIO m, KnownSymbol ck, HasParam "cursor" Integer supports) =>
    TWInfo
    -> Manager
    -> APIRequest supports (WithCursor Integer ck responseType)
    -> ConduitT () Value m ()
    sourceWithCursor' TWInfo
    info Manager
    mgr APIRequest supports (WithCursor Integer ck responseType)
    req = Maybe Integer -> ConduitT () Value m ()
    loop (Integer -> Maybe Integer
    forall a. a -> Maybe a
    Just (-Integer
    1))
      where
        relax ::
            APIRequest apiName (WithCursor Integer ck responseType) ->
            APIRequest apiName (WithCursor Integer ck Value)
        relax :: forall (apiName :: [Param Symbol (*)]) (ck :: Symbol) responseType.
    APIRequest apiName (WithCursor Integer ck responseType)
    -> APIRequest apiName (WithCursor Integer ck Value)
    relax = APIRequest apiName (WithCursor Integer ck responseType)
    -> APIRequest apiName (WithCursor Integer ck Value)
    forall a b. Coercible a b => a -> b
    coerce
        loop :: Maybe Integer -> ConduitT () Value m ()
    loop Maybe Integer
    Nothing = ConduitT () Value m ()
    forall (m :: * -> *) i o. Monad m => ConduitT i o m ()
    CL.sourceNull
        loop (Just Integer
    0) = ConduitT () Value m ()
    forall (m :: * -> *) i o. Monad m => ConduitT i o m ()
    CL.sourceNull
        loop (Just Integer
    cur) = do
            WithCursor Integer ck Value
    res <- IO (WithCursor Integer ck Value)
    -> ConduitT () Value m (WithCursor Integer ck Value)
    forall a. IO a -> ConduitT () Value m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO (WithCursor Integer ck Value)
     -> ConduitT () Value m (WithCursor Integer ck Value))
    -> IO (WithCursor Integer ck Value)
    -> ConduitT () Value m (WithCursor Integer ck Value)
    forall a b. (a -> b) -> a -> b
    $ TWInfo
    -> Manager
    -> APIRequest supports (WithCursor Integer ck Value)
    -> IO (WithCursor Integer ck Value)
    forall responseType (apiName :: [Param Symbol (*)]).
    ResponseBodyType responseType =>
    TWInfo
    -> Manager -> APIRequest apiName responseType -> IO responseType
    call TWInfo
    info Manager
    mgr (APIRequest supports (WithCursor Integer ck Value)
     -> IO (WithCursor Integer ck Value))
    -> APIRequest supports (WithCursor Integer ck Value)
    -> IO (WithCursor Integer ck Value)
    forall a b. (a -> b) -> a -> b
    $ APIRequest supports (WithCursor Integer ck responseType)
    -> APIRequest supports (WithCursor Integer ck Value)
    forall (apiName :: [Param Symbol (*)]) (ck :: Symbol) responseType.
    APIRequest apiName (WithCursor Integer ck responseType)
    -> APIRequest apiName (WithCursor Integer ck Value)
    relax (APIRequest supports (WithCursor Integer ck responseType)
     -> APIRequest supports (WithCursor Integer ck Value))
    -> APIRequest supports (WithCursor Integer ck responseType)
    -> APIRequest supports (WithCursor Integer ck Value)
    forall a b. (a -> b) -> a -> b
    $ APIRequest supports (WithCursor Integer ck responseType)
    req APIRequest supports (WithCursor Integer ck responseType)
    -> (APIRequest supports (WithCursor Integer ck responseType)
        -> APIRequest supports (WithCursor Integer ck responseType))
    -> APIRequest supports (WithCursor Integer ck responseType)
    forall a b. a -> (a -> b) -> b
    & ASetter
      (APIRequest supports (WithCursor Integer ck responseType))
      (APIRequest supports (WithCursor Integer ck responseType))
      (Maybe Integer)
      (Maybe Integer)
    #cursor ASetter
      (APIRequest supports (WithCursor Integer ck responseType))
      (APIRequest supports (WithCursor Integer ck responseType))
      (Maybe Integer)
      (Maybe Integer)
    -> Integer
    -> APIRequest supports (WithCursor Integer ck responseType)
    -> APIRequest supports (WithCursor Integer ck responseType)
    forall s t a b. ASetter s t a (Maybe b) -> b -> s -> t
    ?~ Integer
    cur
            [Value] -> ConduitT () Value m ()
    forall (m :: * -> *) a i. Monad m => [a] -> ConduitT i a m ()
    CL.sourceList ([Value] -> ConduitT () Value m ())
    -> [Value] -> ConduitT () Value m ()
    forall a b. (a -> b) -> a -> b
    $ WithCursor Integer ck Value -> [Value]
    forall cursorType (cursorKey :: Symbol) wrapped.
    WithCursor cursorType cursorKey wrapped -> [wrapped]
    contents WithCursor Integer ck Value
    res
            Maybe Integer -> ConduitT () Value m ()
    loop (Maybe Integer -> ConduitT () Value m ())
    -> Maybe Integer -> ConduitT () Value m ()
    forall a b. (a -> b) -> a -> b
    $ WithCursor Integer ck Value -> Maybe Integer
    forall cursorType (cursorKey :: Symbol) wrapped.
    WithCursor cursorType cursorKey wrapped -> Maybe cursorType
    nextCursor WithCursor Integer ck Value
    res

    -- | A wrapper function to perform multiple API request with @SearchResult@.
    sourceWithSearchResult ::
        ( MonadIO m
        , FromJSON responseType
        ) =>
        -- | Twitter Setting
        TWInfo ->
        HTTP.Manager ->
        APIRequest supports (SearchResult [responseType]) ->
        m (SearchResult (C.ConduitT () responseType m ()))
    sourceWithSearchResult :: forall (m :: * -> *) responseType (supports :: [Param Symbol (*)]).
    (MonadIO m, FromJSON responseType) =>
    TWInfo
    -> Manager
    -> APIRequest supports (SearchResult [responseType])
    -> m (SearchResult (ConduitT () responseType m ()))
    sourceWithSearchResult TWInfo
    info Manager
    mgr APIRequest supports (SearchResult [responseType])
    req = do
        SearchResult [responseType]
    res <- IO (SearchResult [responseType]) -> m (SearchResult [responseType])
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO (SearchResult [responseType])
     -> m (SearchResult [responseType]))
    -> IO (SearchResult [responseType])
    -> m (SearchResult [responseType])
    forall a b. (a -> b) -> a -> b
    $ TWInfo
    -> Manager
    -> APIRequest supports (SearchResult [responseType])
    -> IO (SearchResult [responseType])
    forall responseType (apiName :: [Param Symbol (*)]).
    ResponseBodyType responseType =>
    TWInfo
    -> Manager -> APIRequest apiName responseType -> IO responseType
    call TWInfo
    info Manager
    mgr APIRequest supports (SearchResult [responseType])
    req
        let body :: ConduitT () responseType m ()
    body =
                [responseType] -> ConduitT () responseType m ()
    forall (m :: * -> *) a i. Monad m => [a] -> ConduitT i a m ()
    CL.sourceList (SearchResult [responseType]
    res SearchResult [responseType]
    -> Getting
         [responseType] (SearchResult [responseType]) [responseType]
    -> [responseType]
    forall s a. s -> Getting a s a -> a
    ^. Getting [responseType] (SearchResult [responseType]) [responseType]
    forall body1 body2 (f :: * -> *).
    Functor f =>
    (body1 -> f body2) -> SearchResult body1 -> f (SearchResult body2)
    searchResultStatuses)
                    ConduitT () responseType m ()
    -> ConduitT () responseType m () -> ConduitT () responseType m ()
    forall a. Semigroup a => a -> a -> a
    <> Maybe Text -> ConduitT () responseType m ()
    loop (SearchResult [responseType]
    res SearchResult [responseType]
    -> Getting (Maybe Text) (SearchResult [responseType]) (Maybe Text)
    -> Maybe Text
    forall s a. s -> Getting a s a -> a
    ^. (SearchMetadata -> Const (Maybe Text) SearchMetadata)
    -> SearchResult [responseType]
    -> Const (Maybe Text) (SearchResult [responseType])
    forall body (f :: * -> *).
    Functor f =>
    (SearchMetadata -> f SearchMetadata)
    -> SearchResult body -> f (SearchResult body)
    searchResultSearchMetadata ((SearchMetadata -> Const (Maybe Text) SearchMetadata)
     -> SearchResult [responseType]
     -> Const (Maybe Text) (SearchResult [responseType]))
    -> ((Maybe Text -> Const (Maybe Text) (Maybe Text))
        -> SearchMetadata -> Const (Maybe Text) SearchMetadata)
    -> Getting (Maybe Text) (SearchResult [responseType]) (Maybe Text)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Maybe Text -> Const (Maybe Text) (Maybe Text))
    -> SearchMetadata -> Const (Maybe Text) SearchMetadata
    Lens' SearchMetadata (Maybe Text)
    searchMetadataNextResults)
        SearchResult (ConduitT () responseType m ())
    -> m (SearchResult (ConduitT () responseType m ()))
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (SearchResult (ConduitT () responseType m ())
     -> m (SearchResult (ConduitT () responseType m ())))
    -> SearchResult (ConduitT () responseType m ())
    -> m (SearchResult (ConduitT () responseType m ()))
    forall a b. (a -> b) -> a -> b
    $ SearchResult [responseType]
    res SearchResult [responseType]
    -> (SearchResult [responseType]
        -> SearchResult (ConduitT () responseType m ()))
    -> SearchResult (ConduitT () responseType m ())
    forall a b. a -> (a -> b) -> b
    & ([responseType] -> Identity (ConduitT () responseType m ()))
    -> SearchResult [responseType]
    -> Identity (SearchResult (ConduitT () responseType m ()))
    forall body1 body2 (f :: * -> *).
    Functor f =>
    (body1 -> f body2) -> SearchResult body1 -> f (SearchResult body2)
    searchResultStatuses (([responseType] -> Identity (ConduitT () responseType m ()))
     -> SearchResult [responseType]
     -> Identity (SearchResult (ConduitT () responseType m ())))
    -> ConduitT () responseType m ()
    -> SearchResult [responseType]
    -> SearchResult (ConduitT () responseType m ())
    forall s t a b. ASetter s t a b -> b -> s -> t
    .~ ConduitT () responseType m ()
    body
      where
        origQueryMap :: Map Method PV
    origQueryMap = APIRequest supports (SearchResult [responseType])
    req APIRequest supports (SearchResult [responseType])
    -> Getting
         (Map Method PV)
         (APIRequest supports (SearchResult [responseType]))
         (Map Method PV)
    -> Map Method PV
    forall s a. s -> Getting a s a -> a
    ^. (APIQuery -> Const (Map Method PV) APIQuery)
    -> APIRequest supports (SearchResult [responseType])
    -> Const
         (Map Method PV) (APIRequest supports (SearchResult [responseType]))
    forall req. Parameters req => Lens' req APIQuery
    Lens' (APIRequest supports (SearchResult [responseType])) APIQuery
    params ((APIQuery -> Const (Map Method PV) APIQuery)
     -> APIRequest supports (SearchResult [responseType])
     -> Const
          (Map Method PV)
          (APIRequest supports (SearchResult [responseType])))
    -> ((Map Method PV -> Const (Map Method PV) (Map Method PV))
        -> APIQuery -> Const (Map Method PV) APIQuery)
    -> Getting
         (Map Method PV)
         (APIRequest supports (SearchResult [responseType]))
         (Map Method PV)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (APIQuery -> Map Method PV)
    -> (Map Method PV -> Const (Map Method PV) (Map Method PV))
    -> APIQuery
    -> Const (Map Method PV) APIQuery
    forall (p :: * -> * -> *) (f :: * -> *) s a.
    (Profunctor p, Contravariant f) =>
    (s -> a) -> Optic' p f s a
    to APIQuery -> Map Method PV
    forall k a. Ord k => [(k, a)] -> Map k a
    M.fromList
        loop :: Maybe Text -> ConduitT () responseType m ()
    loop Maybe Text
    Nothing = ConduitT () responseType m ()
    forall (m :: * -> *) i o. Monad m => ConduitT i o m ()
    CL.sourceNull
        loop (Just Text
    nextResultsStr) = do
            let nextResults :: APIQuery
    nextResults = Text
    nextResultsStr Text -> (Text -> SimpleQuery) -> SimpleQuery
    forall a b. a -> (a -> b) -> b
    & Method -> SimpleQuery
    HT.parseSimpleQuery (Method -> SimpleQuery) -> (Text -> Method) -> Text -> SimpleQuery
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Method
    T.encodeUtf8 SimpleQuery -> (SimpleQuery -> APIQuery) -> APIQuery
    forall a b. a -> (a -> b) -> b
    & (SimpleQueryItem -> Identity (Method, PV))
    -> SimpleQuery -> Identity APIQuery
    forall (f :: * -> *) a b.
    Traversable f =>
    IndexedTraversal Int (f a) (f b) a b
    IndexedTraversal
      Int SimpleQuery APIQuery SimpleQueryItem (Method, PV)
    traversed ((SimpleQueryItem -> Identity (Method, PV))
     -> SimpleQuery -> Identity APIQuery)
    -> ((Method -> Identity PV)
        -> SimpleQueryItem -> Identity (Method, PV))
    -> (Method -> Identity PV)
    -> SimpleQuery
    -> Identity APIQuery
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Method -> Identity PV) -> SimpleQueryItem -> Identity (Method, PV)
    forall s t a b. Field2 s t a b => Lens s t a b
    Lens SimpleQueryItem (Method, PV) Method PV
    _2 ((Method -> Identity PV) -> SimpleQuery -> Identity APIQuery)
    -> (Method -> PV) -> SimpleQuery -> APIQuery
    forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
    %~ (Text -> PV
    PVString (Text -> PV) -> (Method -> Text) -> Method -> PV
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Method -> Text
    T.decodeUtf8)
                nextParams :: APIQuery
    nextParams = Map Method PV -> APIQuery
    forall k a. Map k a -> [(k, a)]
    M.toList (Map Method PV -> APIQuery) -> Map Method PV -> APIQuery
    forall a b. (a -> b) -> a -> b
    $ Map Method PV -> Map Method PV -> Map Method PV
    forall k a. Ord k => Map k a -> Map k a -> Map k a
    M.union (APIQuery -> Map Method PV
    forall k a. Ord k => [(k, a)] -> Map k a
    M.fromList APIQuery
    nextResults) Map Method PV
    origQueryMap
            SearchResult [responseType]
    res <- IO (SearchResult [responseType])
    -> ConduitT () responseType m (SearchResult [responseType])
    forall a. IO a -> ConduitT () responseType m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO (SearchResult [responseType])
     -> ConduitT () responseType m (SearchResult [responseType]))
    -> IO (SearchResult [responseType])
    -> ConduitT () responseType m (SearchResult [responseType])
    forall a b. (a -> b) -> a -> b
    $ TWInfo
    -> Manager
    -> APIRequest supports (SearchResult [responseType])
    -> IO (SearchResult [responseType])
    forall responseType (apiName :: [Param Symbol (*)]).
    ResponseBodyType responseType =>
    TWInfo
    -> Manager -> APIRequest apiName responseType -> IO responseType
    call TWInfo
    info Manager
    mgr (APIRequest supports (SearchResult [responseType])
     -> IO (SearchResult [responseType]))
    -> APIRequest supports (SearchResult [responseType])
    -> IO (SearchResult [responseType])
    forall a b. (a -> b) -> a -> b
    $ APIRequest supports (SearchResult [responseType])
    req APIRequest supports (SearchResult [responseType])
    -> (APIRequest supports (SearchResult [responseType])
        -> APIRequest supports (SearchResult [responseType]))
    -> APIRequest supports (SearchResult [responseType])
    forall a b. a -> (a -> b) -> b
    & (APIQuery -> Identity APIQuery)
    -> APIRequest supports (SearchResult [responseType])
    -> Identity (APIRequest supports (SearchResult [responseType]))
    forall req. Parameters req => Lens' req APIQuery
    Lens' (APIRequest supports (SearchResult [responseType])) APIQuery
    params ((APIQuery -> Identity APIQuery)
     -> APIRequest supports (SearchResult [responseType])
     -> Identity (APIRequest supports (SearchResult [responseType])))
    -> APIQuery
    -> APIRequest supports (SearchResult [responseType])
    -> APIRequest supports (SearchResult [responseType])
    forall s t a b. ASetter s t a b -> b -> s -> t
    .~ APIQuery
    nextParams
            [responseType] -> ConduitT () responseType m ()
    forall (m :: * -> *) a i. Monad m => [a] -> ConduitT i a m ()
    CL.sourceList (SearchResult [responseType]
    res SearchResult [responseType]
    -> Getting
         [responseType] (SearchResult [responseType]) [responseType]
    -> [responseType]
    forall s a. s -> Getting a s a -> a
    ^. Getting [responseType] (SearchResult [responseType]) [responseType]
    forall body1 body2 (f :: * -> *).
    Functor f =>
    (body1 -> f body2) -> SearchResult body1 -> f (SearchResult body2)
    searchResultStatuses)
            Maybe Text -> ConduitT () responseType m ()
    loop (Maybe Text -> ConduitT () responseType m ())
    -> Maybe Text -> ConduitT () responseType m ()
    forall a b. (a -> b) -> a -> b
    $ SearchResult [responseType]
    res SearchResult [responseType]
    -> Getting (Maybe Text) (SearchResult [responseType]) (Maybe Text)
    -> Maybe Text
    forall s a. s -> Getting a s a -> a
    ^. (SearchMetadata -> Const (Maybe Text) SearchMetadata)
    -> SearchResult [responseType]
    -> Const (Maybe Text) (SearchResult [responseType])
    forall body (f :: * -> *).
    Functor f =>
    (SearchMetadata -> f SearchMetadata)
    -> SearchResult body -> f (SearchResult body)
    searchResultSearchMetadata ((SearchMetadata -> Const (Maybe Text) SearchMetadata)
     -> SearchResult [responseType]
     -> Const (Maybe Text) (SearchResult [responseType]))
    -> ((Maybe Text -> Const (Maybe Text) (Maybe Text))
        -> SearchMetadata -> Const (Maybe Text) SearchMetadata)
    -> Getting (Maybe Text) (SearchResult [responseType]) (Maybe Text)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Maybe Text -> Const (Maybe Text) (Maybe Text))
    -> SearchMetadata -> Const (Maybe Text) SearchMetadata
    Lens' SearchMetadata (Maybe Text)
    searchMetadataNextResults

    -- | A wrapper function to perform multiple API request with @SearchResult@.
    sourceWithSearchResult' ::
        ( MonadIO m
        ) =>
        -- | Twitter Setting
        TWInfo ->
        HTTP.Manager ->
        APIRequest supports (SearchResult [responseType]) ->
        m (SearchResult (C.ConduitT () Value m ()))
    sourceWithSearchResult' :: forall (m :: * -> *) (supports :: [Param Symbol (*)]) responseType.
    MonadIO m =>
    TWInfo
    -> Manager
    -> APIRequest supports (SearchResult [responseType])
    -> m (SearchResult (ConduitT () Value m ()))
    sourceWithSearchResult' TWInfo
    info Manager
    mgr APIRequest supports (SearchResult [responseType])
    req = do
        SearchResult [Value]
    res <- IO (SearchResult [Value]) -> m (SearchResult [Value])
    forall a. IO a -> m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO (SearchResult [Value]) -> m (SearchResult [Value]))
    -> IO (SearchResult [Value]) -> m (SearchResult [Value])
    forall a b. (a -> b) -> a -> b
    $ TWInfo
    -> Manager
    -> APIRequest supports (SearchResult [Value])
    -> IO (SearchResult [Value])
    forall responseType (apiName :: [Param Symbol (*)]).
    ResponseBodyType responseType =>
    TWInfo
    -> Manager -> APIRequest apiName responseType -> IO responseType
    call TWInfo
    info Manager
    mgr (APIRequest supports (SearchResult [Value])
     -> IO (SearchResult [Value]))
    -> APIRequest supports (SearchResult [Value])
    -> IO (SearchResult [Value])
    forall a b. (a -> b) -> a -> b
    $ APIRequest supports (SearchResult [responseType])
    -> APIRequest supports (SearchResult [Value])
    forall (apiName :: [Param Symbol (*)]) responseType.
    APIRequest apiName (SearchResult [responseType])
    -> APIRequest apiName (SearchResult [Value])
    relax APIRequest supports (SearchResult [responseType])
    req
        let body :: ConduitT () Value m ()
    body =
                [Value] -> ConduitT () Value m ()
    forall (m :: * -> *) a i. Monad m => [a] -> ConduitT i a m ()
    CL.sourceList (SearchResult [Value]
    res SearchResult [Value]
    -> Getting [Value] (SearchResult [Value]) [Value] -> [Value]
    forall s a. s -> Getting a s a -> a
    ^. Getting [Value] (SearchResult [Value]) [Value]
    forall body1 body2 (f :: * -> *).
    Functor f =>
    (body1 -> f body2) -> SearchResult body1 -> f (SearchResult body2)
    searchResultStatuses)
                    ConduitT () Value m ()
    -> ConduitT () Value m () -> ConduitT () Value m ()
    forall a. Semigroup a => a -> a -> a
    <> Maybe Text -> ConduitT () Value m ()
    loop (SearchResult [Value]
    res SearchResult [Value]
    -> Getting (Maybe Text) (SearchResult [Value]) (Maybe Text)
    -> Maybe Text
    forall s a. s -> Getting a s a -> a
    ^. (SearchMetadata -> Const (Maybe Text) SearchMetadata)
    -> SearchResult [Value]
    -> Const (Maybe Text) (SearchResult [Value])
    forall body (f :: * -> *).
    Functor f =>
    (SearchMetadata -> f SearchMetadata)
    -> SearchResult body -> f (SearchResult body)
    searchResultSearchMetadata ((SearchMetadata -> Const (Maybe Text) SearchMetadata)
     -> SearchResult [Value]
     -> Const (Maybe Text) (SearchResult [Value]))
    -> ((Maybe Text -> Const (Maybe Text) (Maybe Text))
        -> SearchMetadata -> Const (Maybe Text) SearchMetadata)
    -> Getting (Maybe Text) (SearchResult [Value]) (Maybe Text)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Maybe Text -> Const (Maybe Text) (Maybe Text))
    -> SearchMetadata -> Const (Maybe Text) SearchMetadata
    Lens' SearchMetadata (Maybe Text)
    searchMetadataNextResults)
        SearchResult (ConduitT () Value m ())
    -> m (SearchResult (ConduitT () Value m ()))
    forall a. a -> m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (SearchResult (ConduitT () Value m ())
     -> m (SearchResult (ConduitT () Value m ())))
    -> SearchResult (ConduitT () Value m ())
    -> m (SearchResult (ConduitT () Value m ()))
    forall a b. (a -> b) -> a -> b
    $ SearchResult [Value]
    res SearchResult [Value]
    -> (SearchResult [Value] -> SearchResult (ConduitT () Value m ()))
    -> SearchResult (ConduitT () Value m ())
    forall a b. a -> (a -> b) -> b
    & ([Value] -> Identity (ConduitT () Value m ()))
    -> SearchResult [Value]
    -> Identity (SearchResult (ConduitT () Value m ()))
    forall body1 body2 (f :: * -> *).
    Functor f =>
    (body1 -> f body2) -> SearchResult body1 -> f (SearchResult body2)
    searchResultStatuses (([Value] -> Identity (ConduitT () Value m ()))
     -> SearchResult [Value]
     -> Identity (SearchResult (ConduitT () Value m ())))
    -> ConduitT () Value m ()
    -> SearchResult [Value]
    -> SearchResult (ConduitT () Value m ())
    forall s t a b. ASetter s t a b -> b -> s -> t
    .~ ConduitT () Value m ()
    body
      where
        origQueryMap :: Map Method PV
    origQueryMap = APIRequest supports (SearchResult [responseType])
    req APIRequest supports (SearchResult [responseType])
    -> Getting
         (Map Method PV)
         (APIRequest supports (SearchResult [responseType]))
         (Map Method PV)
    -> Map Method PV
    forall s a. s -> Getting a s a -> a
    ^. (APIQuery -> Const (Map Method PV) APIQuery)
    -> APIRequest supports (SearchResult [responseType])
    -> Const
         (Map Method PV) (APIRequest supports (SearchResult [responseType]))
    forall req. Parameters req => Lens' req APIQuery
    Lens' (APIRequest supports (SearchResult [responseType])) APIQuery
    params ((APIQuery -> Const (Map Method PV) APIQuery)
     -> APIRequest supports (SearchResult [responseType])
     -> Const
          (Map Method PV)
          (APIRequest supports (SearchResult [responseType])))
    -> ((Map Method PV -> Const (Map Method PV) (Map Method PV))
        -> APIQuery -> Const (Map Method PV) APIQuery)
    -> Getting
         (Map Method PV)
         (APIRequest supports (SearchResult [responseType]))
         (Map Method PV)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (APIQuery -> Map Method PV)
    -> (Map Method PV -> Const (Map Method PV) (Map Method PV))
    -> APIQuery
    -> Const (Map Method PV) APIQuery
    forall (p :: * -> * -> *) (f :: * -> *) s a.
    (Profunctor p, Contravariant f) =>
    (s -> a) -> Optic' p f s a
    to APIQuery -> Map Method PV
    forall k a. Ord k => [(k, a)] -> Map k a
    M.fromList
        relax ::
            APIRequest apiName (SearchResult [responseType]) ->
            APIRequest apiName (SearchResult [Value])
        relax :: forall (apiName :: [Param Symbol (*)]) responseType.
    APIRequest apiName (SearchResult [responseType])
    -> APIRequest apiName (SearchResult [Value])
    relax = APIRequest apiName (SearchResult [responseType])
    -> APIRequest apiName (SearchResult [Value])
    forall a b. Coercible a b => a -> b
    coerce
        loop :: Maybe Text -> ConduitT () Value m ()
    loop Maybe Text
    Nothing = ConduitT () Value m ()
    forall (m :: * -> *) i o. Monad m => ConduitT i o m ()
    CL.sourceNull
        loop (Just Text
    nextResultsStr) = do
            let nextResults :: APIQuery
    nextResults = Text
    nextResultsStr Text -> (Text -> SimpleQuery) -> SimpleQuery
    forall a b. a -> (a -> b) -> b
    & Method -> SimpleQuery
    HT.parseSimpleQuery (Method -> SimpleQuery) -> (Text -> Method) -> Text -> SimpleQuery
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Text -> Method
    T.encodeUtf8 SimpleQuery -> (SimpleQuery -> APIQuery) -> APIQuery
    forall a b. a -> (a -> b) -> b
    & (SimpleQueryItem -> Identity (Method, PV))
    -> SimpleQuery -> Identity APIQuery
    forall (f :: * -> *) a b.
    Traversable f =>
    IndexedTraversal Int (f a) (f b) a b
    IndexedTraversal
      Int SimpleQuery APIQuery SimpleQueryItem (Method, PV)
    traversed ((SimpleQueryItem -> Identity (Method, PV))
     -> SimpleQuery -> Identity APIQuery)
    -> ((Method -> Identity PV)
        -> SimpleQueryItem -> Identity (Method, PV))
    -> (Method -> Identity PV)
    -> SimpleQuery
    -> Identity APIQuery
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Method -> Identity PV) -> SimpleQueryItem -> Identity (Method, PV)
    forall s t a b. Field2 s t a b => Lens s t a b
    Lens SimpleQueryItem (Method, PV) Method PV
    _2 ((Method -> Identity PV) -> SimpleQuery -> Identity APIQuery)
    -> (Method -> PV) -> SimpleQuery -> APIQuery
    forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
    %~ (Text -> PV
    PVString (Text -> PV) -> (Method -> Text) -> Method -> PV
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Method -> Text
    T.decodeUtf8)
                nextParams :: APIQuery
    nextParams = Map Method PV -> APIQuery
    forall k a. Map k a -> [(k, a)]
    M.toList (Map Method PV -> APIQuery) -> Map Method PV -> APIQuery
    forall a b. (a -> b) -> a -> b
    $ Map Method PV -> Map Method PV -> Map Method PV
    forall k a. Ord k => Map k a -> Map k a -> Map k a
    M.union (APIQuery -> Map Method PV
    forall k a. Ord k => [(k, a)] -> Map k a
    M.fromList APIQuery
    nextResults) Map Method PV
    origQueryMap
            SearchResult [Value]
    res <- IO (SearchResult [Value])
    -> ConduitT () Value m (SearchResult [Value])
    forall a. IO a -> ConduitT () Value m a
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    liftIO (IO (SearchResult [Value])
     -> ConduitT () Value m (SearchResult [Value]))
    -> IO (SearchResult [Value])
    -> ConduitT () Value m (SearchResult [Value])
    forall a b. (a -> b) -> a -> b
    $ TWInfo
    -> Manager
    -> APIRequest supports (SearchResult [Value])
    -> IO (SearchResult [Value])
    forall responseType (apiName :: [Param Symbol (*)]).
    ResponseBodyType responseType =>
    TWInfo
    -> Manager -> APIRequest apiName responseType -> IO responseType
    call TWInfo
    info Manager
    mgr (APIRequest supports (SearchResult [Value])
     -> IO (SearchResult [Value]))
    -> APIRequest supports (SearchResult [Value])
    -> IO (SearchResult [Value])
    forall a b. (a -> b) -> a -> b
    $ APIRequest supports (SearchResult [responseType])
    -> APIRequest supports (SearchResult [Value])
    forall (apiName :: [Param Symbol (*)]) responseType.
    APIRequest apiName (SearchResult [responseType])
    -> APIRequest apiName (SearchResult [Value])
    relax (APIRequest supports (SearchResult [responseType])
     -> APIRequest supports (SearchResult [Value]))
    -> APIRequest supports (SearchResult [responseType])
    -> APIRequest supports (SearchResult [Value])
    forall a b. (a -> b) -> a -> b
    $ APIRequest supports (SearchResult [responseType])
    req APIRequest supports (SearchResult [responseType])
    -> (APIRequest supports (SearchResult [responseType])
        -> APIRequest supports (SearchResult [responseType]))
    -> APIRequest supports (SearchResult [responseType])
    forall a b. a -> (a -> b) -> b
    & (APIQuery -> Identity APIQuery)
    -> APIRequest supports (SearchResult [responseType])
    -> Identity (APIRequest supports (SearchResult [responseType]))
    forall req. Parameters req => Lens' req APIQuery
    Lens' (APIRequest supports (SearchResult [responseType])) APIQuery
    params ((APIQuery -> Identity APIQuery)
     -> APIRequest supports (SearchResult [responseType])
     -> Identity (APIRequest supports (SearchResult [responseType])))
    -> APIQuery
    -> APIRequest supports (SearchResult [responseType])
    -> APIRequest supports (SearchResult [responseType])
    forall s t a b. ASetter s t a b -> b -> s -> t
    .~ APIQuery
    nextParams
            [Value] -> ConduitT () Value m ()
    forall (m :: * -> *) a i. Monad m => [a] -> ConduitT i a m ()
    CL.sourceList (SearchResult [Value]
    res SearchResult [Value]
    -> Getting [Value] (SearchResult [Value]) [Value] -> [Value]
    forall s a. s -> Getting a s a -> a
    ^. Getting [Value] (SearchResult [Value]) [Value]
    forall body1 body2 (f :: * -> *).
    Functor f =>
    (body1 -> f body2) -> SearchResult body1 -> f (SearchResult body2)
    searchResultStatuses)
            Maybe Text -> ConduitT () Value m ()
    loop (Maybe Text -> ConduitT () Value m ())
    -> Maybe Text -> ConduitT () Value m ()
    forall a b. (a -> b) -> a -> b
    $ SearchResult [Value]
    res SearchResult [Value]
    -> Getting (Maybe Text) (SearchResult [Value]) (Maybe Text)
    -> Maybe Text
    forall s a. s -> Getting a s a -> a
    ^. (SearchMetadata -> Const (Maybe Text) SearchMetadata)
    -> SearchResult [Value]
    -> Const (Maybe Text) (SearchResult [Value])
    forall body (f :: * -> *).
    Functor f =>
    (SearchMetadata -> f SearchMetadata)
    -> SearchResult body -> f (SearchResult body)
    searchResultSearchMetadata ((SearchMetadata -> Const (Maybe Text) SearchMetadata)
     -> SearchResult [Value]
     -> Const (Maybe Text) (SearchResult [Value]))
    -> ((Maybe Text -> Const (Maybe Text) (Maybe Text))
        -> SearchMetadata -> Const (Maybe Text) SearchMetadata)
    -> Getting (Maybe Text) (SearchResult [Value]) (Maybe Text)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Maybe Text -> Const (Maybe Text) (Maybe Text))
    -> SearchMetadata -> Const (Maybe Text) SearchMetadata
    Lens' SearchMetadata (Maybe Text)
    searchMetadataNextResults

    sinkJSON ::
        ( MonadThrow m
        ) =>
        C.ConduitT ByteString o m Value
    sinkJSON :: forall (m :: * -> *) o. MonadThrow m => ConduitT Method o m Value
    sinkJSON = Parser Method Value -> ConduitT Method o m Value
    forall a (m :: * -> *) b o.
    (AttoparsecInput a, MonadThrow m) =>
    Parser a b -> ConduitT a o m b
    CA.sinkParser Parser Method Value
    json

    sinkFromJSON ::
        ( FromJSON a
        , MonadThrow m
        ) =>
        C.ConduitT ByteString o m a
    sinkFromJSON :: forall a (m :: * -> *) o.
    (FromJSON a, MonadThrow m) =>
    ConduitT Method o m a
    sinkFromJSON = do
        Value
    v <- ConduitT Method o m Value
    forall (m :: * -> *) o. MonadThrow m => ConduitT Method o m Value
    sinkJSON
        case Value -> Result a
    forall a. FromJSON a => Value -> Result a
    fromJSON Value
    v of
            Error String
    err -> TwitterError -> ConduitT Method o m a
    forall e a.
    (HasCallStack, Exception e) =>
    e -> ConduitT Method o m a
    forall (m :: * -> *) e a.
    (MonadThrow m, HasCallStack, Exception e) =>
    e -> m a
    throwM (TwitterError -> ConduitT Method o m a)
    -> TwitterError -> ConduitT Method o m a
    forall a b. (a -> b) -> a -> b
    $ String -> TwitterError
    FromJSONError String
    err
            Success a
    r -> a -> ConduitT Method o m a
    forall a. a -> ConduitT Method o m a
    forall (m :: * -> *) a. Monad m => a -> m a
    return a
    r