module Web.Tweet.Sign where
import Web.Tweet.Utils
import Web.Authenticate.OAuth
import Network.HTTP.Client
import Web.Tweet.Types
signRequest :: FilePath -> Request -> IO Request
signRequest = (. flip signRequestMem) . (>>=) . mkConfig
signRequestMem :: Config -> Request -> IO Request
signRequestMem = uncurry signOAuth
oAuth :: FilePath -> IO OAuth
oAuth filepath = do
secret <- (lineByKey "api-sec") <$> getConfigData filepath
key <- (lineByKey "api-key") <$> getConfigData filepath
let url = "api.twitter.com"
return newOAuth { oauthConsumerKey = key , oauthConsumerSecret = secret , oauthServerName = url }
mkConfig :: FilePath -> IO Config
mkConfig filepath = do
o <- oAuth filepath
c <- credential filepath
pure (o, c)
credential :: FilePath -> IO Credential
credential filepath = newCredential <$> token <*> secretToken
where token = (lineByKey "tok") <$> getConfigData filepath
secretToken = (lineByKey "tok-sec") <$> getConfigData filepath