-- Copyright: 2010 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli module Cltw.Common where import Control.Monad.Error import Control.Monad.Reader import Text.Printf import Cltw.Opts type Cltw a = ErrorT String (ReaderT Options IO) a runCltw :: Options -> Cltw a -> IO (Either String a) runCltw env ev = runReaderT (runErrorT ev) env apiPrefix :: String apiPrefix = "api.twitter.com/1/" constructUri :: String -> Cltw String constructUri apiCall = do account <- asks optUser mbPw <- asks optPassword return $ case mbPw of Just password -> printf "https://%s:%s@%s%s.xml" account password apiPrefix apiCall Nothing -> printf "http://%s%s/%s.xml" apiPrefix apiCall account