Search code examples
rubyruby-on-rails-3twittertweets

Getting the latest Tweet that isn't a direct message


I'm using sferik's Twitter Gem to grab the latest Tweet from a Twitter account using:

Twitter.user_timeline("someUserName").first.text

This works nicely but includes direct message Tweets. I would like to show the latest standard Tweet (i.e. not a Tweet @ someone).

How could I do this?


Solution

  • I just played around a bit with the lib and it seems that even when there is a @user in the text the to_user property of the tweet is nil. A possible way to do it would be to simply search the text for occurrences of @user strings. For example like this:

    tweets.find {|x| x.text.match(/@.*/) == nil }