Created
February 19, 2011 17:36
-
-
Save vkgtaro/835213 to your computer and use it in GitHub Desktop.
Citrus で twitter の内容を表示する plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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