Created
November 28, 2011 16:09
-
-
Save hanachin/1400915 to your computer and use it in GitHub Desktop.
CLI Twitter Client.
This file contains hidden or 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
source "http://rubygems.org" | |
gem "highline" | |
gem "twitter" | |
gem "escape_utils" |
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
require "bundler/setup" | |
require "highline" | |
require "twitter" | |
require "escape_utils" | |
module Faraday | |
module Utils | |
def escape(s) | |
EscapeUtils.escape_url(s.to_s) | |
end | |
end | |
end | |
consumer_key = "" | |
consumer_secret = "" | |
access_token = "" | |
access_token_secret = "" | |
Twitter.configure do |config| | |
config.consumer_key = consumer_key | |
config.consumer_secret = consumer_secret | |
config.oauth_token = access_token | |
config.oauth_token_secret = access_token_secret | |
end | |
@login = false | |
def need_login | |
if not @login | |
puts "loginしないとめっ" | |
return | |
end | |
yield | |
end | |
ui = HighLine.new | |
while true | |
@command = ui.ask("Twitter >>> ") | |
case @command | |
when /^tl/ | |
need_login do | |
count = @command[/[0-9]+/].to_i | |
count = 20 if not (1..200).include?(count) | |
Twitter.home_timeline(:count => count).reverse.each do |t| | |
puts "[#{t.created_at}] #{t.user.name} >> #{t.text}" | |
end | |
end | |
when /^tw / | |
need_login do | |
text = @command.split(/^tw /)[1] | |
Twitter.update(text) | |
end | |
when "mentions" | |
need_login do | |
Twitter.mentions.reverse.each do |t| | |
puts "[#{t.created_at}] #{t.user.name} >> #{t.text}" | |
end | |
end | |
when /^(exit|q|quit)$/ | |
exit | |
when /^login$/ | |
@login = true | |
puts "ログインしました" | |
else | |
puts "なんかわからないコマンド" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment