~vcs-imports-ii/rbot/master

« back to all changes in this revision

Viewing changes to data/rbot/plugins/twitter.rb

  • Committer: Matthias Hecker
  • Date: 2013-11-14 15:51:26 UTC
  • Revision ID: git-v1:a518b9d475ca8223c89cb036ee3841bab35e916b
twitter: filter ret.latest status if non specified

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    :default => 3, :validate => Proc.new { |v| v > 0 && v <= 10},
39
39
    :desc => "Maximum number of status updates shown by 'twitter [home|mentions|retweets] status'")
40
40
 
 
41
  URL_PATTERN = %r{twitter\.com/([^/]+)(?:/status/(\d+))?}
 
42
 
41
43
  def twitter_filter(s)
42
 
    loc = Utils.check_location(s, Regexp.new('twitter\.com/(#!/)?.*/status/\d+'))
 
44
    loc = Utils.check_location(s, URL_PATTERN)
43
45
    return nil unless loc
44
 
    id = loc.first.match(/\/status\/(\d+)/)[1]
45
 
 
46
 
    response = @app_access_token.get('/1.1/statuses/show/'+id+'.json').body
 
46
    matches = loc.first.match URL_PATTERN
 
47
    if matches[2] # status id matched
 
48
      id = matches[2]
 
49
      url = '/1.1/statuses/show/%s.json' % id
 
50
    else # no status id, get the latest status of that user
 
51
      user = matches[1]
 
52
      url = '/1.1/statuses/user_timeline.json?screen_name=%s&count=1&include_rts=true' % user
 
53
    end
 
54
    response = @app_access_token.get(url).body
47
55
    begin
48
56
      tweet = JSON.parse(response)
 
57
      tweet = tweet.first if tweet.instance_of? Array
49
58
      status = {
50
59
        :date => (Time.parse(tweet["created_at"]) rescue "<unknown>"),
51
60
        :id => (tweet["id_str"] rescue "<unknown>"),