Skip to content

Instantly share code, notes, and snippets.

@eagletmt
Created December 19, 2009 03:27
Show Gist options
  • Save eagletmt/259933 to your computer and use it in GitHub Desktop.
Save eagletmt/259933 to your computer and use it in GitHub Desktop.
import Data.Maybe (fromJust)
import Codec.Binary.UTF8.String (encodeString)
import Network.URI (URI, parseURI)
import Network.Browser
import Network.HTTP
tweet :: HStream ty => String -> String -> String -> IO (Response ty)
tweet user pass status = browse $ do
setOutHandler (const (return ()))
addAuthority auth
fmap snd . request $ mkRequest POST uri
where
auth :: Authority
auth = AuthBasic { auRealm = "", auUsername = user, auPassword = pass, auSite = uri }
uri :: URI
uri = fromJust . parseURI $ "http://api.twitter.com/1/statuses/update.xml?" ++ urlEncodeVars [("status", encodeString status)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment