Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

allow the r:twitter:message to return more than just 1 tweet back

  • Loading branch information...
commit f4d5c4f35b0fc3829a115affac0a7ff6b0283373 1 parent 0260306
@dayne dayne authored
Showing with 17 additions and 8 deletions.
  1. +5 −1 HELP_admin.md
  2. +12 −7 lib/twitter_tags.rb
View
6 HELP_admin.md
@@ -12,4 +12,8 @@ On the edit screen of each page, you can select the option to notify Twitter
of all of the updates to the children of that page. You can create a blog page,
for example, and have each new post linked in your Twitter account.
-_Built with version `0.6.6` of the `twitter` gem._
+_Built with version `0.6.6` of the `twitter` gem._
+
+To get latest tweet(s):
+
+<r:twitter:message [ max="10" ] />
View
19 lib/twitter_tags.rb
@@ -9,23 +9,28 @@ module TwitterTags
desc %{
Usage:
- <pre><code><r:twitter:message /></code></pre>
+ <pre><code><r:twitter:message [max="10"] /></code></pre>
Displays the latest status message from the current user's timeline }
tag 'twitter:message' do |tag|
- status = twitter_status
- text = status.text.gsub(/(http:\/\/[^\s]*)/, '<a class="twitter_link" href="\1">\1</a>')
- "<a class=\"twitter_user\" href=\"http://twitter.com/#{status.user.screen_name}\">#{status.user.screen_name}</a> #{text} <p class=\"twitter_time\">#{time_ago_in_words(status.created_at)} ago from #{status.source}</p>"
+ max=tag.attr['max'].to_i
+ out = ""
+ twitter_status(max).each do |status|
+ text = status.text.gsub(/(http:\/\/[^\s]*)/, '<a class="twitter_link" href="\1">\1</a>')
+ out << "<p class=\"twitter_tweet\"><a class=\"twitter_user\" href=\"http://twitter.com/#{status.user.screen_name}\">#{status.user.screen_name}</a> #{text} <span class=\"twitter_time\">#{time_ago_in_words(status.created_at)} ago from #{status.source}</span></p>\n"
+ end
+ out
end
private
- def twitter_status
+ def twitter_status(max = 1)
begin
+ max = 1 if (max>10) or (max< 1)
httpauth = Twitter::HTTPAuth.new(config['twitter.username'], config['twitter.password'])
client = Twitter::Base.new(httpauth)
- return client.user_timeline[0]
+ return client.user_timeline[0..(max-1)]
rescue Exception => e
# Twitter failed... just log for now
logger.error "Twitter Notification failure: #{e.inspect}"
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.