Skip to content

Instantly share code, notes, and snippets.

@vkgtaro
Created February 19, 2011 17:36
Show Gist options
  • Save vkgtaro/835213 to your computer and use it in GitHub Desktop.
Save vkgtaro/835213 to your computer and use it in GitHub Desktop.
Citrus で twitter の内容を表示する plugin
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require "rubygems"
require "twitter"
require "timeout"
class Twitter < Default
def process(uri)
timeout(5) do
twitter(uri)
end
end
def twitter(uri, headers=HEADERS)
return unless uri.host == 'twitter.com'
path = uri.fragment || uri.path
if match = path.match("^!?/([^/]*)/status/([0-9]*)")
return sprintf "%s「%s」", ::Twitter.user(match[1]).name, ::Twitter.status(match[2]).text
elsif match = path.match("^!?/([^/]*)")
return sprintf "%s: %s", ::Twitter.user(match[1]).name, ::Twitter.user(match[1]).description
end
rescue
log $!
return "Not Found >_<"
end
end
tests do
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment