Skip to content

Instantly share code, notes, and snippets.

@sh4869
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sh4869/cf21d61b6f1f61243c83 to your computer and use it in GitHub Desktop.
Save sh4869/cf21d61b6f1f61243c83 to your computer and use it in GitHub Desktop.
Gtk2で出来たツイッタークライアント紛いです。ファイルが結構分割されているので使いたければ。
# Coding: UTF-8
require 'gtk2'
require 'twitter'
require 'keys.rb'
require 'oauth.rb'
require 'Tweet.rb'
unless File::exist?(TokenFile)
oauth_first
end
open(TokenFile){ |file|
ACCESS_TOKEN = file.readlines.values_at(0)[0].gsub("\n","")
}
open(TokenFile){ |file|
ACCESS_SECRET = file.readlines.values_at(1)[0].gsub("\n","")
}
@rest_client = Twitter::REST::Client.new do |config|
config.consumer_key = CONSUMER_KEY
config.consumer_secret = CONSUMER_SECRET
config.access_token = ACCESS_TOKEN
config.access_token_secret = ACCESS_SECRET
end
@stream_client = Twitter::Streaming::Client.new do |config|
config.consumer_key = CONSUMER_KEY
config.consumer_secret = CONSUMER_SECRET
config.access_token = ACCESS_TOKEN
config.access_token_secret = ACCESS_SECRET
end
tweet_dialog
CONSUMER_KEY = ""
CONSUMER_SECRET = ""
# Coding: UTF-8
require 'oauth'
require 'oauth/consumer'
require 'keys.rb'
SourcePath = File.expand_path('../', __FILE__)
TokenFile = "#{SourcePath}/token"
def oauth_first
@consumer = OAuth::Consumer.new(CONSUMER_KEY ,CONSUMER_SECRET,{
:site=>"https://api.twitter.com"
})# Coding: UTF-8
require 'oauth'
require 'oauth/consumer'
require '~/Document/Ruby/gtk/Gtktter/src/keys.rb'
SourcePath = File.expand_path('../', __FILE__)
TokenFile = "#{SourcePath}/token"
def oauth_first
@consumer = OAuth::Consumer.new(CONSUMER_KEY ,CONSUMER_SECRET,{
:site=>"https://api.twitter.com"
})
@request_token = @consumer.get_request_token
puts "Please access this URL: #{@request_token.authorize_url}"
puts "and get the Pin code."
print "Enter your Pin code:"
pin = gets.chomp
@access_token = @request_token.get_access_token(:oauth_verifier => pin)
open(TokenFile, "a" ){|f| f.write("#{@access_token.token}\n")}
open(TokenFile, "a" ){|f| f.write("#{@access_token.secret}\n")}
end
@request_token = @consumer.get_request_token
puts "Please access this URL: #{@request_token.authorize_url}"
puts "and get the Pin code."
print "Enter your Pin code:"
pin = gets.chomp
@access_token = @request_token.get_access_token(:oauth_verifier => pin)
open(TokenFile, "a" ){|f| f.write("#{@access_token.token}\n")}
open(TokenFile, "a" ){|f| f.write("#{@access_token.secret}\n")}
end
def tweet_dialog
window = Gtk::Window.new
window.title = "Tweet"
window.signal_connect("delete_event") do
Gtk.main_quit
false
end
window.border_width = 20
#2x2 のテーブルを作成
table = Gtk::Table.new(4, 4, true)
window.add(table)
#テキストエントリを作成する
entry = Gtk::Entry.new
entry.max_length = 140
table.attach_defaults(entry,0,4,0,2)
button = Gtk::Button.new("Tweet")
button.signal_connect("clicked") do
text = "#{entry.text}"
@rest_client.update("#{text}")
entry.text = ""
end
table.attach_defaults(button,0,4,2,4)
window.show_all
Gtk.main
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment