Tweet from Max with ruby

Update 6/2014: working version here: https://reactivemusic.net/?p=7013

notes

The zapier.com trigger method of sending tweets from Max is limited by number of tweets and sync rate. So it would be nice to set up another intermediary server program in ruby or php which eliminates the middle-man and just sends tweets directly.

Or you could use the mxj searchTweet program, which has been updated to do this on the search side.

twitter gem

update: Got it working with this gem: https://github.com/sferik/twitter. Its much easier than dealing with xively.

docs: http://rdoc.info/gems/twitter

how to destroy a tweet: http://stackoverflow.com/questions/10640811/twitter-gem-how-to-get-the-id-of-a-new-tweet

how to get a timeline: http://bobbyprabowo.wordpress.com/2010/01/01/simple-twitter-gem-tutorial/

example of error handling code:

MAX_ATTEMPTS = 3
num_attempts = 0
begin
  num_attempts += 1
  retweets = Twitter.retweeted_by_user("sferik")
rescue Twitter::Error::TooManyRequests => error
  if num_attempts <= MAX_ATTEMPTS
    # NOTE: Your process could go to sleep for up to 15 minutes but if you
    # retry any sooner, it will almost certainly fail with the same exception.
    sleep error.rate_limit.reset_in
    retry
  else
    raise
  end
end

 

Another useful SO post: http://stackoverflow.com/questions/16618037/twitter-rate-limit-hit-while-requesting-friends-with-ruby-gem/16620639#16620639