    {-# LANGUAGE DeriveDataTypeable #-}

    module Web.Twitter.Conduit.Types (
        TWToken (..),
        TWInfo (..),
        twitterOAuth,
        setCredential,
    ) where

    import Data.Default
    import Data.Typeable (Typeable)
    import Network.HTTP.Conduit
    import Web.Authenticate.OAuth

    data TWToken = TWToken
        { TWToken -> OAuth
    twOAuth :: OAuth
        , TWToken -> Credential
    twCredential :: Credential
        }
        deriving (Int -> TWToken -> ShowS
    [TWToken] -> ShowS
    TWToken -> String
    (Int -> TWToken -> ShowS)
    -> (TWToken -> String) -> ([TWToken] -> ShowS) -> Show TWToken
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> TWToken -> ShowS
    showsPrec :: Int -> TWToken -> ShowS
    $cshow :: TWToken -> String
    show :: TWToken -> String
    $cshowList :: [TWToken] -> ShowS
    showList :: [TWToken] -> ShowS
    Show, ReadPrec [TWToken]
    ReadPrec TWToken
    Int -> ReadS TWToken
    ReadS [TWToken]
    (Int -> ReadS TWToken)
    -> ReadS [TWToken]
    -> ReadPrec TWToken
    -> ReadPrec [TWToken]
    -> Read TWToken
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS TWToken
    readsPrec :: Int -> ReadS TWToken
    $creadList :: ReadS [TWToken]
    readList :: ReadS [TWToken]
    $creadPrec :: ReadPrec TWToken
    readPrec :: ReadPrec TWToken
    $creadListPrec :: ReadPrec [TWToken]
    readListPrec :: ReadPrec [TWToken]
    Read, TWToken -> TWToken -> Bool
    (TWToken -> TWToken -> Bool)
    -> (TWToken -> TWToken -> Bool) -> Eq TWToken
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: TWToken -> TWToken -> Bool
    == :: TWToken -> TWToken -> Bool
    $c/= :: TWToken -> TWToken -> Bool
    /= :: TWToken -> TWToken -> Bool
    Eq, Typeable)
    instance Default TWToken where
        def :: TWToken
    def = OAuth -> Credential -> TWToken
    TWToken OAuth
    twitterOAuth ([(ByteString, ByteString)] -> Credential
    Credential [])

    data TWInfo = TWInfo
        { TWInfo -> TWToken
    twToken :: TWToken
        , TWInfo -> Maybe Proxy
    twProxy :: Maybe Proxy
        }
        deriving (Int -> TWInfo -> ShowS
    [TWInfo] -> ShowS
    TWInfo -> String
    (Int -> TWInfo -> ShowS)
    -> (TWInfo -> String) -> ([TWInfo] -> ShowS) -> Show TWInfo
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> TWInfo -> ShowS
    showsPrec :: Int -> TWInfo -> ShowS
    $cshow :: TWInfo -> String
    show :: TWInfo -> String
    $cshowList :: [TWInfo] -> ShowS
    showList :: [TWInfo] -> ShowS
    Show, ReadPrec [TWInfo]
    ReadPrec TWInfo
    Int -> ReadS TWInfo
    ReadS [TWInfo]
    (Int -> ReadS TWInfo)
    -> ReadS [TWInfo]
    -> ReadPrec TWInfo
    -> ReadPrec [TWInfo]
    -> Read TWInfo
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS TWInfo
    readsPrec :: Int -> ReadS TWInfo
    $creadList :: ReadS [TWInfo]
    readList :: ReadS [TWInfo]
    $creadPrec :: ReadPrec TWInfo
    readPrec :: ReadPrec TWInfo
    $creadListPrec :: ReadPrec [TWInfo]
    readListPrec :: ReadPrec [TWInfo]
    Read, TWInfo -> TWInfo -> Bool
    (TWInfo -> TWInfo -> Bool)
    -> (TWInfo -> TWInfo -> Bool) -> Eq TWInfo
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: TWInfo -> TWInfo -> Bool
    == :: TWInfo -> TWInfo -> Bool
    $c/= :: TWInfo -> TWInfo -> Bool
    /= :: TWInfo -> TWInfo -> Bool
    Eq, Typeable)
    instance Default TWInfo where
        def :: TWInfo
    def =
            TWInfo
                { twToken :: TWToken
    twToken = TWToken
    forall a. Default a => a
    def
                , twProxy :: Maybe Proxy
    twProxy = Maybe Proxy
    forall a. Maybe a
    Nothing
                }

    twitterOAuth :: OAuth
    twitterOAuth :: OAuth
    twitterOAuth =
        OAuth
    forall a. Default a => a
    def
            { oauthServerName = "twitter"
            , oauthRequestUri = "https://api.twitter.com/oauth/request_token"
            , oauthAccessTokenUri = "https://api.twitter.com/oauth/access_token"
            , oauthAuthorizeUri = "https://api.twitter.com/oauth/authorize"
            , oauthConsumerKey = error "You MUST specify oauthConsumerKey parameter."
            , oauthConsumerSecret = error "You MUST specify oauthConsumerSecret parameter."
            , oauthSignatureMethod = HMACSHA1
            , oauthCallback = Nothing
            }

    -- | set OAuth keys and Credentials to TWInfo.
    --
    -- >>> let proxy = Proxy "localhost" 8080
    -- >>> let twinfo = def { twProxy = Just proxy }
    -- >>> let oauth = twitterOAuth { oauthConsumerKey = "consumer_key", oauthConsumerSecret = "consumer_secret" }
    -- >>> let credential = Credential [("oauth_token","...")]
    -- >>> let twinfo2 = setCredential oauth credential twinfo
    -- >>> oauthConsumerKey . twOAuth . twToken $ twinfo2
    -- "consumer_key"
    -- >>> twProxy twinfo2 == Just proxy
    -- True
    setCredential :: OAuth -> Credential -> TWInfo -> TWInfo
    setCredential :: OAuth -> Credential -> TWInfo -> TWInfo
    setCredential OAuth
    oa Credential
    cred TWInfo
    env =
        TWInfo
            { twToken :: TWToken
    twToken = OAuth -> Credential -> TWToken
    TWToken OAuth
    oa Credential
    cred
            , twProxy :: Maybe Proxy
    twProxy = TWInfo -> Maybe Proxy
    twProxy TWInfo
    env
            }