Wednesday, August 12, 2009

Ruby Method to Tweet

This method was written by Paul Damer of our team to tweet messages from Ruby. Pretty neat!:
def send_tweet(tweet=nil)
  tweet ||= "default tweet message"
  require 'open-uri'
  require 'net/http'

  url = URI.parse('http://twitter.com/statuses/update.xml')
  req = Net::HTTP::Post.new(url.path)
  req.basic_auth 'twitter_username','twitter_password'
  req.set_form_data({'status' => tweet})
  res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
end

No comments: