saboyutaka/splapi_gem: splapi Client for ruby
rubyのクライアントを作ってくださった方がいるのでrubyでヤグラのタイミングを教えてくれるtwitter botを書いて遊びました。
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]でsferik/twitter: A Ruby interface to the Twitter API.のv5.14.0使用。
require 'twitter'
require 'splapi'
require 'date'
# Consumer key, Secretの設定
CONSUMER_KEY = 'x'
CONSUMER_SECRET = 'x'
# Access Token Key, Secretの設定
ACCESS_TOKEN_KEY = 'x'
ACCESS_SECRET = 'x'
client = Twitter::REST::Client.new do |config|
config.consumer_key = CONSUMER_KEY
config.consumer_secret = CONSUMER_SECRET
config.access_token = ACCESS_TOKEN_KEY
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_KEY
config.access_token_secret = ACCESS_SECRET
end
splcli = SplAPI::Client.new
rule = 'ガチヤグラ'
stream_client.user do |status|
if status.is_a?(Twitter::Tweet)
puts status.text
flag = false
check = status.text.include?('ヤグラ')
if check && status.user.screen_name == 'retrorocket' then
if splcli.gachi_now.body['result'][0]['rule'] == rule
client.update('今やってるよ? ' + Time.now.to_s)
flag = true
end
if splcli.gachi_next.body['result'][0]['rule'] == rule
client.update('次にやるみたい ' + Time.now.to_s)
flag = true
end
if !flag then
client.update('まだやらないみたい ' + Time.now.to_s)
end
end
end
end